-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathdomparserTest.js
More file actions
145 lines (106 loc) · 5.11 KB
/
domparserTest.js
File metadata and controls
145 lines (106 loc) · 5.11 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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
var xmlshim = require('../');
var dp;
exports.setUp = function(callback) {
dp = new xmlshim.DOMParser();
callback();
};
exports['should parse single element non-namespace xml'] = function(test) {
var input = '<hello-world/>';
var doc = dp.parseFromString(input, 'text/xml');
test.equals(doc.firstChild.nodeName, 'hello-world');
test.done();
};
exports['should parse elements with default namespace'] = function(test) {
var input = '<hello xmlns="http://example.com/"><world/></hello>';
var doc = dp.parseFromString(input, 'text/xml');
test.equals(doc.firstChild.nodeName, 'hello');
test.equals(doc.firstChild.namespaceURI, 'http://example.com/');
test.equals(doc.firstChild.firstChild.nodeName, 'world');
test.equals(doc.firstChild.firstChild.namespaceURI, 'http://example.com/');
test.done();
};
exports['should parse elements with namespace prefix'] = function(test) {
var input = '<hello xmlns="http://example.com/"><big:world xmlns:big="http://example.com/big"/></hello>';
var doc = dp.parseFromString(input, 'text/xml');
test.equals(doc.firstChild.nodeName, 'hello');
test.equals(doc.firstChild.namespaceURI, 'http://example.com/');
test.equals(doc.firstChild.firstChild.nodeName, 'big:world');
test.equals(doc.firstChild.firstChild.namespaceURI, 'http://example.com/big');
test.done();
}
exports['child elements should inherit namespaces from parent'] = function(test) {
var input = '<hello xmlns="http://example.com/" xmlns:big="http://example.com/big"><big:world/></hello>';
var doc = dp.parseFromString(input, 'text/xml');
test.equals(doc.firstChild.nodeName, 'hello');
test.equals(doc.firstChild.namespaceURI, 'http://example.com/');
test.equals(doc.firstChild.firstChild.nodeName, 'big:world');
test.equals(doc.firstChild.firstChild.namespaceURI, 'http://example.com/big');
test.done();
}
exports['child elements may override namespaces from parent'] = function(test) {
var input = '<hello xmlns="http://example.com/" xmlns:big="http://example.com/bigwide"><big:world xmlns:big="http://example.com/big"/></hello>';
var doc = dp.parseFromString(input, 'text/xml');
test.equals(doc.firstChild.nodeName, 'hello');
test.equals(doc.firstChild.namespaceURI, 'http://example.com/');
test.equals(doc.firstChild.firstChild.nodeName, 'big:world');
test.equals(doc.firstChild.firstChild.namespaceURI, 'http://example.com/big');
test.done();
}
exports['should parse non-namespace attributes'] = function(test) {
var input = '<hello say="world"/>';
var doc = dp.parseFromString(input, 'text/xml');
test.equals(doc.firstChild.nodeName, 'hello');
test.equals(doc.firstChild.getAttributeNode('say').nodeValue, 'world');
test.done();
}
exports['should be able to parse invalid xml'] = function(test) {
var input = 'yuck';
var doc = dp.parseFromString(input, 'text/xml');
test.equal(doc.firstChild, null);
var input = '';
var doc = dp.parseFromString(input, 'text/xml');
test.equal(doc.firstChild, null);
test.done();
}
exports['should parse attributes with namespace uri'] = function(test) {
var input = '<hello xmlns:aloud="http://example.com/" aloud:say="world"/>';
var doc = dp.parseFromString(input, 'text/xml');
test.equals(doc.firstChild.nodeName, 'hello');
test.equals(doc.firstChild.getAttributeNode('aloud:say').nodeValue, 'world');
test.equals(doc.firstChild.getAttributeNode('aloud:say').namespaceURI, 'http://example.com/');
test.done();
}
exports['should parse text node'] = function(test) {
var input = '<hello>world</hello>';
var doc = dp.parseFromString(input, 'text/xml');
test.equals(doc.firstChild.nodeName, 'hello');
test.equals(doc.firstChild.firstChild.nodeType, doc.TEXT_NODE);
test.equals(doc.firstChild.firstChild.nodeValue, 'world');
test.done();
}
exports['should parse CDATA section'] = function(test) {
var input = '<hello><![CDATA[> world <]]></hello>';
var doc = dp.parseFromString(input, 'text/xml');
test.equals(doc.firstChild.nodeName, 'hello');
test.equals(doc.firstChild.firstChild.nodeType, doc.CDATA_SECTION_NODE);
test.equals(doc.firstChild.firstChild.nodeValue, '> world <');
test.done();
}
exports['should parse comments'] = function(test) {
var input = '<hello><!--world--></hello>';
var doc = dp.parseFromString(input, 'text/xml');
test.equals(doc.firstChild.nodeName, 'hello');
test.equals(doc.firstChild.firstChild.nodeType, doc.COMMENT_NODE);
test.equals(doc.firstChild.firstChild.nodeValue, 'world');
test.done();
}
exports['should parse text node before empty element into the enclosing element'] = function(test) {
var input = '<hello>world<br/></hello>';
var doc = dp.parseFromString(input, 'text/xml');
test.equals(doc.firstChild.nodeName, 'hello');
test.equals(doc.firstChild.firstChild.nodeType, doc.TEXT_NODE);
test.equals(doc.firstChild.firstChild.nodeValue, 'world');
test.equals(doc.firstChild.firstChild.nextSibling.nodeType, doc.ELEMENT_NODE);
test.equals(doc.firstChild.firstChild.nextSibling.nodeName, 'br');
test.done();
}