From c8005af7c3c3644e387b8efb356286117ee433a8 Mon Sep 17 00:00:00 2001 From: Daniel Fagerstrom Date: Sat, 16 Mar 2013 10:27:31 +0100 Subject: [PATCH] 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