diff options
author | kpdecker <kpdecker@gmail.com> | 2013-12-23 20:59:16 -0600 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2013-12-23 20:59:16 -0600 |
commit | 1a751b2f6ea71a0bf87f36e529a718474282bb7c (patch) | |
tree | 22ebb3cfa9d32e51773ea97d9c0ec11c1f53630b /spec/javascript-compiler.js | |
parent | abe9c82e753744edcac3c767ce5282a7c9ef7c41 (diff) | |
download | handlebars.js-1a751b2f6ea71a0bf87f36e529a718474282bb7c.zip handlebars.js-1a751b2f6ea71a0bf87f36e529a718474282bb7c.tar.gz handlebars.js-1a751b2f6ea71a0bf87f36e529a718474282bb7c.tar.bz2 |
Add JavascriptCompiler public API tests
Diffstat (limited to 'spec/javascript-compiler.js')
-rw-r--r-- | spec/javascript-compiler.js | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/spec/javascript-compiler.js b/spec/javascript-compiler.js new file mode 100644 index 0000000..ded4f3e --- /dev/null +++ b/spec/javascript-compiler.js @@ -0,0 +1,47 @@ +/*global Handlebars, beforeEach, handlebarsEnv, shouldCompileTo */ +describe('javascript-compiler api', function() { + if (!Handlebars.JavaScriptCompiler) { + return; + } + + describe('#nameLookup', function() { + var $superName; + beforeEach(function() { + $superName = handlebarsEnv.JavaScriptCompiler.prototype.nameLookup; + }); + afterEach(function() { + handlebarsEnv.JavaScriptCompiler.prototype.nameLookup = $superName; + }); + + it('should allow override', function() { + handlebarsEnv.JavaScriptCompiler.prototype.nameLookup = function(parent, name) { + return parent + '.bar_' + name; + }; + shouldCompileTo("{{foo}}", { bar_foo: "food" }, "food"); + }); + }); + describe('buffer', function() { + var $superAppend, $superCreate; + beforeEach(function() { + $superAppend = handlebarsEnv.JavaScriptCompiler.prototype.appendToBuffer; + $superCreate = handlebarsEnv.JavaScriptCompiler.prototype.initializeBuffer; + }); + afterEach(function() { + handlebarsEnv.JavaScriptCompiler.prototype.appendToBuffer = $superAppend; + handlebarsEnv.JavaScriptCompiler.prototype.initializeBuffer = $superCreate; + }); + + it('should allow init buffer override', function() { + handlebarsEnv.JavaScriptCompiler.prototype.initializeBuffer = function() { + return this.quotedString('foo_'); + }; + shouldCompileTo("{{foo}} ", { foo: "food" }, "foo_food "); + }); + it('should allow append buffer override', function() { + handlebarsEnv.JavaScriptCompiler.prototype.appendToBuffer = function(string) { + return $superAppend.call(this, string + ' + "_foo"'); + }; + shouldCompileTo("{{foo}}", { foo: "food" }, "food_foo"); + }); + }); +}); |