-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.js
44 lines (33 loc) · 1.17 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
var NID = require('./');
var fs = require('fs');
var path = require('path');
var assert = require('chai').assert;
var jsYaml = require('js-yaml');
assert.deepEqualIgnoreOrder = function(actual, expected, message) {
var sortObjectKeys = function(unsortedObject) {
if (typeof unsortedObject !== 'object') {
return unsortedObject;
}
var sortedObject = {};
Object.keys(unsortedObject).sort().forEach(function(k) {
sortedObject[k] = sortObjectKeys(unsortedObject[k]);
});
return sortedObject;
};
assert.deepEqual(sortObjectKeys(actual), sortObjectKeys(expected), message);
};
describe('parser', function() {
var files = fs.readdirSync('tests');
files.forEach(function(file) {
if(!file.match(/\.nid$/))
return;
var inFile = path.join('tests', file);
var template = fs.readFileSync(inFile).toString('utf8');
var shouldEqual = fs.readFileSync(inFile+'.out').toString('utf8');
it('should parse: ' + file.replace(/_/g/ ' '), function() {
var parseObject = NID.parse(template);
var shouldEqualObject = jsYaml.safeLoad(shouldEqual);
assert.deepEqualIgnoreOrder(parseObject, shouldEqualObject);
});
});
});