-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_test.ts
55 lines (50 loc) · 1.18 KB
/
parse_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
import { parseETag } from "./parse.ts";
import {
assertEquals,
assertIsError,
assertThrows,
describe,
it,
} from "./_dev_deps.ts";
import type { ETag } from "./types.ts";
describe("parseETag", () => {
it("should return parsed etag", () => {
const table: [string, ETag][] = [
[`"abc"`, { tag: "abc", weak: false }],
[`""`, { tag: "", weak: false }],
[`W/""`, { tag: "", weak: true }],
[`W/"abc"`, { tag: "abc", weak: true }],
[`W/"10ab-="`, { tag: "10ab-=", weak: true }],
[` W/"10ab-=" `, { tag: "10ab-=", weak: true }],
];
table.forEach(([input, expected]) => {
assertEquals(parseETag(input), expected);
});
});
it("should throw error", () => {
const table: string[] = [
"",
" ",
"abc",
`"""`,
`"abc`,
`abc"`,
`W/abc`,
`W/"abc`,
`W/abc"`,
];
table.forEach((input) => {
assertThrows(() => parseETag(input));
});
});
it("should be error message", () => {
let err;
try {
parseETag("あ");
} catch (e) {
err = e;
} finally {
assertIsError(err, SyntaxError, `invalid <entity-tag> syntax. "あ"`);
}
});
});