|
|
|
@@ -1,72 +1,27 @@ |
|
|
|
require('./helper'); |
|
|
|
|
|
|
|
var fs = require('fs'); |
|
|
|
var path = require('path'); |
|
|
|
var _files = path.join(__dirname, '_files'); |
|
|
|
var renderHelper = require('./render-helper'); |
|
|
|
|
|
|
|
function getContents(testName, ext) { |
|
|
|
try { |
|
|
|
return fs.readFileSync(path.join(_files, testName + '.' + ext), 'utf8'); |
|
|
|
} catch (ex) { |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function getView(testName) { |
|
|
|
var view = getContents(testName, 'js'); |
|
|
|
if (!view) throw new Error('Cannot find view for test "' + testName + '"'); |
|
|
|
return eval(view); |
|
|
|
} |
|
|
|
|
|
|
|
function getPartial(testName) { |
|
|
|
try { |
|
|
|
return getContents(testName, 'partial'); |
|
|
|
} catch (error) { |
|
|
|
// No big deal. Not all tests need to test partial support. |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
function getTest(testName) { |
|
|
|
var test = {}; |
|
|
|
test.view = getView(testName); |
|
|
|
test.template = getContents(testName, 'mustache'); |
|
|
|
test.partial = getPartial(testName); |
|
|
|
test.expect = getContents(testName, 'txt'); |
|
|
|
return test; |
|
|
|
} |
|
|
|
|
|
|
|
// You can put the name of a specific test to run in the TEST environment |
|
|
|
// variable (e.g. TEST=backslashes vows test/render-test.js) |
|
|
|
var testToRun = process.env.TEST; |
|
|
|
|
|
|
|
var testNames; |
|
|
|
if (testToRun) { |
|
|
|
testNames = [testToRun]; |
|
|
|
} else { |
|
|
|
testNames = fs.readdirSync(_files).filter(function (file) { |
|
|
|
return (/\.js$/).test(file); |
|
|
|
}).map(function (file) { |
|
|
|
return path.basename(file).replace(/\.js$/, ''); |
|
|
|
}); |
|
|
|
} |
|
|
|
var tests = renderHelper.getTests(); |
|
|
|
|
|
|
|
describe('Mustache.render', function () { |
|
|
|
beforeEach(function () { |
|
|
|
Mustache.clearCache(); |
|
|
|
}); |
|
|
|
|
|
|
|
testNames.forEach(function (testName) { |
|
|
|
var test = getTest(testName); |
|
|
|
tests.forEach(function (test) { |
|
|
|
var view = eval(test.view); |
|
|
|
|
|
|
|
it('knows how to render ' + testName, function () { |
|
|
|
it('knows how to render ' + test.name, function () { |
|
|
|
var output; |
|
|
|
if (test.partial) { |
|
|
|
output = Mustache.render(test.template, test.view, { partial: test.partial }); |
|
|
|
output = Mustache.render(test.template, view, { partial: test.partial }); |
|
|
|
} else { |
|
|
|
output = Mustache.render(test.template, test.view); |
|
|
|
output = Mustache.render(test.template, view); |
|
|
|
} |
|
|
|
|
|
|
|
assert.equal(output, test.expect); |
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |