2
* Copyright 2011 Twitter, Inc.
3
* Licensed under the Apache License, Version 2.0 (the "License");
4
* you may not use this file except in compliance with the License.
5
* You may obtain a copy of the License at
7
* http://www.apache.org/licenses/LICENSE-2.0
9
* Unless required by applicable law or agreed to in writing, software
10
* distributed under the License is distributed on an "AS IS" BASIS,
11
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
* See the License for the specific language governing permissions and
13
* limitations under the License.
16
var Hogan = Hogan || require('../lib/hogan');
17
var doc = this["document"];
18
var fs = require('fs');
23
if (!this["output"]) {
24
var output = function (string) {
25
return doc ? doc.write(string + '<br/>') : console.log(string);
29
function runTest(tests) {
30
tests.forEach(function(test) {
32
for (var i in test.partials) {
33
partials[i] = Hogan.compile(test.partials[i]);
35
var t = Hogan.compile(test.template);
37
if (test.data.lambda) {
38
var func = (new Function ('return ' + test.data.lambda.js)());
39
test.data.lambda = function() { return func; };
42
var s = t.render(test.data, partials);
43
is(s, test.expected, test.name + ': ' + test.desc);
47
var testDir = './test/spec/specs';
48
var files = fs.readdirSync(testDir)
49
.filter(function(f) { return f.indexOf('.json') > 0; })
50
.map(function(f) { return testDir + '/' + f});
52
for (var i = 0; i < files.length; i++) {
53
var test = JSON.parse(fs.readFileSync(files[i]).toString());
57
function is(got, expected, msg) {
58
if (got === expected) {
62
output("FAIL: " + msg);
63
output("Expected |" + expected + "|");
64
output(" Got |" + got + "|");
70
output("\nTests Complete");
71
output("--------------");
72
output("Passed: " + passed);
73
output("Failed: " + failed);