@@ -11,9 +11,7 @@ describe('HTML Parser', function () {
11
11
var TextNode = HTMLParser . TextNode ;
12
12
13
13
describe ( 'Matcher' , function ( ) {
14
-
15
14
it ( 'should match corrent elements' , function ( ) {
16
-
17
15
var matcher = new Matcher ( '#id .a a.b *.a.b .a.b * a' ) ;
18
16
var MatchesNothingButStarEl = new HTMLElement ( '_' , { } ) ;
19
17
var withIdEl = new HTMLElement ( 'p' , { id : 'id' } ) ;
@@ -55,15 +53,12 @@ describe('HTML Parser', function () {
55
53
matcher . advance ( withClassNameEl ) . should . be . ok ; // a
56
54
57
55
matcher . matched . should . be . ok ;
58
-
59
56
} ) ;
60
-
61
57
} ) ;
62
58
63
59
var parseHTML = HTMLParser . parse ;
64
60
65
61
describe ( 'parse()' , function ( ) {
66
-
67
62
it ( 'should parse "<p id=\\"id\\"><a class=\'cls\'>Hello</a><ul><li><li></ul><span></span></p>" and return root element' , function ( ) {
68
63
69
64
var root = parseHTML ( '<p id="id"><a class=\'cls\'>Hello</a><ul><li><li></ul><span></span></p>' ) ;
@@ -77,7 +72,6 @@ describe('HTML Parser', function () {
77
72
p . appendChild ( new HTMLElement ( 'span' , { } , '' ) ) ;
78
73
79
74
root . firstChild . should . eql ( p ) ;
80
-
81
75
} ) ;
82
76
83
77
it ( 'should parse "<DIV><a><img/></A><p></P></div>" and return root element' , function ( ) {
@@ -160,7 +154,6 @@ describe('HTML Parser', function () {
160
154
} ) ;
161
155
162
156
describe ( 'TextNode' , function ( ) {
163
-
164
157
describe ( '#isWhitespace' , function ( ) {
165
158
var node = new TextNode ( '' ) ;
166
159
node . isWhitespace . should . be . ok ;
@@ -169,105 +162,77 @@ describe('HTML Parser', function () {
169
162
node = new TextNode ( ' \t \t' ) ;
170
163
node . isWhitespace . should . be . ok ;
171
164
} ) ;
172
-
173
165
} ) ;
174
166
175
167
describe ( 'HTMLElement' , function ( ) {
176
168
177
169
describe ( '#removeWhitespace()' , function ( ) {
178
-
179
170
it ( 'should remove whitespaces while preserving nodes with content' , function ( ) {
180
-
181
171
var root = parseHTML ( '<p> \r \n \t <h5> 123 </h5></p>' ) ;
182
172
183
173
var p = new HTMLElement ( 'p' , { } , '' ) ;
184
174
p . appendChild ( new HTMLElement ( 'h5' , { } , '' ) )
185
175
. appendChild ( new TextNode ( '123' ) ) ;
186
176
187
177
root . firstChild . removeWhitespace ( ) . should . eql ( p ) ;
188
-
189
178
} ) ;
190
-
191
179
} ) ;
192
180
193
181
describe ( '#rawAttributes' , function ( ) {
194
-
195
182
it ( 'should return escaped attributes of the element' , function ( ) {
196
-
197
183
var root = parseHTML ( '<p a=12 data-id="!$$&" yAz=\'1\'></p>' ) ;
198
-
199
184
root . firstChild . rawAttributes . should . eql ( {
200
185
'a' : '12' ,
201
186
'data-id' : '!$$&' ,
202
187
'yAz' : '1'
203
188
} ) ;
204
-
205
189
} ) ;
206
-
207
190
} ) ;
208
191
209
192
describe ( '#attributes' , function ( ) {
210
-
211
193
it ( 'should return attributes of the element' , function ( ) {
212
-
213
194
var root = parseHTML ( '<p a=12 data-id="!$$&" yAz=\'1\'></p>' ) ;
214
-
215
195
root . firstChild . attributes . should . eql ( {
216
196
'a' : '12' ,
217
197
'data-id' : '!$$&' ,
218
198
'yAz' : '1'
219
199
} ) ;
220
-
221
200
} ) ;
222
-
223
201
} ) ;
224
202
225
203
describe ( '#querySelector()' , function ( ) {
226
-
227
204
it ( 'should return correct elements in DOM tree' , function ( ) {
228
-
229
- var root = parseHTML ( '<a id="id"><div><span class="a b"></span><span></span><span></span></div></a>' ) ;
230
-
205
+ var root = parseHTML ( '<a id="id" data-id="myid"><div><span class="a b"></span><span></span><span></span></div></a>' ) ;
231
206
root . querySelector ( '#id' ) . should . eql ( root . firstChild ) ;
232
207
root . querySelector ( 'span.a' ) . should . eql ( root . firstChild . firstChild . firstChild ) ;
233
208
root . querySelector ( 'span.b' ) . should . eql ( root . firstChild . firstChild . firstChild ) ;
234
209
root . querySelector ( 'span.a.b' ) . should . eql ( root . firstChild . firstChild . firstChild ) ;
235
210
root . querySelector ( '#id .b' ) . should . eql ( root . firstChild . firstChild . firstChild ) ;
236
211
root . querySelector ( '#id span' ) . should . eql ( root . firstChild . firstChild . firstChild ) ;
237
-
212
+ root . querySelector ( '[data-id=myid]' ) . should . eql ( root . firstChild ) ;
213
+ root . querySelector ( '[data-id="myid"]' ) . should . eql ( root . firstChild ) ;
238
214
} ) ;
239
-
240
215
} ) ;
241
216
242
217
describe ( '#querySelectorAll()' , function ( ) {
243
-
244
218
it ( 'should return correct elements in DOM tree' , function ( ) {
245
-
246
219
var root = parseHTML ( '<a id="id"><div><span class="a b"></span><span></span><span></span></div></a>' ) ;
247
-
248
220
root . querySelectorAll ( '#id' ) . should . eql ( [ root . firstChild ] ) ;
249
221
root . querySelectorAll ( 'span.a' ) . should . eql ( [ root . firstChild . firstChild . firstChild ] ) ;
250
222
root . querySelectorAll ( 'span.b' ) . should . eql ( [ root . firstChild . firstChild . firstChild ] ) ;
251
223
root . querySelectorAll ( 'span.a.b' ) . should . eql ( [ root . firstChild . firstChild . firstChild ] ) ;
252
224
root . querySelectorAll ( '#id .b' ) . should . eql ( [ root . firstChild . firstChild . firstChild ] ) ;
253
225
root . querySelectorAll ( '#id span' ) . should . eql ( root . firstChild . firstChild . childNodes ) ;
254
-
255
226
} ) ;
256
-
257
227
} ) ;
258
228
259
229
describe ( '#structuredText' , function ( ) {
260
-
261
230
it ( 'should return correct structured text' , function ( ) {
262
-
263
231
var root = parseHTML ( '<span>o<p>a</p><p>b</p>c</span>' ) ;
264
232
root . structuredText . should . eql ( 'o\na\nb\nc' ) ;
265
-
266
233
} ) ;
267
-
268
234
} ) ;
269
235
describe ( '#set_content' , function ( ) {
270
-
271
236
it ( 'set content string' , function ( ) {
272
237
var root = parseHTML ( '<div></div>' ) ;
273
238
root . childNodes [ 0 ] . set_content ( '<span><div>abc</div>bla</span>' ) ;
@@ -288,9 +253,7 @@ describe('HTML Parser', function () {
288
253
root . childNodes [ 0 ] . set_content ( 'abc' ) ;
289
254
root . toString ( ) . should . eql ( '<div>abc</div>' ) ;
290
255
} ) ;
291
-
292
256
} ) ;
293
-
294
257
} ) ;
295
258
296
259
describe ( 'stringify' , function ( ) {
0 commit comments