From 5e583585744be0601df701065500b7b40472d157 Mon Sep 17 00:00:00 2001 From: Daniel Fagerstrom Date: Sat, 16 Mar 2013 10:24:17 +0100 Subject: [PATCH 1/4] Include submodule for Mustache specifications. --- .gitmodules | 3 +++ test/spec | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 test/spec diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..9e2fdf8 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "test/spec"] + path = test/spec + url = https://github.com/mustache/spec diff --git a/test/spec b/test/spec new file mode 160000 index 0000000..72233f3 --- /dev/null +++ b/test/spec @@ -0,0 +1 @@ +Subproject commit 72233f3ffda9e33915fd3022d0a9ebbcce265acd From c8005af7c3c3644e387b8efb356286117ee433a8 Mon Sep 17 00:00:00 2001 From: Daniel Fagerstrom Date: Sat, 16 Mar 2013 10:27:31 +0100 Subject: [PATCH 2/4] Test that use all tests from Mustache specifications. The ones that fails in current mustache.js are skiped to not break the build. --- test/mustache-spec-test.js | 80 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 test/mustache-spec-test.js diff --git a/test/mustache-spec-test.js b/test/mustache-spec-test.js new file mode 100644 index 0000000..f659d20 --- /dev/null +++ b/test/mustache-spec-test.js @@ -0,0 +1,80 @@ +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', + 'Standalone Indentation' + ], + sections: [ + 'Standalone Without Newline' + ], + '~lambdas': [ + 'Interpolation', + 'Interpolation - Expansion', + 'Interpolation - Alternate Delimiters', + 'Interpolation - Multiple Calls', + 'Escaping', + 'Section - Expansion', + 'Section - Alternate Delimiters' + ] +}; + +// You can run the skiped 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; + +var specFiles; +if (fileToRun) { + specFiles = [fileToRun]; +} else if (fs.existsSync(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); + }); + }); + }); + }); +}); \ No newline at end of file From 8cd95a085ba9beb82141fc2762420680728297f5 Mon Sep 17 00:00:00 2001 From: Daniel Fagerstrom Date: Sat, 16 Mar 2013 10:36:20 +0100 Subject: [PATCH 3/4] Update README.md Instruction for including sub module with Mustache specs. --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 723e8af..a86c38a 100644 --- a/README.md +++ b/README.md @@ -357,6 +357,11 @@ The mustache.js test suite uses the [mocha](http://visionmedia.github.com/mocha/ $ npm install -g mocha +You also need to install the sub module containing [Mustache specifications](http://github.com/mustache/spec) in the project root. + + $ git submodule init + $ git submodule update + Then run the tests. $ mocha test From 3ee2574e219fc615e3aaca5b2f4204cfb2577a88 Mon Sep 17 00:00:00 2001 From: Daniel Fagerstrom Date: Sun, 17 Mar 2013 18:05:50 +0100 Subject: [PATCH 4/4] Used fs.existsSync that doesn't exists in nodejs 0.6 that is used by travis for testing. --- test/mustache-spec-test.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/mustache-spec-test.js b/test/mustache-spec-test.js index f659d20..1050ea4 100644 --- a/test/mustache-spec-test.js +++ b/test/mustache-spec-test.js @@ -41,10 +41,19 @@ var noSkip = process.env.NOSKIP; // 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.exisisSync +function existsDir(path) { + try { + return fs.statSync(path).isDirectory(); + } catch (x) { + return false; + } +} + var specFiles; if (fileToRun) { specFiles = [fileToRun]; -} else if (fs.existsSync(specsDir)) { +} else if (existsDir(specsDir)) { specFiles = fs.readdirSync(specsDir).filter(function (file) { return (/\.json$/).test(file); }).map(function (file) {