deno.land / x / lume@v2.1.4 / tests / core / scopes.test.ts

scopes.test.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { assertStrictEquals as equals } from "../../deps/assert.ts";import Scopes from "../../core/scopes.ts";import FS from "../../core/fs.ts";
Deno.test("Scripts", async (t) => { const scopes = new Scopes();
equals(scopes.scopes.size, 0);
const fs = new FS({ root: "/", });
fs.addEntry({ path: "/file1.foo", type: "file" }); fs.addEntry({ path: "/file2.bar", type: "file" }); fs.addEntry({ path: "/file3.css", type: "file" }); fs.addEntry({ path: "/file4.html", type: "file" });
const entries = Array.from(fs.entries.values()).filter((entry) => entry.type === "file" );
// Test cache await t.step("Test cache", () => { const entry = fs.entries.get("/file1.foo")!; equals(!!entry, true); equals(entry.flags.size, 0); entry.flags.add("foo"); equals(entry.flags.size, 1); entry.removeCache(); equals(entry.flags.size, 0); });
await t.step("Add scopes", () => { scopes.scopes.add((path: string) => path.endsWith(".foo")); equals(scopes.scopes.size, 1);
scopes.scopes.add((path: string) => path.endsWith(".bar")); equals(scopes.scopes.size, 2); });
await t.step("Check scoped changes", () => { const filter = scopes.getFilter([ "/file1.foo", "/file3.foo", ]);
const filteredEntries = entries.filter(filter); equals(filteredEntries.length, 1); equals(filteredEntries[0].path, "/file1.foo"); });
await t.step("Check 2 scoped changes", () => { const filter = scopes.getFilter([ "/file1.foo", "/file2.bar", ]);
const filteredEntries = entries.filter(filter); equals(filteredEntries.length, 2); equals(filteredEntries[0].path, "/file1.foo"); equals(filteredEntries[1].path, "/file2.bar"); });
await t.step("Check unscoped changes", () => { const filter = scopes.getFilter([ "/file3.css", ]);
const filteredEntries = entries.filter(filter); equals(filteredEntries.length, 2); equals(filteredEntries[0].path, "/file3.css"); equals(filteredEntries[1].path, "/file4.html"); });
await t.step("Check scoped and unscoped changes", () => { const filter = scopes.getFilter([ "/file3.css", "/file1.foo", ]);
const filteredEntries = entries.filter(filter); equals(filteredEntries.length, 3); equals(filteredEntries[0].path, "/file1.foo"); equals(filteredEntries[1].path, "/file3.css"); equals(filteredEntries[2].path, "/file4.html"); });});
lume

Version Info

Tagged at
7 months ago