~patrick-hetu/+junk/ptittrain_site

« back to all changes in this revision

Viewing changes to apps/ptittrain/static/bootstrap/docs/build/node_modules/hogan.js/test/spec.js

  • Committer: Patrick Hetu
  • Date: 2012-08-05 23:21:32 UTC
  • Revision ID: patrick.hetu@gmail.com-20120805232132-fryckvbj84wzg3tk
remove unnessesary files and fix static+version

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
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
6
 
 *
7
 
 *  http://www.apache.org/licenses/LICENSE-2.0
8
 
 *
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.
14
 
 */
15
 
 
16
 
var Hogan = Hogan || require('../lib/hogan');
17
 
var doc = this["document"];
18
 
var fs = require('fs');
19
 
 
20
 
var passed = 0;
21
 
var failed = 0;
22
 
 
23
 
if (!this["output"]) {
24
 
  var output = function (string) {
25
 
    return doc ? doc.write(string + '<br/>') : console.log(string);
26
 
  };
27
 
}
28
 
 
29
 
function runTest(tests) {
30
 
  tests.forEach(function(test) {
31
 
    var partials = {};
32
 
    for (var i in test.partials) {
33
 
      partials[i] = Hogan.compile(test.partials[i]);
34
 
    }
35
 
    var t = Hogan.compile(test.template);
36
 
 
37
 
    if (test.data.lambda) {
38
 
      var func = (new Function ('return ' + test.data.lambda.js)());
39
 
      test.data.lambda = function() { return func; };
40
 
    }
41
 
 
42
 
    var s = t.render(test.data, partials);
43
 
    is(s, test.expected, test.name + ': ' + test.desc);
44
 
  });
45
 
}
46
 
 
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});
51
 
 
52
 
for (var i = 0; i < files.length; i++) {
53
 
  var test = JSON.parse(fs.readFileSync(files[i]).toString());
54
 
  runTest(test.tests);
55
 
}
56
 
 
57
 
function is(got, expected, msg) {
58
 
  if (got === expected) {
59
 
    output("OK:   " + msg);
60
 
    ++passed;
61
 
  } else {
62
 
    output("FAIL: " + msg);
63
 
    output("Expected |" + expected + "|");
64
 
    output("     Got |" + got + "|");
65
 
    ++failed;
66
 
  }
67
 
}
68
 
 
69
 
function complete() {
70
 
  output("\nTests Complete");
71
 
  output("--------------");
72
 
  output("Passed: " + passed);
73
 
  output("Failed: " + failed);
74
 
  output("\n");
75
 
}
76
 
 
77
 
complete();