-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.test.js
More file actions
94 lines (84 loc) · 2.52 KB
/
parser.test.js
File metadata and controls
94 lines (84 loc) · 2.52 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
"use strict";
var Lexer = require("./lexer");
var Tokenizer = require("./tokenizer");
var Parser = require("./parser");
test("parse <p />", () => {
var parser = new Parser(new Tokenizer(new Lexer("<p />")));
expect(parser.parse()).toBeTruthy();
expect(parser.root()).toEqual(["#root", null, ["p", null]]);
});
test("parse <div />", () => {
var parser = new Parser(new Tokenizer(new Lexer("<div />")));
expect(parser.parse()).toBeTruthy();
expect(parser.root()).toEqual(["#root", null, ["div", null]]);
});
test("parse <div>...</div> #1", () => {
var parser = new Parser(new Tokenizer(new Lexer("<div></div>")));
expect(parser.parse()).toBeTruthy();
expect(parser.root()).toEqual(["#root", null, ["div", null]]);
});
test("parse <div>...</div> #2", () => {
var parser = new Parser(new Tokenizer(new Lexer("<div><h1 /></div>")));
expect(parser.parse()).toBeTruthy();
expect(parser.root()).toEqual(["#root", null, ["div", null, ["h1", null]]]);
});
test("parse <div>...</div> #3", () => {
var parser = new Parser(
new Tokenizer(new Lexer("<div><h1 /><p /><p /></div>"))
);
expect(parser.parse()).toBeTruthy();
expect(parser.root()).toEqual([
"#root",
null,
["div", null, ["h1", null], ["p", null], ["p", null]]
]);
});
test("parse <div>...</div> #4", () => {
var parser = new Parser(
new Tokenizer(new Lexer("<div><h1>hello world</h1></div>"))
);
expect(parser.parse()).toBeTruthy();
expect(parser.root()).toEqual([
"#root",
null,
["div", null, ["h1", null, "hello world"]]
]);
});
test("parse <div>...</div> #5", () => {
var parser = new Parser(
new Tokenizer(
new Lexer(
"<div><h1>How can I use goto in Javascript?</h1><p>ECMAScript has no goto statement.</p></div>"
)
)
);
expect(parser.parse()).toBeTruthy();
expect(parser.root()).toEqual([
"#root",
null,
[
"div",
null,
["h1", null, "How can I use goto in Javascript?"],
["p", null, "ECMAScript has no goto statement."]
]
]);
});
test('parse <a href="about:blank" />', () => {
var parser = new Parser(new Tokenizer(new Lexer('<a href="about:blank" />')));
expect(parser.parse()).toBeTruthy();
expect(parser.root()).toEqual([
"#root",
null,
["a", { href: "about:blank" }]
]);
});
test("parse <a href='about:blank' />", () => {
var parser = new Parser(new Tokenizer(new Lexer("<a href='about:blank' />")));
expect(parser.parse()).toBeTruthy();
expect(parser.root()).toEqual([
"#root",
null,
["a", { href: "about:blank" }]
]);
});