diff options
author | kpdecker <kpdecker@gmail.com> | 2013-05-27 14:40:52 -0500 |
---|---|---|
committer | kpdecker <kpdecker@gmail.com> | 2013-05-27 14:40:52 -0500 |
commit | 822a8911ecd4ffe822fd82afbf7b24704e79f787 (patch) | |
tree | 4f72b0d6a06522f6b25c25e2f46da711d3daf10d /spec/qunit_spec.js | |
parent | 5f349913aa1e3efebcd0a6835d33161c7c81d7a9 (diff) | |
download | handlebars.js-822a8911ecd4ffe822fd82afbf7b24704e79f787.zip handlebars.js-822a8911ecd4ffe822fd82afbf7b24704e79f787.tar.gz handlebars.js-822a8911ecd4ffe822fd82afbf7b24704e79f787.tar.bz2 |
Add support for complex ids in @data references
Diffstat (limited to 'spec/qunit_spec.js')
-rw-r--r-- | spec/qunit_spec.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/spec/qunit_spec.js b/spec/qunit_spec.js index ad690c6..23dcdb9 100644 --- a/spec/qunit_spec.js +++ b/spec/qunit_spec.js @@ -940,6 +940,54 @@ test("hash values can be looked up via @foo", function() { equals("Hello world", result, "@foo as a parameter retrieves template data"); }); +test("nested parameter data can be looked up via @foo.bar", function() { + var template = CompilerContext.compile("{{hello @world.bar}}"); + var helpers = { + hello: function(noun) { + return "Hello " + noun; + } + }; + + var result = template({}, { helpers: helpers, data: { world: {bar: "world" } } }); + equals("Hello world", result, "@foo as a parameter retrieves template data"); +}); + +test("nested parameter data does not fail with @world.bar", function() { + var template = CompilerContext.compile("{{hello @world.bar}}"); + var helpers = { + hello: function(noun) { + return "Hello " + noun; + } + }; + + var result = template({}, { helpers: helpers, data: { foo: {bar: "world" } } }); + equals("Hello undefined", result, "@foo as a parameter retrieves template data"); +}); + +test("parameter data throws when using this scope references", function() { + var string = "{{#goodbyes}}{{text}} cruel {{@./name}}! {{/goodbyes}}"; + + shouldThrow(function() { + CompilerContext.compile(string); + }, Error, "Should throw exception"); +}); + +test("parameter data throws when using parent scope references", function() { + var string = "{{#goodbyes}}{{text}} cruel {{@../name}}! {{/goodbyes}}"; + + shouldThrow(function() { + CompilerContext.compile(string); + }, Error, "Should throw exception"); +}); + +test("parameter data throws when using complex scope references", function() { + var string = "{{#goodbyes}}{{text}} cruel {{@foo/../name}}! {{/goodbyes}}"; + + shouldThrow(function() { + CompilerContext.compile(string); + }, Error, "Should throw exception"); +}); + test("data is inherited downstream", function() { var template = CompilerContext.compile("{{#let foo=bar.baz}}{{@foo}}{{/let}}", { data: true }); var helpers = { |