carto/test/specificity.test.js

43 lines
1.3 KiB
JavaScript
Raw Normal View History

2011-01-21 06:54:51 +08:00
var path = require('path'),
sys = require('sys'),
assert = require('assert'),
fs = require('fs');
2011-01-21 06:54:51 +08:00
2011-05-27 02:07:50 +08:00
var carto = require('../lib/carto');
var tree = require('../lib/carto').tree;
2011-01-21 06:54:51 +08:00
var helper = require('./support/helper');
2011-01-24 22:59:27 +08:00
function cleanupItem(key, value) {
2011-02-03 03:01:40 +08:00
if (key === 'rules') return;
else if (key === 'ruleIndex') return;
2011-01-24 22:59:27 +08:00
else if (key === 'elements') return value.map(function(item) { return item.value; });
else if (key === 'filters') {
2011-02-03 03:01:40 +08:00
var arr = [];
for (var id in value) arr.push(id + value[id].val);
if (arr.length) return arr;
}
2011-02-03 03:01:40 +08:00
else if (key === 'attachment' && value === '__default__') return;
else if (key === 'zoom') {
2011-02-03 03:01:40 +08:00
if (value != tree.Zoom.all) return tree.Zoom.toString(value);
}
2011-01-24 22:59:27 +08:00
else return value;
}
2011-01-21 06:54:51 +08:00
helper.files('specificity', 'mss', function(file) {
exports['test ' + file] = function(beforeExit) {
helper.file(file, function(content) {
2011-02-08 00:22:14 +08:00
new carto.Parser({
paths: [ path.dirname(file) ],
filename: file
}).parse(content, function (err, tree) {
if (err) throw err;
2011-01-24 22:59:27 +08:00
2011-01-25 08:06:01 +08:00
var mss = tree.toList({});
2011-01-24 22:59:27 +08:00
mss = helper.makePlain(mss, cleanupItem);
helper.compareToFile(mss, file, helper.resultFile(file));
});
2011-01-21 06:54:51 +08:00
});
}
});