選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

80 行
2.2KB

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