Skip to content

Commit ecc2e2a

Browse files
committed
Merge pull request janl#301 from danielfagerstrom/topic/spec
Mustache specs
2 parents c2ee9c2 + 3ee2574 commit ecc2e2a

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-0
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "test/spec"]
2+
path = test/spec
3+
url = https://github.com/mustache/spec

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,11 @@ The mustache.js test suite uses the [mocha](http://visionmedia.github.com/mocha/
357357

358358
$ npm install -g mocha
359359

360+
You also need to install the sub module containing [Mustache specifications](http://github.com/mustache/spec) in the project root.
361+
362+
$ git submodule init
363+
$ git submodule update
364+
360365
Then run the tests.
361366

362367
$ mocha test

test/mustache-spec-test.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
require('./helper');
2+
3+
var fs = require('fs');
4+
var path = require('path');
5+
var specsDir = path.join(__dirname, 'spec/specs');
6+
7+
var skipTests = {
8+
comments: [
9+
'Standalone Without Newline'
10+
],
11+
delimiters: [
12+
'Standalone Without Newline'
13+
],
14+
inverted: [
15+
'Standalone Without Newline'
16+
],
17+
partials: [
18+
'Standalone Without Previous Line',
19+
'Standalone Without Newline',
20+
'Standalone Indentation'
21+
],
22+
sections: [
23+
'Standalone Without Newline'
24+
],
25+
'~lambdas': [
26+
'Interpolation',
27+
'Interpolation - Expansion',
28+
'Interpolation - Alternate Delimiters',
29+
'Interpolation - Multiple Calls',
30+
'Escaping',
31+
'Section - Expansion',
32+
'Section - Alternate Delimiters'
33+
]
34+
};
35+
36+
// You can run the skiped tests by setting the NOSKIP environment variable to
37+
// true (e.g. NOSKIP=true mocha test/mustache-spec-test.js)
38+
var noSkip = process.env.NOSKIP;
39+
40+
// You can put the name of a specific test file to run in the TEST environment
41+
// variable (e.g. TEST=interpolation mocha test/mustache-spec-test.js)
42+
var fileToRun = process.env.TEST;
43+
44+
// Mustache should work on node 0.6 that doesn't have fs.exisisSync
45+
function existsDir(path) {
46+
try {
47+
return fs.statSync(path).isDirectory();
48+
} catch (x) {
49+
return false;
50+
}
51+
}
52+
53+
var specFiles;
54+
if (fileToRun) {
55+
specFiles = [fileToRun];
56+
} else if (existsDir(specsDir)) {
57+
specFiles = fs.readdirSync(specsDir).filter(function (file) {
58+
return (/\.json$/).test(file);
59+
}).map(function (file) {
60+
return path.basename(file).replace(/\.json$/, '');
61+
}).sort();
62+
} else {
63+
specFiles = [];
64+
}
65+
66+
function getSpecs(specArea) {
67+
return JSON.parse(fs.readFileSync(path.join(specsDir, specArea + '.' + 'json'), 'utf8'));
68+
}
69+
70+
describe('Mustache spec compliance', function() {
71+
beforeEach(function () {
72+
Mustache.clearCache();
73+
});
74+
75+
specFiles.forEach(function(specArea) {
76+
describe('- ' + specArea + ':', function() {
77+
var specs = getSpecs(specArea);
78+
specs.tests.forEach(function(test) {
79+
var it_ = (!noSkip && skipTests[specArea] && skipTests[specArea].indexOf(test.name) >= 0) ? it.skip : it;
80+
it_(test.name + ' - ' + test.desc, function() {
81+
if (test.data.lambda && test.data.lambda.__tag__ === 'code')
82+
test.data.lambda = eval('(function() { return ' + test.data.lambda.js + '; })');
83+
var output = Mustache.render(test.template, test.data, test.partials);
84+
assert.equal(output, test.expected);
85+
});
86+
});
87+
});
88+
});
89+
});

test/spec

Submodule spec added at 72233f3

0 commit comments

Comments
 (0)