From 9fd287ef77462cc59a74d85f501d8455dffe4079 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Mon, 24 Jan 2011 09:59:27 -0500 Subject: [PATCH] cleanup test a bit --- test/specificity.js | 30 +++++++++++-------------- test/specificity/classes.result | 14 ++++++------ test/specificity/demo.result | 16 ++++++------- test/specificity/filters_and_ids.result | 12 +++++----- test/support/helper.js | 4 ++-- 5 files changed, 36 insertions(+), 40 deletions(-) diff --git a/test/specificity.js b/test/specificity.js index 47f25df..c1be265 100644 --- a/test/specificity.js +++ b/test/specificity.js @@ -7,18 +7,16 @@ var mess = require('mess'); var tree = require('mess/tree'); var helper = require('./support/helper'); -function cleanupItem(item) { - // Remove indexes; we don't care about the exact byte number. - delete item.selector.index; - for (var i = 0; i < item.selector.filters.length; i++) { - delete item.selector.filters[i].index; - } - // Also flatten the elements array a bit, we only care about - // the actual selector. - item.selector.elements = item.selector.elements.map(function(el) { - return el.value; - }); - return item.selector.filters.length ? item.selector : item.selector.elements; +function cleanupItem(key, value) { + if (!key) return value.map(function(item) { return item.selector }); + else if (key === 'elements') return value.map(function(item) { return item.value; }); + else if (key === 'filters' && !value.length) return undefined; + else if (key === 'attachment' && value === '__default__') return undefined; + else if (key === 'index') return undefined; + else if (key === 'range') return value.map(function(v) { return 0 + v; }).join(''); + else if (key === 'op') return value.value; + else if (key === 'val') return value.value; + else return value; } helper.files('specificity', 'mss', function(file) { @@ -29,11 +27,9 @@ helper.files('specificity', 'mss', function(file) { filename: file }).parse(content, function (err, tree) { if (err) throw err; - - var mss = tree.toMSS(); - mss = mss.map(cleanupItem); - mss = helper.makePlain(mss); - + + var mss = tree.toList(); + mss = helper.makePlain(mss, cleanupItem); helper.compareToFile(mss, file, helper.resultFile(file)); }); }); diff --git a/test/specificity/classes.result b/test/specificity/classes.result index 65f690c..82a3a1d 100644 --- a/test/specificity/classes.result +++ b/test/specificity/classes.result @@ -1,9 +1,9 @@ [ - [".foo",".bar",".baz"], - [".foo",".baz"], - [".baz",".foo"], - [".baz",".bar"], - [".baz"], - [".bar"], - [".foo"] + {"elements":[".foo",".bar",".baz"]}, + {"elements":[".foo",".baz"]}, + {"elements":[".baz",".foo"]}, + {"elements":[".baz",".bar"]}, + {"elements":[".baz"]}, + {"elements":[".bar"]}, + {"elements":[".foo"]} ] diff --git a/test/specificity/demo.result b/test/specificity/demo.result index a5b9e81..b62ff6a 100644 --- a/test/specificity/demo.result +++ b/test/specificity/demo.result @@ -1,10 +1,10 @@ [ - ["#countries",".foo",".bar",".baz"], - ["#countries",".countries",".two"], - {"elements":["#world"],"filters":[{"key":"NAME","op":{"value":"="},"val":{"value":"United States","quote":"'","is":"string"}},{"key":"BLUE","op":{"value":"="},"val":{"value":"red","quote":"'","is":"string"}}]}, - {"elements":["#world"],"filters":[{"key":"NAME","op":{"value":"="},"val":{"value":"United States","quote":"'","is":"string"}}]}, - ["#countries"], - ["#world"], - ["#countries"], - ["#world"] + {"elements":["#countries",".foo",".bar",".baz"]}, + {"elements":["#countries",".countries",".two"]}, + {"elements":["#world"],"filters":[{"key":"NAME","op":"=","val":"United States"},{"key":"BLUE","op":"=","val":"red"}]}, + {"elements":["#world"],"filters":[{"key":"NAME","op":"=","val":"United States"}]}, + {"elements":["#countries"]}, + {"elements":["#countries"]}, + {"elements":["#world"]}, + {"elements":["#world"]} ] \ No newline at end of file diff --git a/test/specificity/filters_and_ids.result b/test/specificity/filters_and_ids.result index 8974579..9454b69 100644 --- a/test/specificity/filters_and_ids.result +++ b/test/specificity/filters_and_ids.result @@ -1,8 +1,8 @@ [ - {"elements":["#world","#countries"],"filters":[{"key":"NAME","op":{"value":"="},"val":{"value":"United States","quote":"'","is":"string"}}]}, - {"elements":["#world"],"filters":[{"key":"NAME","op":{"value":"="},"val":{"value":"United States","quote":"'","is":"string"}},{"range":[false,false,false,false,false,false,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true]}]}, - {"elements":["#world"],"filters":[{"key":"NAME","op":{"value":"="},"val":{"value":"United States","quote":"'","is":"string"}}]}, - {"elements":["#world"],"filters":[{"key":"NAME","op":{"value":"="},"val":{"value":"Canada","quote":"'","is":"string"}}]}, - {"elements":[],"filters":[{"range":[false,false,false,false,false,false,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true,true]}]}, - {"elements":[],"filters":[{"key":"NAME","op":{"value":"="},"val":{"value":"United States","quote":"'","is":"string"}}]} + {"elements":["#world","#countries"],"filters":[{"key":"NAME","op":"=","val":"United States"}]}, + {"elements":["#world"],"filters":[{"key":"NAME","op":"=","val":"United States"},{"range":"0000001111111111111111"}]}, + {"elements":["#world"],"filters":[{"key":"NAME","op":"=","val":"United States"}]}, + {"elements":["#world"],"filters":[{"key":"NAME","op":"=","val":"Canada"}]}, + {"elements":[],"filters":[{"range":"0000001111111111111111"}]}, + {"elements":[],"filters":[{"key":"NAME","op":"=","val":"United States"}]} ] \ No newline at end of file diff --git a/test/support/helper.js b/test/support/helper.js index 70e8d0a..2ac1c65 100644 --- a/test/support/helper.js +++ b/test/support/helper.js @@ -46,8 +46,8 @@ exports.formatJSON = function(arr) { }).join(',\n ') + '\n]'; }; -exports.makePlain = function(obj) { - return JSON.parse(JSON.stringify(obj)); +exports.makePlain = function(obj, fn) { + return JSON.parse(JSON.stringify(obj, fn)); }; exports.compareToFile = function(value, originalFile, resultFile) {