Skip to content

Commit

Permalink
Get coverage back above 0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
Seth Kinast committed Nov 4, 2014
1 parent 7f1b442 commit 5749311
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 23 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ matrix:
env: TEST="all"
notifications:
email:
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
before_install:
- npm install -g [email protected]
- npm --version
- npm install -g grunt-cli
- npm install -g npm
script:
- "[ $TEST = 'all' ] && grunt test || grunt testNode"
42 changes: 22 additions & 20 deletions lib/dust-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
},

/**
Expand All @@ -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;
},

/**
Expand All @@ -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;
},

/**
Expand All @@ -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;
},

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -502,8 +504,8 @@ var helpers = {
}
return chunk.write(value);
}


};

for (var key in helpers) {
Expand All @@ -514,4 +516,4 @@ var helpers = {
module.exports = dust;
}

})(typeof exports !== 'undefined' ? require('dustjs-linkedin') : dust);
})(typeof exports !== 'undefined' ? require('dustjs-linkedin') : dust);
63 changes: 63 additions & 0 deletions test/jasmine-test/spec/helpersTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}"}<div> X < Y </div>{/if}',
Expand Down Expand Up @@ -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}",
Expand Down Expand Up @@ -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}",
Expand Down Expand Up @@ -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}",
Expand Down Expand Up @@ -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\"/}",
Expand Down Expand Up @@ -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}',
Expand All @@ -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}',
Expand Down

0 comments on commit 5749311

Please sign in to comment.