Skip to content

Commit 433a225

Browse files
committed
Update test.html to actually work. Fixes #28.
1 parent 91f2450 commit 433a225

1 file changed

Lines changed: 117 additions & 62 deletions

File tree

test.html

Lines changed: 117 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<!doctype html>
22
<title>Tests</title>
3-
<script src="tokenizer.js"></script>
4-
<script src="parser.js"></script>
3+
<script src="parse-css.js"></script>
54
<script src="diff.js"></script>
65
<style>
76
ins { background: hsl(120, 50%, 90%); color: greeen; }
@@ -10,79 +9,135 @@
109
</style>
1110
<script>
1211
function log(str) {
13-
document.querySelector('#log').innerHTML += str+'\n';
12+
document.querySelector('#log').innerHTML += str+'\n';
1413
}
1514
</script>
1615
<pre id='log'></pre>
1716
<script>
1817
var TESTS = [
19-
{
20-
css: 'foo { \
21-
bar: baz; \
22-
}',
23-
expected: {"type": "stylesheet", "value": [
24-
{
25-
"type": "selector",
26-
"selector": ["IDENT(foo)", "WS"],
27-
"value": [
28-
{
29-
"type": "declaration",
30-
"name": "bar",
31-
"value": ["WS", "IDENT(baz)"]}]}]
32-
}
33-
}, {
34-
css: 'foo { bar: rgb(255, 0, 127); }',
35-
expected: {"type": "stylesheet", "value": [
36-
{
37-
"type": "selector",
38-
"selector": ["IDENT(foo)", "WS"],
39-
"value": [
40-
{
41-
"type": "declaration",
42-
"name": "bar",
43-
"value": ["WS", {"type": "func", "name": "rgb", "value": [
44-
["INT(255)"], ["WS", "INT(0)"], ["WS", "INT(127)"]]}]}]}]
45-
}
46-
}, {
47-
css: '#foo {}',
48-
expected: {"type": "stylesheet", "value": [
49-
{
50-
"type": "selector",
51-
"selector": ["HASH(foo)", "WS"],
52-
"value": []}]
53-
}
54-
}, {
55-
css: '@media{ }',
56-
expected: {"type": "stylesheet", "value": [
57-
{
58-
"type": "at", "name": "media",
59-
"prelude": [],
60-
"value": []}]}
61-
}
18+
{
19+
css: 'foo { \
20+
bar: baz; \
21+
}',
22+
expected: {"type": "STYLESHEET",
23+
"value": [
24+
{"type": "QUALIFIED-RULE",
25+
"value": {"type": "BLOCK",
26+
"value": [
27+
{"token": "WHITESPACE"},
28+
{"token": "IDENT", "value": "bar"},
29+
{"token": ":"},
30+
{"token": "WHITESPACE"},
31+
{"token": "IDENT", "value": "baz"},
32+
{"token": ";"},
33+
{"token": "WHITESPACE"}
34+
],
35+
"name": "{"
36+
},
37+
"prelude": [
38+
{"token": "IDENT", "value": "foo"},
39+
{"token": "WHITESPACE"}
40+
]
41+
}
42+
]
43+
}
44+
}, {
45+
css: 'foo { bar: rgb(255, 0, 127); }',
46+
expected: {"type": "STYLESHEET",
47+
"value": [
48+
{
49+
"type": "QUALIFIED-RULE",
50+
"value": {
51+
"type": "BLOCK",
52+
"value": [
53+
{"token": "WHITESPACE"},
54+
{"token": "IDENT", "value": "bar"},
55+
{"token": ":"},
56+
{"token": "WHITESPACE"},
57+
{"type": "FUNCTION",
58+
"value": [
59+
{"token": "NUMBER", "value": 255, "type": "integer", "repr": "255"},
60+
{"token": ","},
61+
{"token": "WHITESPACE"},
62+
{"token": "NUMBER", "value": 0, "type": "integer", "repr": "0"},
63+
{"token": ","},
64+
{"token": "WHITESPACE"},
65+
{"token": "NUMBER", "value": 127, "type": "integer", "repr": "127"}
66+
],
67+
"name": "rgb"
68+
},
69+
{"token": ";"},
70+
{"token": "WHITESPACE"}
71+
],
72+
"name": "{"
73+
},
74+
"prelude": [
75+
{"token": "IDENT", "value": "foo"},
76+
{"token": "WHITESPACE"}
77+
]
78+
}
79+
]
80+
}
81+
}, {
82+
css: '#foo {}',
83+
expected: {"type": "STYLESHEET",
84+
"value": [
85+
{
86+
"type": "QUALIFIED-RULE",
87+
"value": {
88+
"type": "BLOCK",
89+
"value": [],
90+
"name": "{"
91+
},
92+
"prelude": [
93+
{"token": "HASH", "value": "foo", "type": "id"},
94+
{"token": "WHITESPACE"}
95+
]
96+
}
97+
]
98+
}
99+
}, {
100+
css: '@media{ }',
101+
expected: {"type": "STYLESHEET",
102+
"value": [
103+
{
104+
"type": "AT-RULE",
105+
"value": {"type": "BLOCK",
106+
"value": [
107+
{"token": "WHITESPACE"}
108+
],
109+
"name": "{"
110+
},
111+
"name": "media",
112+
"prelude": []
113+
}
114+
]
115+
}
116+
}
62117
];
63118

64119
var total = TESTS.length, failures = 0,
65-
i, test, tokens, sheet, dump, expected_dump;
120+
i, test, tokens, sheet, dump, expected_dump;
66121

67122
for (i = 0; i < total; i++) {
68-
test = TESTS[i];
69-
tokens = tokenize(test.css);
70-
sheet = parse(tokens);
71-
dump = sheet.toString(' ');
72-
expected_dump = JSON.stringify(test.expected, null, ' ');
73-
if (dump == expected_dump) {
74-
log('Test '+i+' of '+total+': PASS');
75-
} else {
76-
log('Test '+i+' of '+total+': FAIL\nCSS: '+test.css+'\nTokens: '+tokens.join(' '));
77-
log(diffString(expected_dump, dump));
78-
failures++;
79-
}
123+
test = TESTS[i];
124+
tokens = tokenize(test.css);
125+
sheet = parseAStylesheet(tokens);
126+
dump = sheet.toString(' ');
127+
expected_dump = JSON.stringify(test.expected, null, ' ');
128+
if (dump == expected_dump) {
129+
log('Test '+i+' of '+total+': PASS');
130+
} else {
131+
log('Test '+i+' of '+total+': FAIL\nCSS: '+test.css+'\nTokens: '+tokens.join(' '));
132+
log(diffString(expected_dump, dump));
133+
failures++;
134+
}
80135
}
81136

82137
// Abuse the differ to get colored output
83138
if (failures == 0) {
84-
log(diffString(total+' tests, ', total+' tests, all passed :)'));
139+
log(diffString(total+' tests, ', total+' tests, all passed :)'));
85140
} else {
86-
log(diffString(total+' tests, '+failures+' failures :(', total+' tests, '));
141+
log(diffString(total+' tests, '+failures+' failures :(', total+' tests, '));
87142
}
88-
</script>
143+
</script>

0 commit comments

Comments
 (0)