cleanup test a bit

This commit is contained in:
Konstantin Käfer 2011-01-24 09:59:27 -05:00
parent 82bbc0ac2f
commit 9fd287ef77
5 changed files with 36 additions and 40 deletions

View File

@ -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));
});
});

View File

@ -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"]}
]

View File

@ -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"]}
]

View File

@ -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"}]}
]

View File

@ -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) {