Skip to content
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
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions specs/loop.json
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."}]}
128 changes: 128 additions & 0 deletions specs/loop.yml
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 '
Copy link

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?


- 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: '|=|'