-
Notifications
You must be signed in to change notification settings - Fork 479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed :else in section when iterating over empty array. #127
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,6 +127,13 @@ var grammarTests = [ | |
expected: "foo, not bar!", | ||
message:"should test the else block" | ||
}, | ||
{ | ||
name: "empty_else_block", | ||
source: "{#foo}full foo{:else}empty foo{/foo}", | ||
context: { foo: []}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we add a few more tests for completeness to make sure both ? and # behave the same way
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should fix the problem more upstream where dust seems to be treating numbers as string literals...i.e. 0 doesn't evaluate to false, which leads me to believe its treating it as "0". {} should evaluate to true in keeping with standard javascript. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for completeness then we should also check |
||
expected: "empty foo", | ||
message: "should test else block when array empty" | ||
}, | ||
{ | ||
name: "conditional", | ||
source: "{?tags}\n" + | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not do it by using the dust.isEmpty instead of len>0 that the exists section uses
dust.isEmpty = function(value) {
if (dust.isArray(value) && !value.length) return true;
if (value === 0) return false;
return (!value);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--len is needed in the loop anyway. no need to call another function.--
nevermind. totally agree let's keep consistent and use isEmpty.. let's put it before the isArray check so that is checked first and for everything type.