This repository has been archived by the owner on Feb 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
streamReaders.spec.js
83 lines (71 loc) · 2.66 KB
/
streamReaders.spec.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
import * as streamReaders from '../../src/streamReaders';
describe('streamReaders', () => {
describe('#comment', () => {
it('reads comment with no remainder', () => {
const tok = streamReaders.comment('-->');
expect(tok).to.have.property('content', '');
expect(tok).to.have.property('length', 3);
});
it('reads comment with remainder', () => {
const tok = streamReaders.comment('-->foo');
expect(tok).to.have.property('content', '');
expect(tok).to.have.property('length', 3);
});
it('returns undefined for no comment', () => {
const tok = streamReaders.comment('-!->');
expect(tok).not.to.be.ok();
});
});
describe('#endTag', () => {
it('reads an end tag', () => {
const tok = streamReaders.endTag('</div>');
expect(tok).to.have.property('tagName', 'div');
expect(tok).to.have.property('length', 6);
});
it('returns undefined for not an end tag', () => {
const tok = streamReaders.endTag('<div>');
expect(tok).not.to.be.ok();
});
});
describe('#chars', () => {
it('reads until tag start', () => {
const tok = streamReaders.chars('foo</div>');
expect(tok).to.have.property('length', 3);
});
it('consumes everything if not tag', () => {
const tok = streamReaders.chars('foo');
expect(tok).to.have.property('length', 3);
});
});
describe('#atomicTag', () => {
it('reads an atomic tag', () => {
const tok = streamReaders.atomicTag('<div class="foo">content</div>');
expect(tok).to.have.property('tagName', 'div');
expect(tok).to.have.property('attrs');
expect(tok.attrs).to.have.property('class', 'foo');
expect(tok).to.have.property('content', 'content');
expect(tok).to.have.property('length', 30);
});
it('returns undefined for a broken atomic tag', () => {
const tok = streamReaders.atomicTag('<b class="foo">content</i>');
expect(tok).not.to.be.ok();
});
});
describe('#startTag', () => {
it('reads a start tag', () => {
const tok = streamReaders.startTag('<b class="foo">content</b>');
expect(tok).to.have.property('tagName', 'b');
expect(tok).to.have.property('attrs');
expect(tok.attrs).to.have.property('class', 'foo');
expect(tok).to.have.property('booleanAttrs');
expect(tok.booleanAttrs).to.be.empty();
expect(tok).to.have.property('rest', '');
expect(tok).to.have.property('unary', false);
expect(tok).to.have.property('length', 15);
});
it('returns undefined for not a start tag', () => {
const tok = streamReaders.startTag('</foo>');
expect(tok).not.to.be.ok();
});
});
});