Skip to content

Commit

Permalink
Tests for "unless…else..end" : {{#foo}}…{{^foo}}…{{/foo}}
Browse files Browse the repository at this point in the history
  • Loading branch information
groue committed Nov 2, 2012
1 parent 6c359ee commit 35125ca
Showing 1 changed file with 133 additions and 0 deletions.
133 changes: 133 additions & 0 deletions src/tests/Public/v6.0/GRMustacheSuites/inverted_sections.json
Expand Up @@ -82,6 +82,139 @@
"expected": "<>"
},

// 'else' sections

{
"name": "Missing key should trigger the inverted section rendering, and the omission of the 'else' section.",
"data": { },
"template": "<{{^subject}}---{{#subject}}+++{{/subject}}>",
"expected": "<--->"
},
{
"name": "Null should trigger the inverted section rendering, and the omission of the 'else' section.",
"data": { "subject": null },
"template": "<{{^subject}}---{{#subject}}+++{{/subject}}>",
"expected": "<--->"
},
{
"name": "False should trigger the inverted section rendering, and the omission of the 'else' section.",
"data": { "subject": false },
"template": "<{{^subject}}---{{#subject}}+++{{/subject}}>",
"expected": "<--->"
},
{
"name": "Empty string should trigger the inverted section rendering, and the omission of the 'else' section.",
"data": { "subject": "" },
"template": "<{{^subject}}---{{#subject}}+++{{/subject}}>",
"expected": "<--->"
},
{
"name": "Empty list should trigger the inverted section rendering, and the omission of the 'else' section.",
"data": { "subject": [] },
"template": "<{{^subject}}---{{#subject}}+++{{/subject}}>",
"expected": "<--->"
},
{
"name": "Zero should trigger the inverted section rendering, and the omission of the 'else' section.",
"data": { "subject": 0 },
"template": "<{{^subject}}---{{#subject}}+++{{/subject}}>",
"expected": "<--->"
},
{
"name": "True should trigger the inverted section omission, and the rendering of the 'else' section.",
"data": { "subject": true },
"template": "<{{^subject}}---{{#subject}}+++{{/subject}}>",
"expected": "<+++>"
},
{
"name": "Object should trigger the inverted section omission, and the rendering of the 'else' section.",
"data": { "subject": { } },
"template": "<{{^subject}}---{{#subject}}+++{{/subject}}>",
"expected": "<+++>"
},
{
"name": "Non-empty string should trigger the inverted section omission, and the rendering of the 'else' section.",
"data": { "subject": "---" },
"template": "<{{^subject}}---{{#subject}}+++{{/subject}}>",
"expected": "<+++>"
},
{
"name": "Non-empty blank string should trigger the inverted section omission, and the rendering of the 'else' section.",
"data": { "subject": " " },
"template": "<{{^subject}}---{{#subject}}+++{{/subject}}>",
"expected": "<+++>"
},
{
"name": "Non-empty list should trigger the inverted section omission, and the rendering of the 'else' section.",
"data": { "subject": [ { "n": 1 }, { "n": 2 }, { "n": 3 } ] },
"template": "<{{^subject}}---{{#subject}}{{n}}{{/subject}}>",
"expected": "<123>"
},
{
"name": "List made of an empty list should trigger the section omission, and the rendering of the 'else' section.",
"data": { "subject": [[]] },
"template": "<{{^subject}}---{{#subject}}+++{{/subject}}>",
"expected": "<+++>"
},

// Empty 'else' and closing tags

{
"name": "Closing tag may be empty.",
"data": { "subject": false },
"template": "<{{^subject}}---{{/}}>",
"expected": "<--->"
},

{
"name": "Closing tag may be blank.",
"data": { "subject": false },
"template": "<{{^subject}}---{{/ }}>",
"expected": "<--->"
},

{
"name": "Closing tag after 'else' tag may be empty.",
"data": { "subject": true },
"template": "<{{^subject}}---{{#subject}}+++{{/}}>",
"expected": "<+++>"
},

{
"name": "Closing tag after 'else' tag may be blank.",
"data": { "subject": true },
"template": "<{{^subject}}---{{#subject}}+++{{/ }}>",
"expected": "<+++>"
},

{
"name": "'Else' tag may be empty.",
"data": { "subject": true },
"template": "<{{^subject}}---{{#}}+++{{/subject}}>",
"expected": "<+++>"
},

{
"name": "'Else' tag may be blank.",
"data": { "subject": true },
"template": "<{{^subject}}---{{# }}+++{{/subject}}>",
"expected": "<+++>"
},

{
"name": "Both 'else' and closing tags may be empty.",
"data": { "subject": true },
"template": "<{{^subject}}---{{#}}+++{{/}}>",
"expected": "<+++>"
},

{
"name": "Both 'else' and closing tags may be blank.",
"data": { "subject": true },
"template": "<{{^subject}}---{{# }}+++{{/ }}>",
"expected": "<+++>"
},

// Whitespace Insensitivity

{
Expand Down

0 comments on commit 35125ca

Please sign in to comment.