-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathvalidate.test.ts
More file actions
106 lines (82 loc) · 3.18 KB
/
Copy pathvalidate.test.ts
File metadata and controls
106 lines (82 loc) · 3.18 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import assert from "node:assert/strict";
import { isValidAttrValue, isValidScriptlet, isValidStatement } from "..";
describe("validation helpers", () => {
describe("isValidStatement", () => {
it("accepts single-line expressions", () => {
assert.equal(isValidStatement("foo + bar"), 2);
});
it("accepts indented continuation lines", () => {
assert.equal(isValidStatement("foo\n + bar"), 1);
});
it("rejects unindented continuation lines", () => {
assert.equal(isValidStatement("foo\nbar"), 0);
});
it("accepts indented ternary continuation", () => {
assert.equal(isValidStatement("foo ?\n bar : baz"), 2);
});
it("rejects unterminated groups", () => {
assert.equal(isValidStatement("(foo"), 0);
});
it("rejects mismatched closing groups", () => {
assert.equal(isValidStatement(")"), 0);
});
});
describe("isValidScriptlet", () => {
it("accepts single-line expressions", () => {
assert.equal(isValidScriptlet("foo + bar"), 2);
});
it("rejects indented continuation lines", () => {
assert.equal(isValidScriptlet("foo\n + bar"), 0);
});
it("rejects unindented continuation lines", () => {
assert.equal(isValidScriptlet("foo\nbar"), 0);
});
it("accepts indented ternary continuation", () => {
assert.equal(isValidScriptlet("foo ?\n bar : baz"), 2);
});
it("rejects unterminated groups", () => {
assert.equal(isValidScriptlet("(foo"), 0);
});
it("rejects mismatched closing groups", () => {
assert.equal(isValidScriptlet(")"), 0);
});
});
describe("isValidAttrValue", () => {
it("accepts html attr values with operators", () => {
assert.equal(isValidAttrValue("foo + bar", false), 2);
});
it("accepts html attr values containing =>", () => {
assert.equal(isValidAttrValue("foo=>bar", false), 2);
});
it("rejects html attr values terminated by >", () => {
assert.equal(isValidAttrValue("foo >", false), 0);
});
it("accepts concise attr values with >", () => {
assert.equal(isValidAttrValue("foo > bar", true), 2);
});
it("rejects html attr values terminated by commas", () => {
assert.equal(isValidAttrValue("foo, bar", false), 0);
});
it("accepts html attr values containing semicolons", () => {
assert.equal(isValidAttrValue("foo;", false), 2);
});
it("rejects concise attr values terminated by semicolons", () => {
assert.equal(isValidAttrValue("foo;", true), 0);
});
it("accepts html attr values with decrement operator", () => {
assert.equal(isValidAttrValue("foo --", false), 2);
});
it("rejects concise attr values with decrement operator", () => {
assert.equal(isValidAttrValue("foo --", true), 0);
});
it("rejects attr values separated only by whitespace", () => {
assert.equal(isValidAttrValue("foo bar", false), 0);
});
it("accepts continued multiline logical expression", () => {
assert.equal(isValidAttrValue("a &&\nb", true), 1);
});
it("accepts continued multiline enclosed logical expression", () => {
assert.equal(isValidAttrValue("a && (\nb\n)", true), 2);
});
});
});