forked from kissyteam/kissy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlexer-spec.js
More file actions
69 lines (60 loc) · 2.31 KB
/
lexer-spec.js
File metadata and controls
69 lines (60 loc) · 2.31 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
KISSY.use("htmlparser", function(S, HtmlParser) {
var Lexer = HtmlParser.Lexer;
describe("Lexer", function() {
it("works", function() {
var html = "<div id='z'><<a> ";
var lexer = new Lexer(html),node;
var nodes = [];
while (node = lexer.nextNode()) {
nodes.push(node);
}
expect(nodes[0].nodeType).toBe(1);
expect(nodes[0].nodeName).toBe("div");
expect(nodes[0].attributes.length).toBe(1);
expect(nodes[0].attributes[0].name).toBe("id");
expect(nodes[0].attributes[0].value).toBe("z");
expect(nodes[0].toHtml()).toBe("<div id='z'>");
expect(nodes[1].nodeType).toBe(3);
expect(nodes[1].toHtml()).toBe("<");
expect(nodes[2].nodeType).toBe(1);
expect(nodes[2].nodeName).toBe("a");
expect(nodes[2].toHtml()).toBe("<a>");
});
it("works for isSelfClosed", function() {
var html = "<z/>x";
var lexer = new Lexer(html),node;
var nodes = [];
while (node = lexer.nextNode()) {
nodes.push(node);
}
expect(nodes.length).toBe(2);
expect(nodes[0].tagName).toBe("z");
expect(nodes[0].isSelfClosed).toBe(true);
});
it("works for <br/>", function() {
var html = "<br/>";
var lexer = new Lexer(html),node;
var nodes = [];
while (node = lexer.nextNode()) {
nodes.push(node);
}
expect(nodes.length).toBe(1);
expect(nodes[0].tagName).toBe("br");
expect(nodes[0].isSelfClosed).toBe(true);
});
it("works when encounter invalid attribute value", function() {
var html = '<a href="http://g.cn/"">1</a>';
var lexer = new Lexer(html),node;
var nodes = [];
while (node = lexer.nextNode()) {
nodes.push(node);
}
node = nodes[0];
expect(nodes.length).toBe(3);
var attributes = node.attributes;
expect(attributes.length).toBe(1);
expect(attributes[0].name).toBe('href');
expect(attributes[0].value).toBe('http://g.cn/');
});
});
});