From 574931193c64e72bb7eae9b013a5aa0981ab2952 Mon Sep 17 00:00:00 2001 From: Seth Kinast Date: Tue, 4 Nov 2014 13:56:39 -0800 Subject: [PATCH] Get coverage back above 0.9 --- .travis.yml | 7 +-- lib/dust-helpers.js | 42 +++++++++-------- test/jasmine-test/spec/helpersTests.js | 63 ++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 23 deletions(-) diff --git a/.travis.yml b/.travis.yml index e9eb249..901ac78 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,11 +13,12 @@ matrix: env: TEST="all" notifications: email: - - jdemorais@linkedin.com - - vbasavaraj@linkedin.com - jleppert@linkedin.com + - jchan@linkedin.com + - skinast@linkedin.com before_install: + - npm install -g npm@1.4 + - npm --version - npm install -g grunt-cli - - npm install -g npm script: - "[ $TEST = 'all' ] && grunt test || grunt testNode" \ No newline at end of file diff --git a/lib/dust-helpers.js b/lib/dust-helpers.js index a4387b3..6f99aad 100644 --- a/lib/dust-helpers.js +++ b/lib/dust-helpers.js @@ -94,16 +94,16 @@ var helpers = { Reference resolution rules: if value exists in JSON: "" or '' will evaluate to false, boolean false, null, or undefined will evaluate to false, - numeric 0 evaluates to true, so does, string "0", string "null", string "undefined" and string "false". + numeric 0 evaluates to true, so does, string "0", string "null", string "undefined" and string "false". Also note that empty array -> [] is evaluated to false and empty object -> {} and non-empty object are evaluated to true - The type of the return value is string ( since we concatenate to support interpolated references + The type of the return value is string ( since we concatenate to support interpolated references if value does not exist in JSON and the input is a single reference: {x} - dust render emits empty string, and we then return false - + dust render emits empty string, and we then return false + if values does not exist in JSON and the input is interpolated references : {x} < {y} - dust render emits < and we return the partial output - + dust render emits < and we return the partial output + */ "tap": function(input, chunk, context) { // return given input if there is no dust reference to resolve @@ -359,8 +359,9 @@ var helpers = { "eq": function(chunk, context, bodies, params) { if(params) { params.filterOpType = "eq"; + return filter(chunk, context, bodies, params, function(expected, actual) { return actual === expected; }); } - return filter(chunk, context, bodies, params, function(expected, actual) { return actual === expected; }); + return chunk; }, /** @@ -379,7 +380,7 @@ var helpers = { params.filterOpType = "ne"; return filter(chunk, context, bodies, params, function(expected, actual) { return actual !== expected; }); } - return chunk; + return chunk; }, /** @@ -394,10 +395,11 @@ var helpers = { Note : use type="number" when comparing numeric **/ "lt": function(chunk, context, bodies, params) { - if(params) { - params.filterOpType = "lt"; - return filter(chunk, context, bodies, params, function(expected, actual) { return actual < expected; }); - } + if(params) { + params.filterOpType = "lt"; + return filter(chunk, context, bodies, params, function(expected, actual) { return actual < expected; }); + } + return chunk; }, /** @@ -412,10 +414,10 @@ var helpers = { Note : use type="number" when comparing numeric **/ "lte": function(chunk, context, bodies, params) { - if(params) { - params.filterOpType = "lte"; - return filter(chunk, context, bodies, params, function(expected, actual) { return actual <= expected; }); - } + if(params) { + params.filterOpType = "lte"; + return filter(chunk, context, bodies, params, function(expected, actual) { return actual <= expected; }); + } return chunk; }, @@ -456,7 +458,7 @@ var helpers = { params.filterOpType = "gte"; return filter(chunk, context, bodies, params, function(expected, actual) { return actual >= expected; }); } - return chunk; + return chunk; }, // to be used in conjunction with the select helper @@ -502,8 +504,8 @@ var helpers = { } return chunk.write(value); } - - + + }; for (var key in helpers) { @@ -514,4 +516,4 @@ var helpers = { module.exports = dust; } -})(typeof exports !== 'undefined' ? require('dustjs-linkedin') : dust); \ No newline at end of file +})(typeof exports !== 'undefined' ? require('dustjs-linkedin') : dust); diff --git a/test/jasmine-test/spec/helpersTests.js b/test/jasmine-test/spec/helpersTests.js index 3cd3340..8b0531b 100644 --- a/test/jasmine-test/spec/helpersTests.js +++ b/test/jasmine-test/spec/helpersTests.js @@ -23,6 +23,13 @@ expected: "", message: "should test if helper with no body and fail gracefully" }, + { + name: "if helper with no condition", + source: '{@if}Hello{/if}', + context: { x: 2, y: 3 }, + expected: "", + message: "should test if helper with no condition fails gracefully" + }, { name: "if helper without else", source: '{@if cond="{x}<{y}"}
X < Y
{/if}', @@ -488,6 +495,13 @@ expected: "", message: "eq helper with no body silently fails with console log" }, + { + name: "eq helper with no params", + source: "{@eq}Hello{/eq}", + context: {}, + expected: "", + message: "eq helper with no params does not execute" + }, { name: "eq helper matching string case", source: "{@eq key=\"foo\" value=\"foo\"}equal{/eq}", @@ -561,6 +575,13 @@ expected: "", message: "ne helper with no body silently fails with console log" }, + { + name: "ne helper with no params", + source: "{@ne}Hello{/ne}", + context: {}, + expected: "", + message: "ne helper with no params does not execute" + }, { name: "ne helper matching string case", source: "{@ne key=\"foo\" value=\"foo\"}not equal{/ne}", @@ -622,6 +643,13 @@ expected: "", message: "lt helper with no body silently fails with console log" }, + { + name: "lt helper with no params", + source: "{@lt}Hello{/lt}", + context: {}, + expected: "", + message: "lt helper with no params does not execute" + }, { name: "lt helper defaults to type number", source: "{@lt key=\"22\" value=\"33\"}22 less than 33{/lt}", @@ -690,6 +718,27 @@ expected: "22 not greater than 3 with type string", message: "gt helper with type string not valid case" }, + { + name: "gt helper with no params", + source: "{@gt}Hello{/gt}", + context: {}, + expected: "", + message: "gt helper with no params does not execute" + }, + { + name: "lte helper with no params", + source: "{@lte}Hello{/lte}", + context: {}, + expected: "", + message: "lte helper with no params does not execute" + }, + { + name: "gte helper with no params", + source: "{@gte}Hello{/gte}", + context: {}, + expected: "", + message: "gte helper with no params does not execute" + }, { name: "lte helper with no body", source: "{@lte key=\"2\" value=\"3\" type=\"number\"/}", @@ -1259,6 +1308,13 @@ { name: "idx", tests: [ + { + name: "idx helper with no body", + source: '{#n}{@idx/}{.} {/n}', + context: { n: ["Mick", "Tom", "Bob"] }, + expected: "Mick Tom Bob ", + message: "idx helper with no body should not render" + }, { name: "idx helper within partial included in a array", source: '{#n}{@idx}{.}>>{/idx}{>hello_there name=. count="30"/}{/n}', @@ -1271,6 +1327,13 @@ { name: "sep", tests: [ + { + name: "sep helper with no body", + source: '{#n}{.} {@sep/}{/n}', + context: { n: ["Mick", "Tom", "Bob"] }, + expected: "Mick Tom Bob ", + message: "sep helper with no body should not render" + }, { name: "sep helper within partial included in a array", source: '{#n}{>hello_there name=. count="30"/}{@sep} {/sep}{/n}',