Permalink
Browse files

Updated tests and examples to properly use fillType='declaration'

  • Loading branch information...
1 parent 23d025d commit 9c002704353c3e483b852a0f1ecad1a20071fe84 @tabatkins committed Jul 16, 2012
Showing with 86 additions and 86 deletions.
  1. +1 −1 example.html
  2. +85 −85 tests.js
View
@@ -50,7 +50,7 @@
<script>
var debug;
function parseStuff() {
- AtRule.registry.foo = 'decl';
+ AtRule.registry.foo = 'declaration';
var css = document.querySelector('#css').value;
var tokenlist = tokenize(css);
View
@@ -1,85 +1,85 @@
-// This test suite runs on NodeJS and uses the 'ansidiff' package.
-// Once you have NodeJS, install ansidiff with:
-//
-// npm install ansidiff
-//
-// Then run the test suite with:
-//
-// node tests.js
-
-var TESTS = [
- {
- css: 'foo { bar: baz; }',
- expected: {"type": "stylesheet", "value": [
- {
- "type": "selector",
- "selector": ["IDENT(foo)", "WS"],
- "value": [
- {
- "type": "decl",
- "name": "bar",
- "value": ["WS", "IDENT(baz)"]}]}]
- }
- }, {
- css: 'foo { bar: rgb(255, 0, 127); }',
- expected: {"type": "stylesheet", "value": [
- {
- "type": "selector",
- "selector": ["IDENT(foo)", "WS"],
- "value": [
- {
- "type": "decl",
- "name": "bar",
- "value": ["WS", {"type": "func", "name": "rgb", "value": [
- ["INT(255)"], ["WS", "INT(0)"], ["WS", "INT(127)"]]}]}]}]
- }
- }, {
- css: '#foo {}',
- expected: {"type": "stylesheet", "value": [
- {
- "type": "selector",
- "selector": ["HASH(foo)", "WS"],
- "value": []}]
- }
- }, {
- css: '@media{ }',
- expected: {"type": "stylesheet", "value": [
- {
- "type": "at", "name": "media",
- "prelude": [],
- "value": []}]}
- }
-];
-
-
-var ansidiff = require('ansidiff'),
- tokenize = require('./tokenizer').tokenize,
- parse = require('./parser').parse;
-
-var total = TESTS.length, failures = 0,
- i, test, tokens, sheet, dump, expected_dump;
-
-for (i = 0; i < total; i++) {
- test = TESTS[i];
- tokens = tokenize(test.css);
- sheet = parse(tokens);
- dump = sheet.toString(' ');
- expected_dump = JSON.stringify(test.expected, null, ' ');
- if (dump == expected_dump) {
- console.log('Test %d of %d: PASS', i, total);
- } else {
- console.log('Test %d of %d: FAIL\nCSS: %s\nTokens: %s',
- i, total, test.css, tokens.join(' '));
- console.log(ansidiff.lines(expected_dump, dump));
- failures++;
- }
-}
-
-// Abuse the differ to get colored output
-if (failures == 0) {
- console.log(ansidiff.words('%d tests, ', '%d tests, all passed :)'),
- total);
-} else {
- console.log(ansidiff.words('%d tests, %d failures :(', '%d tests, '),
- total, failures);
-}
+// This test suite runs on NodeJS and uses the 'ansidiff' package.
+// Once you have NodeJS, install ansidiff with:
+//
+// npm install ansidiff
+//
+// Then run the test suite with:
+//
+// node tests.js
+
+var TESTS = [
+ {
+ css: 'foo { bar: baz; }',
+ expected: {"type": "stylesheet", "value": [
+ {
+ "type": "selector",
+ "selector": ["IDENT(foo)", "WS"],
+ "value": [
+ {
+ "type": "declaration",
+ "name": "bar",
+ "value": ["WS", "IDENT(baz)"]}]}]
+ }
+ }, {
+ css: 'foo { bar: rgb(255, 0, 127); }',
+ expected: {"type": "stylesheet", "value": [
+ {
+ "type": "selector",
+ "selector": ["IDENT(foo)", "WS"],
+ "value": [
+ {
+ "type": "declaration",
+ "name": "bar",
+ "value": ["WS", {"type": "func", "name": "rgb", "value": [
+ ["INT(255)"], ["WS", "INT(0)"], ["WS", "INT(127)"]]}]}]}]
+ }
+ }, {
+ css: '#foo {}',
+ expected: {"type": "stylesheet", "value": [
+ {
+ "type": "selector",
+ "selector": ["HASH(foo)", "WS"],
+ "value": []}]
+ }
+ }, {
+ css: '@media{ }',
+ expected: {"type": "stylesheet", "value": [
+ {
+ "type": "at", "name": "media",
+ "prelude": [],
+ "value": []}]}
+ }
+];
+
+
+var ansidiff = require('ansidiff'),
+ tokenize = require('./tokenizer').tokenize,
+ parse = require('./parser').parse;
+
+var total = TESTS.length, failures = 0,
+ i, test, tokens, sheet, dump, expected_dump;
+
+for (i = 0; i < total; i++) {
+ test = TESTS[i];
+ tokens = tokenize(test.css);
+ sheet = parse(tokens);
+ dump = sheet.toString(' ');
+ expected_dump = JSON.stringify(test.expected, null, ' ');
+ if (dump == expected_dump) {
+ console.log('Test %d of %d: PASS', i, total);
+ } else {
+ console.log('Test %d of %d: FAIL\nCSS: %s\nTokens: %s',
+ i, total, test.css, tokens.join(' '));
+ console.log(ansidiff.lines(expected_dump, dump));
+ failures++;
+ }
+}
+
+// Abuse the differ to get colored output
+if (failures == 0) {
+ console.log(ansidiff.words('%d tests, ', '%d tests, all passed :)'),
+ total);
+} else {
+ console.log(ansidiff.words('%d tests, %d failures :(', '%d tests, '),
+ total, failures);
+}

0 comments on commit 9c00270

Please sign in to comment.