summaryrefslogtreecommitdiffstats
path: root/spec/env
diff options
context:
space:
mode:
Diffstat (limited to 'spec/env')
-rw-r--r--spec/env/browser.js13
-rw-r--r--spec/env/common.js28
-rw-r--r--spec/env/node.js13
-rw-r--r--spec/env/runner.js40
-rw-r--r--spec/env/runtime.js15
5 files changed, 109 insertions, 0 deletions
diff --git a/spec/env/browser.js b/spec/env/browser.js
new file mode 100644
index 0000000..a17aa66
--- /dev/null
+++ b/spec/env/browser.js
@@ -0,0 +1,13 @@
+require('./common');
+
+global.Handlebars = require('../../dist/handlebars');
+
+global.CompilerContext = {
+ compile: function(template, options) {
+ var templateSpec = Handlebars.precompile(template, options);
+ return Handlebars.template(eval('(' + templateSpec + ')'));
+ },
+ compileWithPartial: function(template, options) {
+ return Handlebars.compile(template, options);
+ }
+};
diff --git a/spec/env/common.js b/spec/env/common.js
new file mode 100644
index 0000000..53ddd61
--- /dev/null
+++ b/spec/env/common.js
@@ -0,0 +1,28 @@
+global.should = require('should');
+
+global.shouldCompileTo = function(string, hashOrArray, expected, message) {
+ shouldCompileToWithPartials(string, hashOrArray, false, expected, message);
+};
+
+global.shouldCompileToWithPartials = function(string, hashOrArray, partials, expected, message) {
+ var result = compileWithPartials(string, hashOrArray, partials);
+ result.should.equal(expected, "'" + expected + "' should === '" + result + "': " + message);
+};
+
+global.compileWithPartials = function(string, hashOrArray, partials) {
+ var template = CompilerContext[partials ? 'compileWithPartial' : 'compile'](string), ary;
+ if(Object.prototype.toString.call(hashOrArray) === "[object Array]") {
+ ary = [];
+ ary.push(hashOrArray[0]);
+ ary.push({ helpers: hashOrArray[1], partials: hashOrArray[2] });
+ } else {
+ ary = [hashOrArray];
+ }
+
+ return template.apply(this, ary);
+};
+
+
+global.equals = global.equal = function(a, b, msg) {
+ a.should.equal(b, msg || '');
+};
diff --git a/spec/env/node.js b/spec/env/node.js
new file mode 100644
index 0000000..fe34f94
--- /dev/null
+++ b/spec/env/node.js
@@ -0,0 +1,13 @@
+require('./common');
+
+global.Handlebars = require('../../lib/handlebars');
+
+global.CompilerContext = {
+ compile: function(template, options) {
+ var templateSpec = Handlebars.precompile(template, options);
+ return Handlebars.template(eval('(' + templateSpec + ')'));
+ },
+ compileWithPartial: function(template, options) {
+ return Handlebars.compile(template, options);
+ }
+};
diff --git a/spec/env/runner.js b/spec/env/runner.js
new file mode 100644
index 0000000..919f0ae
--- /dev/null
+++ b/spec/env/runner.js
@@ -0,0 +1,40 @@
+var fs = require('fs'),
+ Mocha = require('mocha'),
+ path = require('path');
+
+var errors = 0,
+ testDir = path.dirname(__dirname),
+ grep = process.argv[2];
+
+var files = fs.readdirSync(testDir)
+ .filter(function(name) { return (/.*\.js$/).test(name); })
+ .map(function(name) { return testDir + '/' + name; });
+
+run('./node', function() {
+ run('./browser', function() {
+ run('./runtime', function() {
+ process.exit(errors);
+ });
+ });
+});
+
+
+function run(env, callback) {
+ var mocha = new Mocha();
+ mocha.ui('bdd');
+ mocha.files = files.slice();
+ if (grep) {
+ mocha.grep(grep);
+ }
+
+ files.forEach(function(name) {
+ delete require.cache[name];
+ });
+
+ console.log('Running env: ' + env);
+ require(env);
+ mocha.run(function(errorCount) {
+ errors += errorCount;
+ callback();
+ });
+}
diff --git a/spec/env/runtime.js b/spec/env/runtime.js
new file mode 100644
index 0000000..fb4b342
--- /dev/null
+++ b/spec/env/runtime.js
@@ -0,0 +1,15 @@
+require('./common');
+
+global.Handlebars = require('../../dist/handlebars.runtime');
+
+var compiler = require('../../lib/handlebars');
+
+global.CompilerContext = {
+ compile: function(template, options) {
+ var templateSpec = compiler.precompile(template, options);
+ return Handlebars.template(eval('(' + templateSpec + ')'));
+ },
+ compileWithPartial: function(template, options) {
+ return compiler.compile(template, options);
+ }
+};