-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathif_match_test.ts
75 lines (66 loc) · 1.53 KB
/
if_match_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
import { parse } from "./if_match.ts";
import { type ETag } from "./deps.ts";
import { assertEquals, assertThrows, describe, it } from "./_dev_deps.ts";
describe("parse", () => {
it("should return star", () => {
const table: string[] = [
"*",
];
table.forEach((input) => {
assertEquals(parse(input), "*");
});
});
it("should return empty list", () => {
const table: string[] = [
"",
" ",
" , ",
", , ,",
];
table.forEach((input) => {
assertEquals(parse(input), []);
});
});
it("should return etag list", () => {
const table: [string, ETag[]][] = [
[`""`, [{ tag: "", weak: false }]],
[`"", "a", "b"`, [{ tag: "", weak: false }, { tag: "a", weak: false }, {
tag: "b",
weak: false,
}]],
[`W/"", "a", W/"abc"`, [{ tag: "", weak: true }, {
tag: "a",
weak: false,
}, {
tag: "abc",
weak: true,
}]],
[`"", "*"`, [{ tag: "", weak: false }, {
tag: "*",
weak: false,
}]],
[`","`, [{ tag: ",", weak: false }]],
];
table.forEach(([input, expected]) => {
assertEquals(parse(input), expected);
});
});
it("should throw error if the input is invalid syntax", () => {
const table: string[] = [
`"`,
"* a",
"*,",
`*, ""`,
`* *`,
`**`,
`"", *`,
" *",
"* ",
" * ",
"a,",
];
table.forEach((input) => {
assertThrows(() => parse(input));
});
});
});