diff options
author | kpdecker <kpdecker@gmail.com> | 2012-07-23 13:45:53 -0500 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2012-07-23 13:45:53 -0500 |
commit | 09ac8ac24b18d7c407b49edd50d166c4d4fab2f0 (patch) | |
tree | 3a8651f0e9488071d6c84a40fef6dade46ad501b /spec/qunit_spec.js | |
parent | adb8486e5fd7a6ac1ba2b3e8dd324f149abddec7 (diff) | |
download | handlebars.js-09ac8ac24b18d7c407b49edd50d166c4d4fab2f0.zip handlebars.js-09ac8ac24b18d7c407b49edd50d166c4d4fab2f0.tar.gz handlebars.js-09ac8ac24b18d7c407b49edd50d166c4d4fab2f0.tar.bz2 |
Make jshint happy(er)
Diffstat (limited to 'spec/qunit_spec.js')
-rw-r--r-- | spec/qunit_spec.js | 73 |
1 files changed, 35 insertions, 38 deletions
diff --git a/spec/qunit_spec.js b/spec/qunit_spec.js index 3fa8e4b..a1df160 100644 --- a/spec/qunit_spec.js +++ b/spec/qunit_spec.js @@ -6,13 +6,13 @@ Handlebars.registerHelper('helperMissing', function(helper, context) { } }); -var shouldCompileTo = function(string, hashOrArray, expected, message) { +function shouldCompileTo(string, hashOrArray, expected, message) { shouldCompileToWithPartials(string, hashOrArray, false, expected, message); -}; -var shouldCompileToWithPartials = function(string, hashOrArray, partials, expected, message) { +} +function shouldCompileToWithPartials(string, hashOrArray, partials, expected, message) { var template = CompilerContext[partials ? 'compileWithPartial' : 'compile'](string), ary; if(Object.prototype.toString.call(hashOrArray) === "[object Array]") { - helpers = hashOrArray[1]; + var helpers = hashOrArray[1]; if(helpers) { for(var prop in Handlebars.helpers) { @@ -27,11 +27,11 @@ var shouldCompileToWithPartials = function(string, hashOrArray, partials, expect ary = [hashOrArray]; } - result = template.apply(this, ary); + var result = template.apply(this, ary); equal(result, expected, "'" + expected + "' should === '" + result + "': " + message); -}; +} -var shouldThrow = function(fn, exception, message) { +function shouldThrow(fn, exception, message) { var caught = false; try { fn(); @@ -158,7 +158,7 @@ test("this keyword in paths", function() { shouldCompileTo(string, hash, "goodbyeGoodbyeGOODBYE", "This keyword in paths evaluates to current context"); - string = "{{#hellos}}{{this/text}}{{/hellos}}" + string = "{{#hellos}}{{this/text}}{{/hellos}}"; hash = {hellos: [{text: "hello"}, {text: "Hello"}, {text: "HELLO"}]}; shouldCompileTo(string, hash, "helloHelloHELLO", "This keyword evaluates in more complex paths"); }); @@ -186,7 +186,7 @@ test("inverted section with empty set", function() { suite("blocks"); test("array", function() { - var string = "{{#goodbyes}}{{text}}! {{/goodbyes}}cruel {{world}}!" + var string = "{{#goodbyes}}{{text}}! {{/goodbyes}}cruel {{world}}!"; var hash = {goodbyes: [{text: "goodbye"}, {text: "Goodbye"}, {text: "GOODBYE"}], world: "world"}; shouldCompileTo(string, hash, "goodbye! Goodbye! GOODBYE! cruel world!", "Arrays iterate over the contents when not empty"); @@ -197,7 +197,7 @@ test("array", function() { }); test("empty block", function() { - var string = "{{#goodbyes}}{{/goodbyes}}cruel {{world}}!" + var string = "{{#goodbyes}}{{/goodbyes}}cruel {{world}}!"; var hash = {goodbyes: [{text: "goodbye"}, {text: "Goodbye"}, {text: "GOODBYE"}], world: "world"}; shouldCompileTo(string, hash, "cruel world!", "Arrays iterate over the contents when not empty"); @@ -270,7 +270,7 @@ test("block helper", function() { var string = "{{#goodbyes}}{{text}}! {{/goodbyes}}cruel {{world}}!"; var template = CompilerContext.compile(string); - result = template({world: "world"}, { helpers: {goodbyes: function(options) { return options.fn({text: "GOODBYE"}); }}}); + var result = template({world: "world"}, { helpers: {goodbyes: function(options) { return options.fn({text: "GOODBYE"}); }}}); equal(result, "GOODBYE! cruel world!", "Block helper executed"); }); @@ -278,7 +278,7 @@ test("block helper staying in the same context", function() { var string = "{{#form}}<p>{{name}}</p>{{/form}}"; var template = CompilerContext.compile(string); - result = template({name: "Yehuda"}, {helpers: {form: function(options) { return "<form>" + options.fn(this) + "</form>"; } }}); + var result = template({name: "Yehuda"}, {helpers: {form: function(options) { return "<form>" + options.fn(this) + "</form>"; } }}); equal(result, "<form><p>Yehuda</p></form>", "Block helper executed with current context"); }); @@ -303,7 +303,7 @@ test("block helper passing a new context", function() { var string = "{{#form yehuda}}<p>{{name}}</p>{{/form}}"; var template = CompilerContext.compile(string); - result = template({yehuda: {name: "Yehuda"}}, { helpers: {form: function(context, options) { return "<form>" + options.fn(context) + "</form>"; }}}); + var result = template({yehuda: {name: "Yehuda"}}, { helpers: {form: function(context, options) { return "<form>" + options.fn(context) + "</form>"; }}}); equal(result, "<form><p>Yehuda</p></form>", "Context variable resolved"); }); @@ -311,7 +311,7 @@ test("block helper passing a complex path context", function() { var string = "{{#form yehuda/cat}}<p>{{name}}</p>{{/form}}"; var template = CompilerContext.compile(string); - result = template({yehuda: {name: "Yehuda", cat: {name: "Harold"}}}, { helpers: {form: function(context, options) { return "<form>" + options.fn(context) + "</form>"; }}}); + var result = template({yehuda: {name: "Yehuda", cat: {name: "Harold"}}}, { helpers: {form: function(context, options) { return "<form>" + options.fn(context) + "</form>"; }}}); equal(result, "<form><p>Harold</p></form>", "Complex path variable resolved"); }); @@ -319,7 +319,7 @@ test("nested block helpers", function() { var string = "{{#form yehuda}}<p>{{name}}</p>{{#link}}Hello{{/link}}{{/form}}"; var template = CompilerContext.compile(string); - result = template({ + var result = template({ yehuda: {name: "Yehuda" } }, { helpers: { @@ -427,9 +427,6 @@ test("rendering undefined partial throws an exception", function() { test("rendering template partial in vm mode throws an exception", function() { shouldThrow(function() { var template = CompilerContext.compile("{{> whatever}}"); - var string = "Dudes: {{>dude}} {{another_dude}}"; - var dude = "{{name}}"; - var hash = {name:"Jeepers", another_dude:"Creepers"}; template(); }, Handlebars.Exception, "Should throw exception"); }); @@ -468,7 +465,7 @@ test("simple literals work", function() { if(typeof bool1 !== 'boolean') { bool1 = "NaB"; } if(typeof bool2 !== 'boolean') { bool2 = "NaB"; } return "Hello " + param + " " + times + " times: " + bool1 + " " + bool2; - }} + }}; shouldCompileTo(string, [hash, helpers], "Message: Hello world 12 times: true false", "template with a simple String literal"); }); @@ -481,8 +478,8 @@ test("using a quote in the middle of a parameter raises an error", function() { test("escaping a String is possible", function(){ var string = 'Message: {{{hello "\\"world\\""}}}'; - var hash = {} - var helpers = {hello: function(param) { return "Hello " + param; }} + var hash = {}; + var helpers = {hello: function(param) { return "Hello " + param; }}; shouldCompileTo(string, [hash, helpers], "Message: Hello \"world\"", "template with an escaped String literal"); }); @@ -531,38 +528,38 @@ test("if a context is not found, helperMissing is used", function() { suite("knownHelpers"); test("Known helper should render helper", function() { - var template = CompilerContext.compile("{{hello}}", {knownHelpers: {"hello" : true}}) + var template = CompilerContext.compile("{{hello}}", {knownHelpers: {"hello" : true}}); var result = template({}, {helpers: {hello: function() { return "foo"; }}}); equal(result, "foo", "'foo' should === '" + result); }); test("Unknown helper in knownHelpers only mode should be passed as undefined", function() { - var template = CompilerContext.compile("{{typeof hello}}", {knownHelpers: {'typeof': true}, knownHelpersOnly: true}) + var template = CompilerContext.compile("{{typeof hello}}", {knownHelpers: {'typeof': true}, knownHelpersOnly: true}); var result = template({}, {helpers: {'typeof': function(arg) { return typeof arg; }, hello: function() { return "foo"; }}}); equal(result, "undefined", "'undefined' should === '" + result); }); test("Builtin helpers available in knownHelpers only mode", function() { - var template = CompilerContext.compile("{{#unless foo}}bar{{/unless}}", {knownHelpersOnly: true}) + var template = CompilerContext.compile("{{#unless foo}}bar{{/unless}}", {knownHelpersOnly: true}); var result = template({}); equal(result, "bar", "'bar' should === '" + result); }); test("Field lookup works in knownHelpers only mode", function() { - var template = CompilerContext.compile("{{foo}}", {knownHelpersOnly: true}) + var template = CompilerContext.compile("{{foo}}", {knownHelpersOnly: true}); var result = template({foo: 'bar'}); equal(result, "bar", "'bar' should === '" + result); }); test("Conditional blocks work in knownHelpers only mode", function() { - var template = CompilerContext.compile("{{#foo}}bar{{/foo}}", {knownHelpersOnly: true}) + var template = CompilerContext.compile("{{#foo}}bar{{/foo}}", {knownHelpersOnly: true}); var result = template({foo: 'baz'}); equal(result, "bar", "'bar' should === '" + result); }); test("Invert blocks work in knownHelpers only mode", function() { - var template = CompilerContext.compile("{{^foo}}bar{{/foo}}", {knownHelpersOnly: true}) + var template = CompilerContext.compile("{{^foo}}bar{{/foo}}", {knownHelpersOnly: true}); var result = template({foo: false}); equal(result, "bar", "'bar' should === '" + result); @@ -605,13 +602,13 @@ test("if", function() { test("if with function argument", function() { var string = "{{#if goodbye}}GOODBYE {{/if}}cruel {{world}}!"; - shouldCompileTo(string, {goodbye: function() {return true}, world: "world"}, "GOODBYE cruel world!", + shouldCompileTo(string, {goodbye: function() {return true;}, world: "world"}, "GOODBYE cruel world!", "if with function shows the contents when function returns true"); - shouldCompileTo(string, {goodbye: function() {return this.world}, world: "world"}, "GOODBYE cruel world!", + shouldCompileTo(string, {goodbye: function() {return this.world;}, world: "world"}, "GOODBYE cruel world!", "if with function shows the contents when function returns string"); - shouldCompileTo(string, {goodbye: function() {return false}, world: "world"}, "cruel world!", + shouldCompileTo(string, {goodbye: function() {return false;}, world: "world"}, "cruel world!", "if with function does not show the contents when returns false"); - shouldCompileTo(string, {goodbye: function() {return this.foo}, world: "world"}, "cruel world!", + shouldCompileTo(string, {goodbye: function() {return this.foo;}, world: "world"}, "cruel world!", "if with function does not show the contents when returns undefined"); }); @@ -635,13 +632,13 @@ test("each with @index", function() { }); test("log", function() { - var string = "{{log blah}}" + var string = "{{log blah}}"; var hash = { blah: "whee" }; var logArg; var originalLog = Handlebars.log; - Handlebars.log = function(arg){ logArg = arg; } - teardown = function(){ Handlebars.log = originalLog; } + Handlebars.log = function(arg){ logArg = arg; }; + teardown = function(){ Handlebars.log = originalLog; }; shouldCompileTo(string, hash, "", "log should not display"); equals("whee", logArg, "should call log with 'whee'"); @@ -998,8 +995,8 @@ test("block helpers can take an optional hash with booleans", function() { var result = template({}, {helpers: helpers}); equals(result, "GOODBYE CRUEL world", "Boolean hash parameter honored"); - var template = CompilerContext.compile('{{#goodbye cruel="CRUEL" print=false}}world{{/goodbye}}'); - var result = template({}, {helpers: helpers}); + template = CompilerContext.compile('{{#goodbye cruel="CRUEL" print=false}}world{{/goodbye}}'); + result = template({}, {helpers: helpers}); equals(result, "NOT PRINTING", "Boolean hash parameter honored"); }); @@ -1099,13 +1096,13 @@ test("GH-150: Inverted sections print when they shouldn't", function() { }); test("Mustache man page", function() { - var string = "Hello {{name}}. You have just won ${{value}}!{{#in_ca}} Well, ${{taxed_value}}, after taxes.{{/in_ca}}" + var string = "Hello {{name}}. You have just won ${{value}}!{{#in_ca}} Well, ${{taxed_value}}, after taxes.{{/in_ca}}"; var data = { "name": "Chris", "value": 10000, "taxed_value": 10000 - (10000 * 0.4), "in_ca": true - } + }; shouldCompileTo(string, data, "Hello Chris. You have just won $10000! Well, $6000, after taxes.", "the hello world mustache example works"); }); |