-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
mustache-spec-test.js
88 lines (79 loc) · 2.41 KB
/
mustache-spec-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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
require('./helper');
var fs = require('fs');
var path = require('path');
var specsDir = path.join(__dirname, 'spec/specs');
var skipTests = {
comments: [
'Standalone Without Newline'
],
delimiters: [
'Standalone Without Newline'
],
inverted: [
'Standalone Without Newline'
],
partials: [
'Standalone Without Previous Line',
'Standalone Without Newline'
],
sections: [
'Standalone Without Newline'
],
'~lambdas': [
'Interpolation',
'Interpolation - Expansion',
'Interpolation - Alternate Delimiters',
'Interpolation - Multiple Calls',
'Escaping',
'Section - Expansion',
'Section - Alternate Delimiters'
]
};
// You can run the skipped tests by setting the NOSKIP environment variable to
// true (e.g. NOSKIP=true mocha test/mustache-spec-test.js)
var noSkip = process.env.NOSKIP;
// You can put the name of a specific test file to run in the TEST environment
// variable (e.g. TEST=interpolation mocha test/mustache-spec-test.js)
var fileToRun = process.env.TEST;
// Mustache should work on node 0.6 that doesn't have fs.existsSync
function existsDir (path) {
try {
return fs.statSync(path).isDirectory();
} catch (x) {
return false;
}
}
var specFiles;
if (fileToRun) {
specFiles = [fileToRun];
} else if (existsDir(specsDir)) {
specFiles = fs.readdirSync(specsDir).filter(function (file) {
return (/\.json$/).test(file);
}).map(function (file) {
return path.basename(file).replace(/\.json$/, '');
}).sort();
} else {
specFiles = [];
}
function getSpecs (specArea) {
return JSON.parse(fs.readFileSync(path.join(specsDir, specArea + '.' + 'json'), 'utf8'));
}
describe('Mustache spec compliance', function () {
beforeEach(function () {
Mustache.clearCache();
});
specFiles.forEach(function (specArea) {
describe('- ' + specArea + ':', function () {
var specs = getSpecs(specArea);
specs.tests.forEach(function (test) {
var it_ = (!noSkip && skipTests[specArea] && skipTests[specArea].indexOf(test.name) >= 0) ? it.skip : it;
it_(test.name + ' - ' + test.desc, function () {
if (test.data.lambda && test.data.lambda.__tag__ === 'code')
test.data.lambda = eval('(function() { return ' + test.data.lambda.js + '; })');
var output = Mustache.render(test.template, test.data, test.partials);
assert.equal(output, test.expected);
});
});
});
});
});