-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathdocument.test.ts
More file actions
45 lines (39 loc) · 1.41 KB
/
document.test.ts
File metadata and controls
45 lines (39 loc) · 1.41 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
import { testCases, testSyntaxError } from "../helpers.ts";
import { type Root } from "../types.ts";
const selectors = [
getDocument(0),
getDocumentHead(0),
getDocumentBody(0),
getDocument(1),
getDocumentHead(1),
getDocumentBody(1),
];
testSyntaxError(`- 123\na:\n`);
testCases([
["\n123\n\n---\n\n456\n\n", selectors],
["\n123\n\n...\n\n456\n\n", selectors],
["\n%AAA\n---\n123\n\n...\n\n456\n\n", selectors],
["\n%AAA\n---\n123\n\n---\n\n456\n\n", selectors],
["\n%AAA\n---\n123\n\n...\n\n---\n\n456\n\n", selectors],
["\n%AAA\n---\n123\n\n...\n\n%BBB\n---\n\n456\n\n", selectors],
["- AAA\n# comment\n---\n- BBB", selectors],
["---\nhello\n... #documentEndComment\n", getDocument(0)],
['&123 123 "123"\n\n... #123\n #\n\n123\n\n\n ', selectors],
["...\n\n#\n\n", getDocument(0)],
["#123\n#456\n---", getDocumentHead(0)],
["...\n\n# comment 1\n# comment 2\n", getDocument(0)],
["123\n--- #666\n456", root => root],
["123\n...\n456", [getDocument(0), getDocumentBody(0)]],
["", root => root],
[" ", root => root],
["\n", root => root],
]);
function getDocument(documentIndex: number) {
return (root: Root) => root.children[documentIndex];
}
function getDocumentHead(documentIndex: number) {
return (root: Root) => getDocument(documentIndex)(root).children[0];
}
function getDocumentBody(documentIndex: number) {
return (root: Root) => getDocument(documentIndex)(root).children[1];
}