Skip to content

Commit 9ff506f

Browse files
committed
Unit tests for pattern matching
1 parent a71be50 commit 9ff506f

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

test/unit-tests/utilities/filesystem.test.ts

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@
1313
//===----------------------------------------------------------------------===//
1414

1515
import * as path from "path";
16-
import { isPathInsidePath, expandFilePathTilde } from "../../../src/utilities/filesystem";
16+
import { Uri } from "vscode";
17+
import {
18+
isPathInsidePath,
19+
expandFilePathTilde,
20+
isExcluded,
21+
isIncluded,
22+
} from "../../../src/utilities/filesystem";
1723
import { expect } from "chai";
1824

1925
suite("File System Utilities Unit Test Suite", () => {
@@ -55,4 +61,58 @@ suite("File System Utilities Unit Test Suite", () => {
5561
expect(expandFilePathTilde("~/Test", "C:\\Users\\John", "win32")).to.equal("~/Test");
5662
});
5763
});
64+
65+
suite("isExcluded()", () => {
66+
const uri = Uri.file("path/to/foo/bar/file.swift");
67+
68+
test("excluded", () => {
69+
expect(isExcluded(uri, { "/path": true })).to.be.true;
70+
expect(isExcluded(uri, { "**/foo": true })).to.be.true;
71+
expect(isExcluded(uri, { "**/foo/**": true })).to.be.true;
72+
});
73+
74+
test("excluded, overwriting patterns", () => {
75+
expect(isExcluded(uri, { "**/foo": false, "**/foo/bar": true })).to.be.true;
76+
});
77+
78+
test("NOT excluded", () => {
79+
expect(isExcluded(uri, { "**/qux/**": false })).to.be.false;
80+
expect(isExcluded(uri, { "**/foo": false, "**/foo/qux": true })).to.be.false;
81+
expect(
82+
isExcluded(uri, {
83+
"**/foo": false,
84+
"**/foo/bar": true,
85+
"**/foo/bar/file.swift": false,
86+
})
87+
).to.be.false;
88+
});
89+
});
90+
91+
suite("isIncluded()", () => {
92+
const uri = Uri.file("path/to/foo/bar/file.swift");
93+
94+
test("included", () => {
95+
expect(isIncluded(uri, {})).to.be.true;
96+
expect(isIncluded(uri, { "/path": false })).to.be.true;
97+
expect(isIncluded(uri, { "**/foo": false })).to.be.true;
98+
expect(isIncluded(uri, { "**/foo/**": false })).to.be.true;
99+
expect(isIncluded(uri, { "**/qux/**": true })).to.be.true;
100+
});
101+
102+
test("included, overwriting patterns", () => {
103+
expect(isIncluded(uri, { "**/foo": true, "**/foo/bar": false })).to.be.true;
104+
});
105+
106+
test("NOT included", () => {
107+
expect(isIncluded(uri, { "**/foo": true })).to.be.false;
108+
expect(isIncluded(uri, { "**/foo": true, "**/foo/qux": false })).to.be.false;
109+
expect(
110+
isIncluded(uri, {
111+
"**/foo": true,
112+
"**/foo/bar": false,
113+
"**/foo/bar/file.swift": true,
114+
})
115+
).to.be.false;
116+
});
117+
});
58118
});

0 commit comments

Comments
 (0)