-
-
Notifications
You must be signed in to change notification settings - Fork 369
/
Tokenizer.spec.ts
68 lines (60 loc) · 1.99 KB
/
Tokenizer.spec.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
import { Tokenizer } from ".";
function tokenize(str: string) {
const log: unknown[][] = [];
const tokenizer = new Tokenizer(
{},
new Proxy({} as any, {
get(_, prop) {
return (...args: unknown[]) => log.push([prop, ...args]);
},
})
);
tokenizer.write(str);
tokenizer.end();
return log;
}
describe("Tokenizer", () => {
describe("should support self-closing special tags", () => {
it("for self-closing script tag", () => {
expect(tokenize("<script /><div></div>")).toMatchSnapshot();
});
it("for self-closing style tag", () => {
expect(tokenize("<style /><div></div>")).toMatchSnapshot();
});
it("for self-closing title tag", () => {
expect(tokenize("<title /><div></div>")).toMatchSnapshot();
});
});
describe("should support standard special tags", () => {
it("for normal script tag", () => {
expect(tokenize("<script></script><div></div>")).toMatchSnapshot();
});
it("for normal style tag", () => {
expect(tokenize("<style></style><div></div>")).toMatchSnapshot();
});
it("for normal sitle tag", () => {
expect(tokenize("<title></title><div></div>")).toMatchSnapshot();
});
});
it("should not lose data when pausing", () => {
const log: unknown[][] = [];
const tokenizer = new Tokenizer(
{},
new Proxy({} as any, {
get(_, prop) {
return (...args: unknown[]) => {
if (prop === "ontext") {
tokenizer.pause();
}
log.push([prop, ...args]);
};
},
})
);
tokenizer.write("& it up!");
tokenizer.resume();
tokenizer.resume();
tokenizer.end();
expect(log).toMatchSnapshot();
});
});