From 135147173bb2db003ff4d8c2583d717e316d8cf4 Mon Sep 17 00:00:00 2001 From: Alan Johnson Date: Sun, 15 Aug 2010 16:10:26 -0400 Subject: [PATCH] Write tests for inverted sections. --- test/handlebars.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/handlebars.js b/test/handlebars.js index a394f3b9..1b2d19df 100644 --- a/test/handlebars.js +++ b/test/handlebars.js @@ -86,6 +86,32 @@ test("this keyword in paths", function() { shouldCompileTo(string, hash, "helloHelloHELLO", "This keyword evaluates in more complex paths"); }); +module("inverted sections"); + +test("inverted sections with unset value", function() { + var string = "{{#goodbyes}}{{this}}{{/goodbyes}}{{^goodbyes}}Right On!{{/goodbyes}}"; + var hash = {}; + shouldCompileTo(string, hash, "Right On!", "Inverted section rendered when value isn't set."); +}); + +test("inverted section with false value", function() { + var string = "{{#goodbyes}}{{this}}{{/goodbyes}}{{^goodbyes}}Right On!{{/goodbyes}}"; + var hash = {goodbyes: false}; + shouldCompileTo(string, hash, "Right On!", "Inverted section rendered when value is false."); +}); + +test("inverted section with empty set", function() { + var string = "{{#goodbyes}}{{this}}{{/goodbyes}}{{^goodbyes}}Right On!{{/goodbyes}}"; + var hash = {goodbyes: []}; + shouldCompileTo(string, hash, "Right On!", "Inverted section rendered when value is empty set."); +}); + +test("inverted section using result of function call", function() { + var string = "{{#goodbyes}}{{this}}{{/goodbyes}}{{^goodbyes}}Right On!{{/goodbyes}}"; + var hash = {goodbyes: function() { return false; }} + shouldCompileTo(string, hash, "Right On!", "Inverted section rendered when result of function in expression is false."); +}); + module("blocks"); test("array", function() {