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
|
var fs = require('fs'),
test = require('tape'),
through = require('through2'),
tokenize = require('../')
test('basic', function(t) {
var tok = tokenize();
var input = "html { font-size: 10px; }"
var expected = [
['rule_start', 'html {'],
['rule', ' font-size: 10px; '],
['rule_end', '}']
]
t.plan(expected.length);
tok.pipe(through.obj(function(token, enc, next) {
token[1] = token[1].toString();
if (expected.length > 0) t.same(token, expected.shift())
next();
}))
tok.end(input);
})
test('at-rule nesting', function(t) {
var tok = tokenize();
var expected = [
[ 'atrule_start', '@media screen and (min-width: 1000px) {' ],
[ 'atrule', '\n ' ],
[ 'rule_start', 'a {' ],
[ 'rule', '\n text-decoration: underline;\n ' ],
[ 'rule_end', '}' ],
[ 'atrule', '\n' ],
[ 'atrule_end', '}' ],
[ 'root', '\n' ]
]
t.plan(expected.length);
tok.pipe(through.obj(function(token, enc, next) {
token[1] = token[1].toString();
if (expected.length > 0) t.same(token, expected.shift())
next();
}))
fs.createReadStream(__dirname + '/nested.css').pipe(tok);
})
test('gauntlet', function(t) {
var tok = tokenize();
var expected = [
['root', '\n'],
['rule_start', 'div {'],
['rule', '\n background: red;\n'],
['rule_end', '}'],
['root', '\n\n'],
['rule_start', '.cls {'],
['rule', '\n color: green;\n'],
['rule_end', '}'],
['root', '\n\n'],
['rule_start', '#id {'],
['rule', '\n font-size: 10px;\n'],
['rule_end', '}'],
['comment', '\n\n/* comment */'],
['space', '\n\n'],
['atrule_start', '@media screen and (min-width: 1000px) {'],
['atrule', '\n '],
['rule_start', 'a {'],
['rule', '\n text-decoration: underline;\n '],
['rule_end', '}'],
['atrule', '\n'],
['atrule_end', '}'],
['root', '\n\n'],
['rule_start', 'a:hover {'],
['rule', '\n font-weight: bold; \n'],
['rule_end', '}'],
['root', '\n\n'],
['rule_start', 'section \n\n\n{'],
['rule', '\n margin: 0;\n '],
['comment', '/* comment wthin a rule */'],
['rule', '\n padding: 5px;\n'],
['rule_end', '}'],
['root', '\n\n\n'],
['rule_start', 'body > * {'],
['rule', '\n \n'],
['rule_end', '}'],
['root', '\n']
]
t.plan(expected.length);
tok.pipe(through.obj(function(token, enc, next) {
token[1] = token[1].toString();
if (expected.length > 0) t.same(token, expected.shift())
next();
}));
fs.createReadStream(__dirname + '/gauntlet.css').pipe(tok);
})
|