浏览代码

Merge pull request #301 from danielfagerstrom/topic/spec

Mustache specs
tags/0.7.3
Michael Jackson 13 年前
父节点
当前提交
ecc2e2a28f
共有 4 个文件被更改,包括 98 次插入0 次删除
  1. +3
    -0
      .gitmodules
  2. +5
    -0
      README.md
  3. +89
    -0
      test/mustache-spec-test.js
  4. +1
    -0
      test/spec

+ 3
- 0
.gitmodules 查看文件

@@ -0,0 +1,3 @@
[submodule "test/spec"]
path = test/spec
url = https://github.com/mustache/spec

+ 5
- 0
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


+ 89
- 0
test/mustache-spec-test.js 查看文件

@@ -0,0 +1,89 @@
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;

// 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 (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);
});
});
});
});
});

+ 1
- 0
test/spec

@@ -0,0 +1 @@
Subproject commit 72233f3ffda9e33915fd3022d0a9ebbcce265acd

正在加载...
取消
保存