Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
quarto-dev
GitHub Repository: quarto-dev/quarto-cli
Path: blob/main/tests/unit/filter-paths.test.ts
6449 views
1
/*
2
* glob.test.ts
3
*
4
* Copyright (C) 2020-2022 Posit Software, PBC
5
*
6
*/
7
import { assert } from "testing/asserts";
8
import { filterPaths } from "../../src/core/path.ts";
9
import { unitTest } from "../test.ts";
10
11
unitTest(
12
"globs",
13
//deno-lint-ignore require-await
14
async () => {
15
const paths = [
16
"/test.qmd",
17
"/test2.qmd",
18
"/test3.qmd",
19
"/folder/test.qmd",
20
"/folder/test2.qmd",
21
"/folder/test.txt",
22
];
23
24
const globDescs = [
25
{ globs: ["*.qmd"], includes: 5, excludes: 0 },
26
{ globs: ["**"], includes: 6, excludes: 0 },
27
{ globs: ["*.qmd", "!folder"], includes: 5, excludes: 0 },
28
{ globs: ["*.qmd", "!folder/"], includes: 5, excludes: 3 },
29
{ globs: ["test*.*", "!folder/"], includes: 6, excludes: 3 },
30
{ globs: ["test*.*", "!*.txt"], includes: 6, excludes: 1 },
31
{ globs: ["folder/*.txt"], includes: 1, excludes: 0 },
32
{ globs: ["folder/*.*", "!*.txt"], includes: 3, excludes: 1 },
33
{ globs: ["folder/**"], includes: 3, excludes: 0 },
34
{ globs: ["test2.*", "!folder/"], includes: 2, excludes: 3 },
35
];
36
for (const globDesc of globDescs) {
37
const filtered = filterPaths("/", paths, globDesc.globs);
38
assert(
39
filtered.include.length === globDesc.includes,
40
`Globs [${
41
globDesc.globs.join(",")
42
}] result in the wrong number of 'includes' matches.`,
43
);
44
assert(
45
filtered.exclude.length === globDesc.excludes,
46
`Globs [${
47
globDesc.globs.join(",")
48
}] result in the wrong number of 'excludes' matches.`,
49
);
50
}
51
},
52
);
53
54