-
Notifications
You must be signed in to change notification settings - Fork 71
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
Feature/loop syntax #23
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ | ||
{"__ATTN__":"Do not edit this file; changes belong in the appropriate YAML file.","overview":"\nLoop tags are used to loop over an array, without lambda evaluation\nor testing for truthyness or pushing new hash context frames (hashes\nin the array however are pushed).\n\nLoop tags SHOULD be treated as standalone when\nappropriate.\n","tests":[{"name":"Loop over an empty array","data":{"array":[]},"expected":"","template":"{{,array}}This should not be rendered.{{/array}}","desc":"Loop over an empty array should not evaluate contents"},{"name":"Loop immediate","data":{"array":[1,2,3]},"expected":"1 2 3 ","template":"{{,array}}{{.}} {{/array}}","desc":"Loop over an array with immediate values"},{"name":"Loop hash","data":{"array":[{"item":1},{"item":2},{"item":3}]},"expected":"1 2 3 ","template":"{{,array}}{{item}} {{/array}}","desc":"Loop over an array with hashes"},{"name":"Loop single","data":{"a":"first","array":{"a":1,"b":2,"c":3}},"expected":"first first first ","template":"{{,array}}{{a}} {{/array}}","desc":"Loop over a hash should not push a new context"},{"name":"Nested loops single","data":{"a":"first","array":{"a":1,"b":2,"c":3}},"expected":"first first first ","template":"{{,array}}{{a}} {{/array}}","desc":"Loop over a hash should not push a new context"},{"name":"Context Misses","data":{},"expected":"","template":"{{,missing}}foobar{{/missing}}","desc":"Context misses should be considered as an empty array"},{"name":"Surrounding Whitespace","data":{"array":[1]},"expected":" | \t|\t | \n","template":" | {{,array}}\t|\t{{/array}} | \n","desc":"Loops should not alter surrounding whitespace."},{"name":"Internal Whitespace","data":{"array":[1]},"expected":" | \n | \n","template":" | {{,array}} {{! Important Whitespace }}\n {{/array}} | \n","desc":"Loops should not alter internal whitespace."},{"name":"Indented Inline Sections","data":{"array":[1]},"expected":" YES\n GOOD\n","template":" {{,array}}YES{{/array}}\n {{,array}}GOOD{{/array}}\n","desc":"Single-line Loops should not alter surrounding whitespace."},{"name":"Standalone Lines","data":{"array":[1]},"expected":"| This Is\n|\n| A Line\n","template":"| This Is\n{{,array}}\n|\n{{/array}}\n| A Line\n","desc":"Standalone lines should be removed from the template."},{"name":"Indented Standalone Lines","data":{"array":[1]},"expected":"| This Is\n|\n| A Line\n","template":"| This Is\n {{,array}}\n|\n {{/array}}\n| A Line\n","desc":"Indented standalone lines should be removed from the template."},{"name":"Standalone Line Endings","data":{"array":[1]},"expected":"|\r\n|","template":"|\r\n{{,array}}\r\n{{/array}}\r\n|","desc":"\"\\r\\n\" should be considered a newline for standalone tags."},{"name":"Standalone Without Previous Line","data":{"array":[1]},"expected":"#\n/","template":" {{,array}}\n#{{/array}}\n/","desc":"Standalone tags should not require a newline to precede them."},{"name":"Standalone Without Newline","data":{"array":[1]},"expected":"#\n/\n","template":"#{{,array}}\n/\n {{/array}}","desc":"Standalone tags should not require a newline to follow them."},{"name":"Padding","data":{"array":[1]},"expected":"|=|","template":"|{{, array }}={{/ array }}|","desc":"Superfluous in-tag whitespace should be ignored."}]} |
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,128 @@ | ||
overview: | | ||
|
||
Loop tags are used to loop over an array, without lambda evaluation | ||
or testing for truthyness or pushing new hash context frames (hashes | ||
in the array however are pushed). | ||
|
||
Loop tags SHOULD be treated as standalone when | ||
appropriate. | ||
tests: | ||
- name: Loop over an empty array | ||
desc: Loop over an empty array should not evaluate contents | ||
data: { array: [] } | ||
template: '{{,array}}This should not be rendered.{{/array}}' | ||
expected: '' | ||
|
||
- name: Loop immediate | ||
desc: Loop over an array with immediate values | ||
data: { array: [ 1, 2, 3 ] } | ||
template: '{{,array}}{{.}} {{/array}}' | ||
expected: '1 2 3 ' | ||
|
||
- name: Loop hash | ||
desc: Loop over an array with hashes | ||
data: { array: [ { item: 1 }, { item: 2 }, { item: 3 } ] } | ||
template: '{{,array}}{{item}} {{/array}}' | ||
expected: '1 2 3 ' | ||
|
||
- name: Loop single | ||
desc: Loop over a hash should not push a new context | ||
data: | ||
a: 'first' | ||
array: | ||
a: 1 | ||
b: 2 | ||
c: 3 | ||
template: '{{,array}}{{a}} {{/array}}' | ||
expected: 'first first first ' | ||
|
||
- name: Nested loops single | ||
desc: Loop over a hash should not push a new context | ||
data: | ||
a: 'first' | ||
array: | ||
a: 1 | ||
b: 2 | ||
c: 3 | ||
template: '{{,array}}{{a}} {{/array}}' | ||
expected: 'first first first ' | ||
|
||
- name: Context Misses | ||
desc: Context misses should be considered as an empty array | ||
data: { } | ||
template: '{{,missing}}foobar{{/missing}}' | ||
expected: '' | ||
|
||
# Whitespace Sensitivy | ||
- name: Surrounding Whitespace | ||
desc: Loops should not alter surrounding whitespace. | ||
data: { array: [ 1 ] } | ||
template: " | {{,array}}\t|\t{{/array}} | \n" | ||
expected: " | \t|\t | \n" | ||
|
||
- name: Internal Whitespace | ||
desc: Loops should not alter internal whitespace. | ||
data: { array: [ 1 ] } | ||
template: " | {{,array}} {{! Important Whitespace }}\n {{/array}} | \n" | ||
expected: " | \n | \n" | ||
|
||
- name: Indented Inline Sections | ||
desc: Single-line Loops should not alter surrounding whitespace. | ||
data: { array: [ 1 ] } | ||
template: " {{,array}}YES{{/array}}\n {{,array}}GOOD{{/array}}\n" | ||
expected: " YES\n GOOD\n" | ||
|
||
- name: Standalone Lines | ||
desc: Standalone lines should be removed from the template. | ||
data: { array: [ 1 ] } | ||
template: | | ||
| This Is | ||
{{,array}} | ||
| | ||
{{/array}} | ||
| A Line | ||
expected: | | ||
| This Is | ||
| | ||
| A Line | ||
|
||
- name: Indented Standalone Lines | ||
desc: Indented standalone lines should be removed from the template. | ||
data: { array: [ 1 ] } | ||
template: | | ||
| This Is | ||
{{,array}} | ||
| | ||
{{/array}} | ||
| A Line | ||
expected: | | ||
| This Is | ||
| | ||
| A Line | ||
|
||
- name: Standalone Line Endings | ||
desc: '"\r\n" should be considered a newline for standalone tags.' | ||
data: { array: [ 1 ] } | ||
template: "|\r\n{{,array}}\r\n{{/array}}\r\n|" | ||
expected: "|\r\n|" | ||
|
||
- name: Standalone Without Previous Line | ||
desc: Standalone tags should not require a newline to precede them. | ||
data: { array: [ 1 ] } | ||
template: " {{,array}}\n#{{/array}}\n/" | ||
expected: "#\n/" | ||
|
||
- name: Standalone Without Newline | ||
desc: Standalone tags should not require a newline to follow them. | ||
data: { array: [ 1 ] } | ||
template: "#{{,array}}\n/\n {{/array}}" | ||
expected: "#\n/\n" | ||
|
||
# Whitespace Insensitivity | ||
|
||
- name: Padding | ||
desc: Superfluous in-tag whitespace should be ignored. | ||
data: { array: [ 1 ] } | ||
template: '|{{, array }}={{/ array }}|' | ||
expected: '|=|' | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This test looks exactly like the previous one. Where is the difference?