forked from mustache/spec
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
133 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
overview: | | ||
Conditional tags are used to check for truthyness/falsyness | ||
values. They are similar to section, but don't iterate. Also, an | ||
else case can be specified. | ||
When and Unless tags SHOULD be treated as standalone when | ||
appropriate. | ||
tests: | ||
- name: Truthy When | ||
desc: Truthy Whens should have their contents rendered. | ||
data: { value: true } | ||
template: '{{?value}}This should be rendered.{{/value}}' | ||
expected: 'This should be rendered.' | ||
|
||
- name: Falsy When | ||
desc: Falsy Whens should not have their contents rendered. | ||
data: { value: false } | ||
template: '{{?value}}This should not be rendered.{{/value}}' | ||
expected: '' | ||
|
||
- name: Falsy Unless | ||
desc: Falsy Unless should have their contents rendered. | ||
data: { value: false } | ||
template: '{{^value}}This should be rendered.{{/value}}' | ||
expected: 'This should be rendered.' | ||
|
||
- name: Truthy Unless | ||
desc: Truthy Unless should not have their contents rendered. | ||
data: { value: true } | ||
template: '{{^value}}This should not be rendered.{{/value}}' | ||
expected: '' | ||
|
||
- name: When Unless aka If Then Else | ||
desc: When and Unless can be chained | ||
data: { value: true } | ||
template: '{{?value}}YES{{^value}}NO{{/value}}' | ||
expected: 'YES' | ||
|
||
- name: When Unless aka If Then Else with Falsy value | ||
desc: When and Unless can be chained | ||
data: { value: false } | ||
template: '{{?value}}YES{{^value}}NO{{/value}}' | ||
expected: 'NO' | ||
|
||
- name: When Unless aka If Then Else can be inverted | ||
desc: When and Unless can be inverted | ||
data: { value: false } | ||
template: '{{^value}}NO{{?value}}YES{{/value}}' | ||
expected: 'NO' | ||
|
||
# No iteration | ||
|
||
- name: When should not iterate | ||
desc: When is not a section | ||
data: | ||
{ list: [ { item: 1 }, { item: 2 }, { item: 3 } ], item: 'item' } | ||
template: '{{?list}}{{item}}{{/list}}' | ||
expected: 'item' | ||
|
||
# Whitespace Sensitivy | ||
- name: Surrounding Whitespace | ||
desc: Whens should not alter surrounding whitespace. | ||
data: { boolean: true } | ||
template: " | {{?boolean}}\t|\t{{/boolean}} | \n" | ||
expected: " | \t|\t | \n" | ||
|
||
- name: Internal Whitespace | ||
desc: Whens should not alter internal whitespace. | ||
data: { boolean: true } | ||
template: " | {{?boolean}} {{! Important Whitespace }}\n {{/boolean}} | \n" | ||
expected: " | \n | \n" | ||
|
||
- name: Indented Inline Sections | ||
desc: Single-line Whens should not alter surrounding whitespace. | ||
data: { boolean: true } | ||
template: " {{?boolean}}YES{{/boolean}}\n {{?boolean}}GOOD{{/boolean}}\n" | ||
expected: " YES\n GOOD\n" | ||
|
||
- name: Standalone Lines | ||
desc: Standalone lines should be removed from the template. | ||
data: { boolean: true } | ||
template: | | ||
| This Is | ||
{{?boolean}} | ||
| | ||
{{/boolean}} | ||
| A Line | ||
expected: | | ||
| This Is | ||
| | ||
| A Line | ||
- name: Indented Standalone Lines | ||
desc: Indented standalone lines should be removed from the template. | ||
data: { boolean: true } | ||
template: | | ||
| This Is | ||
{{?boolean}} | ||
| | ||
{{/boolean}} | ||
| A Line | ||
expected: | | ||
| This Is | ||
| | ||
| A Line | ||
- name: Standalone Line Endings | ||
desc: '"\r\n" should be considered a newline for standalone tags.' | ||
data: { boolean: true } | ||
template: "|\r\n{{?boolean}}\r\n{{/boolean}}\r\n|" | ||
expected: "|\r\n|" | ||
|
||
- name: Standalone Without Previous Line | ||
desc: Standalone tags should not require a newline to precede them. | ||
data: { boolean: true } | ||
template: " {{?boolean}}\n#{{/boolean}}\n/" | ||
expected: "#\n/" | ||
|
||
- name: Standalone Without Newline | ||
desc: Standalone tags should not require a newline to follow them. | ||
data: { boolean: true } | ||
template: "#{{?boolean}}\n/\n {{/boolean}}" | ||
expected: "#\n/\n" | ||
|
||
# Whitespace Insensitivity | ||
|
||
- name: Padding | ||
desc: Superfluous in-tag whitespace should be ignored. | ||
data: { boolean: true } | ||
template: '|{{? boolean }}={{/ boolean }}|' | ||
expected: '|=|' | ||
|