2011-01-21 06:54:51 +08:00
|
|
|
var path = require('path'),
|
2011-01-21 07:05:35 +08:00
|
|
|
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; });
|
2011-01-28 09:50:53 +08:00
|
|
|
else if (key === 'filters') {
|
2011-02-03 03:01:40 +08:00
|
|
|
var arr = [];
|
2014-06-11 23:52:06 +08:00
|
|
|
for (var id in value.filters) arr.push(id + value.filters[id].val);
|
2011-02-03 03:01:40 +08:00
|
|
|
if (arr.length) return arr;
|
2011-01-28 09:50:53 +08:00
|
|
|
}
|
2011-02-03 03:01:40 +08:00
|
|
|
else if (key === 'attachment' && value === '__default__') return;
|
2011-01-28 05:52:07 +08:00
|
|
|
else if (key === 'zoom') {
|
2014-06-11 23:52:06 +08:00
|
|
|
if (value != tree.Zoom.all) return (new tree.Zoom()).setZoom(value).toString();
|
2011-01-28 05:52:07 +08:00
|
|
|
}
|
2011-01-24 22:59:27 +08:00
|
|
|
else return value;
|
2011-01-22 02:20:57 +08:00
|
|
|
}
|
2011-01-21 06:54:51 +08:00
|
|
|
|
2012-05-03 00:56:38 +08:00
|
|
|
describe('Specificity', function() {
|
2011-01-22 02:20:57 +08:00
|
|
|
helper.files('specificity', 'mss', function(file) {
|
2012-05-03 00:56:38 +08:00
|
|
|
it('should handle spec correctly in ' + file, function(done) {
|
2011-01-22 02:20:57 +08:00
|
|
|
helper.file(file, function(content) {
|
2011-08-23 04:21:57 +08:00
|
|
|
var tree = (new carto.Parser({
|
2011-01-21 07:05:35 +08:00
|
|
|
paths: [ path.dirname(file) ],
|
|
|
|
filename: file
|
2011-08-23 04:21:57 +08:00
|
|
|
})).parse(content);
|
2011-01-24 22:59:27 +08:00
|
|
|
|
2011-08-23 04:21:57 +08:00
|
|
|
var mss = tree.toList({});
|
|
|
|
mss = helper.makePlain(mss, cleanupItem);
|
2014-06-11 23:52:06 +08:00
|
|
|
var json = JSON.parse(fs.readFileSync(helper.resultFile(file)));
|
|
|
|
var actual = file.replace(path.extname(file),'') + '-actual.json';
|
|
|
|
var expected = file.replace(path.extname(file),'') + '-expected.json';
|
|
|
|
try {
|
|
|
|
assert.deepEqual(mss, json);
|
|
|
|
// cleanup any actual renders that no longer fail
|
|
|
|
try {
|
|
|
|
fs.unlinkSync(actual);
|
|
|
|
fs.unlinkSync(expected);
|
|
|
|
} catch (err) {}
|
|
|
|
} catch (err) {
|
|
|
|
fs.writeFileSync(actual,JSON.stringify(mss,null,4));
|
|
|
|
fs.writeFileSync(expected,JSON.stringify(json,null,4));
|
|
|
|
throw new Error('failed: ' + actual + ' not equal to expected: ' + expected);
|
|
|
|
}
|
2012-05-03 00:56:38 +08:00
|
|
|
done();
|
2011-01-21 06:54:51 +08:00
|
|
|
});
|
2012-05-03 00:56:38 +08:00
|
|
|
});
|
|
|
|
});
|
2011-01-21 07:05:35 +08:00
|
|
|
});
|