Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/tests/unit/text.test.ts
6449 views
1
/*
2
* lines.test.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*
6
*/
7
import { unitTest } from "../test.ts";
8
import { assert } from "testing/asserts";
9
import { lines } from "../../src/core/text.ts";
10
import { editDistance } from "../../src/core/lib/text.ts";
11
12
// deno-lint-ignore require-await
13
unitTest("text - lines()", async () => {
14
const texts = ["a", "b", "c"];
15
const splits = ["\n", "\r\n"];
16
splits.forEach((split) => {
17
assert(
18
lines(texts.join(split)).length === texts.length,
19
"Invalid line count",
20
);
21
});
22
});
23
24
// deno-lint-ignore require-await
25
unitTest("text - editDistance", async () => {
26
assert(editDistance("abc", "abd") === 10);
27
assert(editDistance("", "abd") === 30);
28
assert(editDistance("abdef", "abd") === 20);
29
assert(editDistance("abdef", "") === 50);
30
assert(editDistance("abdef", "abcdef") === 10);
31
assert(editDistance("abdef", "abcef") === 10);
32
assert(editDistance("abcDef", "abc-def") === 2);
33
assert(editDistance("abc_def", "abc-def") === 1);
34
assert(editDistance("abc_def", "abcDef") === 2);
35
assert(editDistance("one-option-2", "one-option-3") === 1);
36
});
37
38