From 1041c1d533dcf551cc834076cea128d767e0f2ae Mon Sep 17 00:00:00 2001 From: kpdecker Date: Sun, 22 Dec 2013 18:46:13 -0600 Subject: [PATCH] Add tests for object @index and @first handling --- spec/builtins.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/spec/builtins.js b/spec/builtins.js index 401e789a..ef2d8297 100644 --- a/spec/builtins.js +++ b/spec/builtins.js @@ -98,6 +98,17 @@ describe('builtin helpers', function() { equal(result, "0. goodbye! 0 1 2 After 0 1. Goodbye! 0 1 2 After 1 2. GOODBYE! 0 1 2 After 2 cruel world!", "The @index variable is used"); }); + it("each object with @index", function() { + var string = "{{#each goodbyes}}{{@index}}. {{text}}! {{/each}}cruel {{world}}!"; + var hash = {goodbyes: {'a': {text: "goodbye"}, b: {text: "Goodbye"}, c: {text: "GOODBYE"}}, world: "world"}; + + var template = CompilerContext.compile(string); + var result = template(hash); + + equal(result, "0. goodbye! 1. Goodbye! 2. GOODBYE! cruel world!", "The @index variable is used"); + }); + + it("each with @first", function() { var string = "{{#each goodbyes}}{{#if @first}}{{text}}! {{/if}}{{/each}}cruel {{world}}!"; var hash = {goodbyes: [{text: "goodbye"}, {text: "Goodbye"}, {text: "GOODBYE"}], world: "world"}; @@ -118,6 +129,16 @@ describe('builtin helpers', function() { equal(result, "(goodbye! goodbye! goodbye!) (goodbye!) (goodbye!) cruel world!", "The @first variable is used"); }); + it("each object with @first", function() { + var string = "{{#each goodbyes}}{{#if @first}}{{text}}! {{/if}}{{/each}}cruel {{world}}!"; + var hash = {goodbyes: {'foo': {text: "goodbye"}, bar: {text: "Goodbye"}}, world: "world"}; + + var template = CompilerContext.compile(string); + var result = template(hash); + + equal(result, "goodbye! cruel world!", "The @first variable is used"); + }); + it("each with @last", function() { var string = "{{#each goodbyes}}{{#if @last}}{{text}}! {{/if}}{{/each}}cruel {{world}}!"; var hash = {goodbyes: [{text: "goodbye"}, {text: "Goodbye"}, {text: "GOODBYE"}], world: "world"};