forked from jeresig/env-js
/
parser.js
120 lines (96 loc) · 3.1 KB
/
parser.js
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
module("Html5Parser");
var should = function(msg, options){
try{
if(options.be&&options.be=='equal'){
equals(
options.expected,
options.actual,
msg
);
}else if(options.be&&options.be==='safe'){
options.test();
ok(true, msg);
}else{
ok(false, 'unknown test '+options.be);
}
}catch(e){
//no nothing
equals(true, false, options.msg||'This test failed.');
}finally{
//TODO: might as well keep score here
return this;
}
};
test("XML Standard Entities: Spot Check", function() {
expect(2);
var htmlstr =
"<div id='xmlentity' \
style='<Hello>, "W'rld"!'\
><Hello>, "W'rld"!</div>";
var doc = document.implementation.createHTMLDocument();
doc.body.innerHTML = htmlstr;
should("Replace entities at nodeValue",{
be:'equal',
actual : doc.
getElementById('xmlentity').
childNodes[0].
nodeValue,
expected : '<Hello>, "W\'rld"!'
}).
should("serialize only &, < and > for TextNode with innerHTML",{
be: 'equal',
actual : doc.
getElementById('xmlentity').
innerHTML,
expected : '<Hello>, "W\'rld"!'
});
});
test("HTML Standard Entities: Spot Check", function() {
expect(1);
var htmlstr = "<div id='htmlentity'>" & < > "+
" © ® ¥ ¶ " +
"Ê Õ æ ÷ Κ θ "+
"• … ™ ⇒ ∑ ♣ " +
"  —</div>";
var doc = document.implementation.createHTMLDocument();
doc.body.innerHTML = htmlstr;
should("serialize only &, < and > for TextNode with innerHTML",{
be:'equal',
actual:doc.
getElementById('htmlentity').
innerHTML,
expected : '" & < > '+
'\xA0 \xA9 \xAE \xA5 \xB6 '+
'\xCA \xD5 \xE6 \xF7 \u039A \u03B8 '+
'\u2022 \u2026 \u2122 \u21D2 \u2211 \u2663 '+
'\u2002 \u2014'
});
});
test("Serialization Conventions", function(){
});
test("Ugly HTML Parsing", function() {
expect(1);
var doc = document.implementation.createHTMLDocument();
doc.body.innerHTML = '<div id="pig"><p>this is a pig... 'oink! oink!'</div>';
should('correct the unclosed p tag',{
be:'equal',
actual:doc.
getElementById('pig').
xml,
expected:'<div id="pig"><p>this is a pig... \'oink! oink!\'</p></div>'
});
});
test("Really Ugly HTML Parsing", function() {
expect(1);
should('parse the document without error',{
be:'safe',
test:function(){
window.open('html/malformed.html');
}
});
});
// Local Variables:
// espresso-indent-level:4
// c-basic-offset:4
// tab-width:4
// End: