/
test.js
71 lines (66 loc) · 1.75 KB
/
test.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
var renderUnit = require('./js2html').renderUnit
var renderList = require('./js2html').renderList
var assert = require('assert')
var unit = ['html', [
['head', [
['meta/', {
charset: 'utf-8'
}],
['meta/', {
name: 'viewport',
content: 'width=device-width, initial-scale=1.0, user-scalable=no'
}],
['title', 'Page Title']
]],
['body', [
['article', [
['h1', 'Article Heading'],
['p', 'Paragraph 01'],
['p', ['Paragraph 02']],
'Random String',
['br/'],
['audio#id.c1.c2', {
preload: true,
autoplay: false,
loop: null,
//'class': 'c3 c4',
//'class': ['c3', 'c4'],
'class': {
c3: true,
c4: true,
c5: false
},
'data-a': '',
'data-b': 'b',
'data-c': {
c: 1,
c1: 'sad"\'s'
}
}, [
['source/', {
type: 'audio/mp3',
src: 'media/audio-01.mp3'
}]
]],
['img/', {
src: 'images/picture-01.jpg',
alt: 'Picture 01'
}]
]]
]]
]]
var html = '<html><head><meta charset="utf-8"/>\
<meta name="viewport" content="width=device-width, \
initial-scale=1.0, user-scalable=no"/><title>Page Title</title>\
</head><body><article><h1>Article Heading</h1><p>Paragraph 01</p>\
<p>Paragraph 02</p>Random String<br/>\
<audio id="id" preload \
data-a="" data-b="b" data-c={"c":1,"c1":"sad\\"\'s"} class="c1 c2 c3 c4">\
<source type="audio/mp3" src="media/audio-01.mp3"/>\
</audio><img src="images/picture-01.jpg" alt="Picture 01"/>\
</article></body></html>'
console.log(html)
assert.equal(renderUnit(unit), html)
console.log('it parses unit!')
assert.equal(renderList([unit]), html)
console.log('it parses list!')