@markuplint/pug-parser 3.0.0-alpha.6 → 3.0.0-dev.176

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,556 @@
1
+ const { nodeListToDebugMaps } = require('@markuplint/parser-utils');
2
+
3
+ const { parse } = require('../lib/');
4
+
5
+ describe('parser', () => {
6
+ it('syntax error', () => {
7
+ expect(() => {
8
+ parse('div(');
9
+ }).toThrow('The end of the string reached with no closing bracket ) found.');
10
+ });
11
+
12
+ it('empty code', () => {
13
+ const doc = parse('');
14
+ expect(doc.nodeList).toStrictEqual([]);
15
+ expect(doc.nodeList.length).toBe(0);
16
+ });
17
+
18
+ it('text only', () => {
19
+ const doc = parse('| text');
20
+ expect(doc.nodeList[0].nodeName).toBe('#text');
21
+ expect(doc.nodeList[0].raw).toBe('text');
22
+ expect(doc.nodeList.length).toBe(1);
23
+ });
24
+
25
+ it('element', () => {
26
+ const doc = parse('div');
27
+ expect(doc.nodeList[0].nodeName).toBe('div');
28
+ expect(doc.nodeList[0].raw).toBe('div');
29
+ expect(doc.nodeList.length).toBe(1);
30
+ });
31
+
32
+ it('with attribute', () => {
33
+ const doc = parse('div(data-attr="value")');
34
+ expect(doc.nodeList[0].nodeName).toBe('div');
35
+ expect(doc.nodeList[0].raw).toBe('div(data-attr="value")');
36
+ expect(doc.nodeList.length).toBe(1);
37
+ expect(doc.nodeList[0].attributes.length).toBe(1);
38
+ expect(doc.nodeList[0].attributes[0].name.raw).toBe('data-attr');
39
+ expect(doc.nodeList[0].attributes[0].value.raw).toBe('value');
40
+ });
41
+
42
+ it('with dynamic attribute', () => {
43
+ const doc = parse(
44
+ 'div(data-attr= variable + variable2 data-attr2 = variable3 + variable4 data-attr3 data-attr4 = `${variable5}`)',
45
+ );
46
+ expect(doc.nodeList[0].nodeName).toBe('div');
47
+ expect(doc.nodeList[0].raw).toBe(
48
+ 'div(data-attr= variable + variable2 data-attr2 = variable3 + variable4 data-attr3 data-attr4 = `${variable5}`)',
49
+ );
50
+ expect(doc.nodeList.length).toBe(1);
51
+ expect(doc.nodeList[0].attributes.length).toBe(4);
52
+ expect(doc.nodeList[0].attributes[0].name.raw).toBe('data-attr');
53
+ expect(doc.nodeList[0].attributes[0].value.raw).toBe('variable + variable2');
54
+ expect(doc.nodeList[0].attributes[1].name.raw).toBe('data-attr2');
55
+ expect(doc.nodeList[0].attributes[1].value.raw).toBe('variable3 + variable4');
56
+ expect(doc.nodeList[0].attributes[2].name.raw).toBe('data-attr3');
57
+ expect(doc.nodeList[0].attributes[2].value.raw).toBe('');
58
+ expect(doc.nodeList[0].attributes[3].name.raw).toBe('data-attr4');
59
+ expect(doc.nodeList[0].attributes[3].value.raw).toBe('${variable5}');
60
+ });
61
+
62
+ it('ID and Classes', () => {
63
+ const doc = parse('div#the-id.the-class.the-class2');
64
+ expect(doc.nodeList[0].attributes[0].potentialName).toBe('id');
65
+ expect(doc.nodeList[0].attributes[0].potentialValue).toBe('the-id');
66
+ expect(doc.nodeList[0].attributes[1].potentialName).toBe('class');
67
+ expect(doc.nodeList[0].attributes[1].potentialValue).toBe('the-class');
68
+ expect(doc.nodeList[0].attributes[2].potentialName).toBe('class');
69
+ expect(doc.nodeList[0].attributes[2].potentialValue).toBe('the-class2');
70
+ });
71
+
72
+ it('HTML in Pug', () => {
73
+ const doc = parse(
74
+ `div
75
+ <span data-hoge hoge>Text</span>
76
+ <span data-hoge2 hoge2>Text2</span>`,
77
+ );
78
+ // console.log(doc.nodeList);
79
+ // const map = nodeListToDebugMaps(doc.nodeList);
80
+ // console.log(map);
81
+
82
+ expect(doc.nodeList[0].nodeName).toBe('div');
83
+ expect(doc.nodeList[1].nodeName).toBe('span');
84
+ expect(doc.nodeList[1].attributes[0].name.raw).toBe('data-hoge');
85
+ expect(doc.nodeList[1].attributes[1].name.raw).toBe('hoge');
86
+ expect(doc.nodeList[0].childNodes[0].nodeName).toBe('span');
87
+ });
88
+
89
+ it('standard code', () => {
90
+ const doc = parse(`doctype html
91
+ html
92
+ head
93
+ meta(charset='UTF-8')
94
+ meta(name="viewport" content='width=device-width, initial-scale=1.0')
95
+ meta(http-equiv='X-UA-Compatible' content='ie=edge')
96
+ title Document
97
+ body
98
+ script.
99
+ const i = 0;
100
+ // html-comment
101
+ div
102
+ | text&amp;div
103
+ table
104
+ tr
105
+ th header
106
+ td cell
107
+ table
108
+ tbody
109
+ tr
110
+ th header
111
+ td cell
112
+ img(src=path/to)
113
+ `);
114
+ const map = nodeListToDebugMaps(doc.nodeList);
115
+ // console.log(doc.nodeList[doc.nodeList.length - 1]);
116
+ // console.log(map);
117
+ expect(map).toStrictEqual([
118
+ '[1:1]>[1:13](0,12)#doctype: doctype␣html',
119
+ '[2:1]>[2:5](13,17)html: html',
120
+ '[3:2]>[3:6](19,23)head: head',
121
+ "[4:3]>[4:24](26,47)meta: meta(charset='UTF-8')",
122
+ '[5:3]>[5:72](50,119)meta: meta(name="viewport"␣content=\'width=device-width,␣initial-scale=1.0\')',
123
+ "[6:3]>[6:55](122,174)meta: meta(http-equiv='X-UA-Compatible'␣content='ie=edge')",
124
+ '[7:3]>[7:8](177,182)title: title',
125
+ '[7:9]>[8:2](183,193)#text: Document⏎→',
126
+ '[8:2]>[8:6](193,197)body: body',
127
+ '[9:3]>[9:9](200,206)script: script',
128
+ '[10:4]>[10:16](211,223)#text: const␣i␣=␣0;',
129
+ '[11:3]>[11:18](226,241)#comment: //␣html-comment',
130
+ '[12:3]>[12:6](244,247)div: div',
131
+ '[13:6]>[14:3](253,268)#text: text&amp;div⏎→→',
132
+ '[14:3]>[14:8](268,273)table: table',
133
+ '[15:4]>[15:6](277,279)tr: tr',
134
+ '[16:4]>[16:6](283,285)th: th',
135
+ '[16:7]>[16:13](286,292)#text: header',
136
+ '[17:4]>[17:6](296,298)td: td',
137
+ '[17:7]>[18:3](299,306)#text: cell⏎→→',
138
+ '[18:3]>[18:8](306,311)table: table',
139
+ '[19:4]>[19:9](315,320)tbody: tbody',
140
+ '[20:4]>[20:6](324,326)tr: tr',
141
+ '[21:5]>[21:7](331,333)th: th',
142
+ '[21:8]>[21:14](334,340)#text: header',
143
+ '[22:5]>[22:7](345,347)td: td',
144
+ '[22:8]>[23:3](348,355)#text: cell⏎→→',
145
+ '[23:3]>[23:19](355,371)img: img(src=path/to)',
146
+ ]);
147
+ });
148
+
149
+ it('minimum code', () => {
150
+ const doc = parse(`html
151
+ head
152
+ title Title
153
+ body
154
+ h1 Title
155
+ `);
156
+ const map = nodeListToDebugMaps(doc.nodeList);
157
+ // console.log(doc.nodeList);
158
+ // console.log(map);
159
+ expect(map).toStrictEqual([
160
+ '[1:1]>[1:5](0,4)html: html',
161
+ '[2:2]>[2:6](6,10)head: head',
162
+ '[3:3]>[3:8](13,18)title: title',
163
+ '[3:9]>[4:2](19,26)#text: Title⏎→',
164
+ '[4:2]>[4:6](26,30)body: body',
165
+ '[5:3]>[5:5](33,35)h1: h1',
166
+ '[5:6]>[6:1](36,42)#text: Title⏎',
167
+ ]);
168
+ });
169
+
170
+ it('deep structure code', () => {
171
+ const doc = parse(`div(data-depth=0)
172
+ div(data-depth=1)
173
+ div(data-depth=2)
174
+ div(data-depth=3)
175
+ div(data-depth=4)
176
+ div(data-depth=5)
177
+ div(data-depth=6)
178
+ div(data-depth=7)
179
+ div(data-depth=8)
180
+ div(data-depth=9)
181
+ div(data-depth=10)
182
+ div(data-depth=11)
183
+ div(data-depth=12)
184
+ div(data-depth=13)
185
+ div(data-depth=14)
186
+ div(data-depth=15)
187
+ div(data-depth=16)
188
+ div(data-depth=17)
189
+ div(data-depth=18)
190
+ div(data-depth=19)
191
+ `);
192
+ const map = nodeListToDebugMaps(doc.nodeList);
193
+ // console.log(doc.nodeList);
194
+ // console.log(map);
195
+ expect(map).toStrictEqual([
196
+ '[1:1]>[1:18](0,17)div: div(data-depth=0)',
197
+ '[2:3]>[2:20](20,37)div: div(data-depth=1)',
198
+ '[3:4]>[3:21](41,58)div: div(data-depth=2)',
199
+ '[4:5]>[4:22](63,80)div: div(data-depth=3)',
200
+ '[5:6]>[5:23](86,103)div: div(data-depth=4)',
201
+ '[6:7]>[6:24](110,127)div: div(data-depth=5)',
202
+ '[7:8]>[7:25](135,152)div: div(data-depth=6)',
203
+ '[8:9]>[8:26](161,178)div: div(data-depth=7)',
204
+ '[9:10]>[9:27](188,205)div: div(data-depth=8)',
205
+ '[10:11]>[10:28](216,233)div: div(data-depth=9)',
206
+ '[11:12]>[11:30](245,263)div: div(data-depth=10)',
207
+ '[12:13]>[12:31](276,294)div: div(data-depth=11)',
208
+ '[13:14]>[13:32](308,326)div: div(data-depth=12)',
209
+ '[14:15]>[14:33](341,359)div: div(data-depth=13)',
210
+ '[15:16]>[15:34](375,393)div: div(data-depth=14)',
211
+ '[16:17]>[16:35](410,428)div: div(data-depth=15)',
212
+ '[17:18]>[17:36](446,464)div: div(data-depth=16)',
213
+ '[18:19]>[18:37](483,501)div: div(data-depth=17)',
214
+ '[19:20]>[19:38](521,539)div: div(data-depth=18)',
215
+ '[20:21]>[20:39](560,578)div: div(data-depth=19)',
216
+ ]);
217
+ });
218
+
219
+ it('code in code', () => {
220
+ const doc = parse(`ul
221
+ each i in obj
222
+ li= i
223
+ `);
224
+ const map = nodeListToDebugMaps(doc.nodeList);
225
+ // console.log(doc.nodeList);
226
+ // console.log(map);
227
+ expect(map).toStrictEqual([
228
+ '[1:1]>[1:3](0,2)ul: ul',
229
+ '[2:2]>[2:15](4,17)Each: each␣i␣in␣obj',
230
+ '[3:3]>[3:5](20,22)li: li',
231
+ '[3:5]>[3:8](22,25)Code: =␣i',
232
+ ]);
233
+ });
234
+
235
+ it('code in code', () => {
236
+ const doc = parse(`if bool
237
+ | 1
238
+ else if bool2
239
+ | 2
240
+ else
241
+ | 3
242
+ `);
243
+ const map = nodeListToDebugMaps(doc.nodeList);
244
+ // console.log(doc.nodeList);
245
+ // console.log(map);
246
+ expect(map).toStrictEqual([
247
+ '[1:1]>[1:8](0,7)Conditional: if␣bool',
248
+ '[2:4]>[3:1](11,13)#text: 1⏎',
249
+ '[3:1]>[3:14](13,26)Conditional: else␣if␣bool2',
250
+ '[4:4]>[5:1](30,32)#text: 2⏎',
251
+ '[5:1]>[5:5](32,36)Conditional: else',
252
+ '[6:4]>[7:1](40,42)#text: 3⏎',
253
+ ]);
254
+ });
255
+
256
+ it('HTML in Pug', () => {
257
+ const doc = parse(
258
+ `section
259
+ div
260
+ <span>
261
+ <img src="path/to">
262
+ </span>
263
+ `,
264
+ );
265
+ // console.log(doc.nodeList);
266
+ const map = nodeListToDebugMaps(doc.nodeList);
267
+ // console.log(map);
268
+ expect(map).toStrictEqual([
269
+ '[1:1]>[1:8](0,7)section: section',
270
+ '[2:2]>[2:5](9,12)div: div',
271
+ '[3:3]>[3:9](15,21)span: <span>',
272
+ '[3:9]>[4:4](21,25)#text: ⏎→→→',
273
+ '[4:4]>[4:25](25,44)img: <img␣src="path/to">',
274
+ '[4:23]>[5:3](44,47)#text: ⏎→→',
275
+ '[5:3]>[5:10](47,54)span: </span>',
276
+ '[5:10]>[6:4](54,58)#text: ⏎→→→',
277
+ ]);
278
+ });
279
+
280
+ it('tag interpolation (Issue #58)', () => {
281
+ const doc = parse(`p
282
+ | lorem #[span ipsum]`);
283
+ const map = nodeListToDebugMaps(doc.nodeList);
284
+ // console.log(map);
285
+ expect(doc.unknownParseError).toBeUndefined();
286
+ expect(map).toStrictEqual([
287
+ '[1:1]>[1:2](0,1)p: p',
288
+ '[2:4]>[2:10](5,11)#text: lorem␣',
289
+ '[2:12]>[2:16](13,17)span: span',
290
+ '[2:17]>[2:22](18,23)#text: ipsum',
291
+ ]);
292
+ });
293
+
294
+ it('block-in-tag div', () => {
295
+ const doc = parse(`div.
296
+ <span>text</span>`);
297
+ const map = nodeListToDebugMaps(doc.nodeList);
298
+ expect(doc.unknownParseError).toBeUndefined();
299
+ expect(map).toStrictEqual([
300
+ '[1:1]>[1:4](0,3)div: div',
301
+ '[2:2]>[2:8](6,12)span: <span>',
302
+ '[2:8]>[2:12](12,16)#text: text',
303
+ '[2:12]>[2:19](16,23)span: </span>',
304
+ ]);
305
+ });
306
+
307
+ it('block-in-tag div 2', () => {
308
+ const doc = parse(`.root.
309
+ <div>
310
+ text
311
+ </div>`);
312
+ const map = nodeListToDebugMaps(doc.nodeList);
313
+ expect(doc.unknownParseError).toBeUndefined();
314
+ expect(map).toStrictEqual([
315
+ '[1:1]>[1:6](0,5)div: .root',
316
+ '[1:7]>[2:2](6,8)#text: ⏎→',
317
+ '[2:2]>[2:13](8,13)div: <div>',
318
+ '[2:7]>[4:2](13,22)#text: ⏎→→text⏎→',
319
+ '[4:2]>[4:8](22,28)div: </div>',
320
+ ]);
321
+ });
322
+
323
+ it('block-in-tag div 3', () => {
324
+ const doc = parse(`.root.
325
+ <div>
326
+ <img />
327
+ </div>`);
328
+ const map = nodeListToDebugMaps(doc.nodeList);
329
+ expect(doc.unknownParseError).toBeUndefined();
330
+ expect(map).toStrictEqual([
331
+ '[1:1]>[1:6](0,5)div: .root',
332
+ '[1:7]>[2:2](6,8)#text: ⏎→',
333
+ '[2:2]>[2:13](8,13)div: <div>',
334
+ '[2:7]>[3:3](13,16)#text: ⏎→→',
335
+ '[3:3]>[3:16](16,23)img: <img␣/>',
336
+ '[3:10]>[4:2](23,25)#text: ⏎→',
337
+ '[4:2]>[4:8](25,31)div: </div>',
338
+ ]);
339
+ });
340
+
341
+ it('block-in-tag script', () => {
342
+ const doc = parse(`script.
343
+ const $span = '<span>text</span>';`);
344
+ const map = nodeListToDebugMaps(doc.nodeList);
345
+ expect(doc.unknownParseError).toBeUndefined();
346
+ expect(map).toStrictEqual([
347
+ '[1:1]>[1:7](0,6)script: script',
348
+ "[2:2]>[2:36](9,43)#text: const␣$span␣=␣'<span>text</span>';",
349
+ ]);
350
+ });
351
+
352
+ it('block-in-tag script2', () => {
353
+ const doc = parse(`div.
354
+ <script> var a = "<aaaa>"; </script>`);
355
+ const map = nodeListToDebugMaps(doc.nodeList);
356
+ expect(doc.unknownParseError).toBeUndefined();
357
+ expect(map).toStrictEqual([
358
+ '[1:1]>[1:4](0,3)div: div',
359
+ '[2:2]>[2:10](6,14)script: <script>',
360
+ '[2:10]>[2:29](14,33)#text: ␣var␣a␣=␣"<aaaa>";␣',
361
+ '[2:29]>[2:38](33,42)script: </script>',
362
+ ]);
363
+ const code = doc.nodeList[1].childNodes[0];
364
+ expect(code.raw).toBe(' var a = "<aaaa>"; ');
365
+ expect(code.parentNode.nodeName).toBe('script');
366
+ });
367
+
368
+ it('block-in-tag attr', () => {
369
+ const doc = parse(`div.
370
+ <input invalid-attr/>
371
+ <input invalid-attr/>`);
372
+ const map = nodeListToDebugMaps(doc.nodeList);
373
+ expect(doc.unknownParseError).toBeUndefined();
374
+ expect(map).toStrictEqual([
375
+ '[1:1]>[1:4](0,3)div: div',
376
+ '[1:5]>[2:2](4,6)#text: ⏎→',
377
+ '[2:2]>[2:27](6,27)input: <input␣invalid-attr/>',
378
+ '[2:23]>[3:2](27,29)#text: ⏎→',
379
+ '[3:2]>[3:27](29,50)input: <input␣invalid-attr/>',
380
+ ]);
381
+ const input1 = doc.nodeList[2];
382
+ const input2 = doc.nodeList[4];
383
+ expect(input1.startOffset).toBe(6);
384
+ expect(input1.startLine).toBe(2);
385
+ expect(input1.startCol).toBe(2);
386
+ expect(input1.attributes[0].startLine).toBe(2);
387
+ expect(input1.attributes[0].startCol).toBe(9);
388
+ expect(input2.startOffset).toBe(29);
389
+ expect(input2.startLine).toBe(3);
390
+ expect(input2.startCol).toBe(2);
391
+ expect(input2.attributes[0].startLine).toBe(3);
392
+ expect(input2.attributes[0].startCol).toBe(9);
393
+ });
394
+
395
+ it('block-in-tag attr2', () => {
396
+ const doc = parse(
397
+ '\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\ndiv.\n\t<input invalid-attr/>\n\t<input invalid-attr invalid-attr2/>',
398
+ );
399
+ const map = nodeListToDebugMaps(doc.nodeList);
400
+ expect(doc.unknownParseError).toBeUndefined();
401
+ expect(map).toStrictEqual([
402
+ '[21:1]>[21:4](20,23)div: div',
403
+ '[21:5]>[22:2](24,26)#text: ⏎→',
404
+ '[22:2]>[22:27](26,47)input: <input␣invalid-attr/>',
405
+ '[22:23]>[23:2](47,49)#text: ⏎→',
406
+ '[23:2]>[23:41](49,84)input: <input␣invalid-attr␣invalid-attr2/>',
407
+ ]);
408
+ const input1 = doc.nodeList[2];
409
+ const input2 = doc.nodeList[4];
410
+ const attr1 = input1.attributes[0];
411
+ const attr2 = input2.attributes[0];
412
+ const attr3 = input2.attributes[1];
413
+ expect(attr1.startLine).toBe(22);
414
+ expect(attr1.startCol).toBe(9);
415
+ expect(attr1.name.startLine).toBe(22);
416
+ expect(attr1.name.startCol).toBe(9);
417
+ expect(attr2.startLine).toBe(23);
418
+ expect(attr2.startCol).toBe(9);
419
+ expect(attr2.name.startLine).toBe(23);
420
+ expect(attr2.name.startCol).toBe(9);
421
+ expect(attr3.startLine).toBe(23);
422
+ expect(attr3.startCol).toBe(22);
423
+ expect(attr3.name.startLine).toBe(23);
424
+ expect(attr3.name.startCol).toBe(22);
425
+ });
426
+
427
+ // TODO: If there is an HTML tag in siblings
428
+ // it.only('html', () => {
429
+ // const doc = parse('div\n<input invalid-attr/>\n<input invalid-attr/>');
430
+ // const map = nodeListToDebugMaps(doc.nodeList);
431
+ // expect(doc.parseError).toBeUndefined();
432
+ // expect(map).toStrictEqual(['[1:1]>[1:4](0,3)div: div', '[2:1]>[2:22](4,25)input: <input␣invalid-attr/>']);
433
+ // const input1 = doc.nodeList[1];
434
+ // const input2 = doc.nodeList[2];
435
+ // const attr1 = input1.attributes[0];
436
+ // const attr2 = input2.attributes[0];
437
+ // expect(attr1.startLine).toBe(2);
438
+ // expect(attr1.startCol).toBe(8);
439
+ // expect(attr1.name.startLine).toBe(2);
440
+ // expect(attr1.name.startCol).toBe(9);
441
+ // expect(attr2.startLine).toBe(3);
442
+ // expect(attr2.startCol).toBe(8);
443
+ // expect(attr2.name.startLine).toBe(3);
444
+ // expect(attr2.name.startCol).toBe(9);
445
+ // });
446
+
447
+ it('attribute', () => {
448
+ const doc = parse('div(data-hoge="content")');
449
+ const attr = doc.nodeList[0].attributes[0];
450
+ if (attr.type !== 'html-attr') {
451
+ return;
452
+ }
453
+ expect(attr.raw).toEqual('data-hoge="content"');
454
+ expect(attr.name.raw).toEqual('data-hoge');
455
+ expect(attr.equal.raw).toEqual('=');
456
+ expect(attr.startQuote.raw).toEqual('"');
457
+ expect(attr.value.raw).toEqual('content');
458
+ expect(attr.endQuote.raw).toEqual('"');
459
+ });
460
+
461
+ it('attribute 2', () => {
462
+ const doc = parse("div(data-hoge='content')");
463
+ const attr = doc.nodeList[0].attributes[0];
464
+ if (attr.type !== 'html-attr') {
465
+ return;
466
+ }
467
+ expect(attr.raw).toEqual("data-hoge='content'");
468
+ expect(attr.name.raw).toEqual('data-hoge');
469
+ expect(attr.equal.raw).toEqual('=');
470
+ expect(attr.startQuote.raw).toEqual("'");
471
+ expect(attr.value.raw).toEqual('content');
472
+ expect(attr.endQuote.raw).toEqual("'");
473
+ });
474
+
475
+ it('attribute 3', () => {
476
+ const doc = parse(`div.
477
+ <span data-attr="value">`);
478
+ // console.log(doc.nodeList);
479
+ const attr = doc.nodeList[1].attributes[0];
480
+ if (attr.type !== 'html-attr') {
481
+ return;
482
+ }
483
+ expect(attr.raw).toEqual('data-attr="value"');
484
+ expect(attr.startCol).toEqual(8);
485
+ expect(attr.name.raw).toEqual('data-attr');
486
+ expect(attr.name.startCol).toEqual(8);
487
+ expect(attr.equal.raw).toEqual('=');
488
+ expect(attr.equal.startCol).toEqual(17);
489
+ expect(attr.startQuote.raw).toEqual('"');
490
+ expect(attr.startQuote.startCol).toEqual(18);
491
+ expect(attr.value.raw).toEqual('value');
492
+ expect(attr.value.startCol).toEqual(19);
493
+ expect(attr.endQuote.raw).toEqual('"');
494
+ expect(attr.endQuote.startCol).toEqual(24);
495
+ });
496
+
497
+ it('add space to below', () => {
498
+ const doc = parse(` \n \n \nhtml
499
+ head
500
+ title Title
501
+ body
502
+ h1 Title
503
+ `);
504
+ const map = nodeListToDebugMaps(doc.nodeList);
505
+ // console.log(doc.nodeList);
506
+ // console.log(map);
507
+ expect(map).toStrictEqual([
508
+ '[1:1]>[1:4](0,3)#text: ␣␣␣',
509
+ '[4:1]>[4:5](20,24)html: html',
510
+ '[5:2]>[5:6](26,30)head: head',
511
+ '[6:3]>[6:8](33,38)title: title',
512
+ '[6:9]>[7:2](39,46)#text: Title⏎→',
513
+ '[7:2]>[7:6](46,50)body: body',
514
+ '[8:3]>[8:5](53,55)h1: h1',
515
+ '[8:6]>[9:1](56,62)#text: Title⏎',
516
+ ]);
517
+ });
518
+
519
+ it('with frontmatter', () => {
520
+ const doc = parse(
521
+ `---
522
+ prop: value
523
+ ---
524
+ html
525
+ head
526
+ title Title
527
+ body
528
+ h1 Title
529
+ `,
530
+ { ignoreFrontMatter: true },
531
+ );
532
+ const map = nodeListToDebugMaps(doc.nodeList);
533
+ // console.log(doc.nodeList);
534
+ // console.log(map);
535
+ expect(map).toStrictEqual([
536
+ '[1:1]>[1:4](0,3)#text: ␣␣␣',
537
+ '[4:1]>[4:5](20,24)html: html',
538
+ '[5:2]>[5:6](26,30)head: head',
539
+ '[6:3]>[6:8](33,38)title: title',
540
+ '[6:9]>[7:2](39,46)#text: Title⏎→',
541
+ '[7:2]>[7:6](46,50)body: body',
542
+ '[8:3]>[8:5](53,55)h1: h1',
543
+ '[8:6]>[9:1](56,62)#text: Title⏎',
544
+ ]);
545
+ });
546
+
547
+ it('namespace', () => {
548
+ const doc = parse('div: svg: text');
549
+ expect(doc.nodeList[0].nodeName).toBe('div');
550
+ expect(doc.nodeList[0].namespace).toBe('http://www.w3.org/1999/xhtml');
551
+ expect(doc.nodeList[1].nodeName).toBe('svg');
552
+ expect(doc.nodeList[1].namespace).toBe('http://www.w3.org/2000/svg');
553
+ expect(doc.nodeList[2].nodeName).toBe('text');
554
+ expect(doc.nodeList[2].namespace).toBe('http://www.w3.org/2000/svg');
555
+ });
556
+ });