From efc78b9a555af2cd90bc048f47d3bff0346c7315 Mon Sep 17 00:00:00 2001 From: Pieter van de Bruggen Date: Wed, 23 Feb 2011 18:34:57 -0800 Subject: Adding basic spec for the implicit iterator. --- specs/implicit_iterator.json | 1 + specs/implicit_iterator.yml | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 specs/implicit_iterator.json create mode 100644 specs/implicit_iterator.yml diff --git a/specs/implicit_iterator.json b/specs/implicit_iterator.json new file mode 100644 index 0000000..de0de6d --- /dev/null +++ b/specs/implicit_iterator.json @@ -0,0 +1 @@ +{"__ATTN__":"Do not edit this file; changes belong in the appropriate YAML file.","tests":[{"name":"Strings","data":{"list":["a","b","c","d","e"]},"expected":"\"(a)(b)(c)(d)(e)\"","template":"\"{{#list}}({{.}}){{/list}}\"","desc":"Strings should be directly interpolated."},{"name":"Integers","data":{"list":[1,2,3,4,5]},"expected":"\"(1)(2)(3)(4)(5)\"","template":"\"{{#list}}({{.}}){{/list}}\"","desc":"Integers should be coerced into strings and interpolated."},{"name":"Non-Integers","data":{"list":[1.1,2.2,3.3,4.4,5.5]},"expected":"\"(1.1)(2.2)(3.3)(4.4)(5.5)\"","template":"\"{{#list}}({{.}}){{/list}}\"","desc":"Non-integers should be coerced into strings and interpolated."}]} \ No newline at end of file diff --git a/specs/implicit_iterator.yml b/specs/implicit_iterator.yml new file mode 100644 index 0000000..eafd175 --- /dev/null +++ b/specs/implicit_iterator.yml @@ -0,0 +1,19 @@ +tests: + - name: Strings + desc: Strings should be directly interpolated. + data: + list: [ 'a', 'b', 'c', 'd', 'e' ] + template: '"{{#list}}({{.}}){{/list}}"' + expected: '"(a)(b)(c)(d)(e)"' + - name: Integers + desc: Integers should be coerced into strings and interpolated. + data: + list: [ 1, 2, 3, 4, 5 ] + template: '"{{#list}}({{.}}){{/list}}"' + expected: '"(1)(2)(3)(4)(5)"' + - name: Non-Integers + desc: Non-integers should be coerced into strings and interpolated. + data: + list: [ 1.1, 2.2, 3.3, 4.4, 5.5 ] + template: '"{{#list}}({{.}}){{/list}}"' + expected: '"(1.1)(2.2)(3.3)(4.4)(5.5)"' -- cgit v1.2.1 From 51342cec63e330dfe867c0013bf0c4440feb801b Mon Sep 17 00:00:00 2001 From: Pieter van de Bruggen Date: Wed, 2 Mar 2011 10:42:54 -0800 Subject: Moving the implicit iterator specs into the Section tag specs. --- specs/implicit_iterator.json | 1 - specs/implicit_iterator.yml | 19 ------------------- specs/sections.json | 2 +- specs/sections.yml | 23 +++++++++++++++++++++++ 4 files changed, 24 insertions(+), 21 deletions(-) delete mode 100644 specs/implicit_iterator.json delete mode 100644 specs/implicit_iterator.yml diff --git a/specs/implicit_iterator.json b/specs/implicit_iterator.json deleted file mode 100644 index de0de6d..0000000 --- a/specs/implicit_iterator.json +++ /dev/null @@ -1 +0,0 @@ -{"__ATTN__":"Do not edit this file; changes belong in the appropriate YAML file.","tests":[{"name":"Strings","data":{"list":["a","b","c","d","e"]},"expected":"\"(a)(b)(c)(d)(e)\"","template":"\"{{#list}}({{.}}){{/list}}\"","desc":"Strings should be directly interpolated."},{"name":"Integers","data":{"list":[1,2,3,4,5]},"expected":"\"(1)(2)(3)(4)(5)\"","template":"\"{{#list}}({{.}}){{/list}}\"","desc":"Integers should be coerced into strings and interpolated."},{"name":"Non-Integers","data":{"list":[1.1,2.2,3.3,4.4,5.5]},"expected":"\"(1.1)(2.2)(3.3)(4.4)(5.5)\"","template":"\"{{#list}}({{.}}){{/list}}\"","desc":"Non-integers should be coerced into strings and interpolated."}]} \ No newline at end of file diff --git a/specs/implicit_iterator.yml b/specs/implicit_iterator.yml deleted file mode 100644 index eafd175..0000000 --- a/specs/implicit_iterator.yml +++ /dev/null @@ -1,19 +0,0 @@ -tests: - - name: Strings - desc: Strings should be directly interpolated. - data: - list: [ 'a', 'b', 'c', 'd', 'e' ] - template: '"{{#list}}({{.}}){{/list}}"' - expected: '"(a)(b)(c)(d)(e)"' - - name: Integers - desc: Integers should be coerced into strings and interpolated. - data: - list: [ 1, 2, 3, 4, 5 ] - template: '"{{#list}}({{.}}){{/list}}"' - expected: '"(1)(2)(3)(4)(5)"' - - name: Non-Integers - desc: Non-integers should be coerced into strings and interpolated. - data: - list: [ 1.1, 2.2, 3.3, 4.4, 5.5 ] - template: '"{{#list}}({{.}}){{/list}}"' - expected: '"(1.1)(2.2)(3.3)(4.4)(5.5)"' diff --git a/specs/sections.json b/specs/sections.json index c6ba2ac..a8f15e0 100644 --- a/specs/sections.json +++ b/specs/sections.json @@ -1 +1 @@ -{"__ATTN__":"Do not edit this file; changes belong in the appropriate YAML file.","tests":[{"name":"Truthy","data":{"boolean":true},"expected":"\"This should be rendered.\"","template":"\"{{#boolean}}This should be rendered.{{/boolean}}\"","desc":"Truthy sections should have their contents rendered."},{"name":"Falsey","data":{"boolean":false},"expected":"\"\"","template":"\"{{#boolean}}This should not be rendered.{{/boolean}}\"","desc":"Falsey sections should have their contents omitted."},{"name":"Context","data":{"context":{"name":"Joe"}},"expected":"\"Hi Joe.\"","template":"\"{{#context}}Hi {{name}}.{{/context}}\"","desc":"Objects and hashes should be pushed onto the context stack."},{"name":"Deeply Nested Contexts","data":{"a":{"one":1},"b":{"two":2},"c":{"three":3},"d":{"four":4},"e":{"five":5}},"expected":"1\n121\n12321\n1234321\n123454321\n1234321\n12321\n121\n1\n","template":"{{#a}}\n{{one}}\n{{#b}}\n{{one}}{{two}}{{one}}\n{{#c}}\n{{one}}{{two}}{{three}}{{two}}{{one}}\n{{#d}}\n{{one}}{{two}}{{three}}{{four}}{{three}}{{two}}{{one}}\n{{#e}}\n{{one}}{{two}}{{three}}{{four}}{{five}}{{four}}{{three}}{{two}}{{one}}\n{{/e}}\n{{one}}{{two}}{{three}}{{four}}{{three}}{{two}}{{one}}\n{{/d}}\n{{one}}{{two}}{{three}}{{two}}{{one}}\n{{/c}}\n{{one}}{{two}}{{one}}\n{{/b}}\n{{one}}\n{{/a}}\n","desc":"All elements on the context stack should be accessible."},{"name":"List","data":{"list":[{"item":1},{"item":2},{"item":3}]},"expected":"\"123\"","template":"\"{{#list}}{{item}}{{/list}}\"","desc":"Lists should be iterated; list items should visit the context stack."},{"name":"Empty List","data":{"list":[]},"expected":"\"\"","template":"\"{{#list}}Yay lists!{{/list}}\"","desc":"Empty lists should behave like falsey values."},{"name":"Doubled","data":{"two":"second","bool":true},"expected":"* first\n* second\n* third\n","template":"{{#bool}}\n* first\n{{/bool}}\n* {{two}}\n{{#bool}}\n* third\n{{/bool}}\n","desc":"Multiple sections per template should be permitted."},{"name":"Nested (Truthy)","data":{"bool":true},"expected":"| A B C D E |","template":"| A {{#bool}}B {{#bool}}C{{/bool}} D{{/bool}} E |","desc":"Nested truthy sections should have their contents rendered."},{"name":"Nested (Falsey)","data":{"bool":false},"expected":"| A E |","template":"| A {{#bool}}B {{#bool}}C{{/bool}} D{{/bool}} E |","desc":"Nested falsey sections should be omitted."},{"name":"Surrounding Whitespace","data":{"boolean":true},"expected":" | \t|\t | \n","template":" | {{#boolean}}\t|\t{{/boolean}} | \n","desc":"Sections should not alter surrounding whitespace."},{"name":"Internal Whitespace","data":{"boolean":true},"expected":" | \n | \n","template":" | {{#boolean}} {{! Important Whitespace }}\n {{/boolean}} | \n","desc":"Sections should not alter internal whitespace."},{"name":"Standalone Lines","data":{"boolean":true},"expected":"| This Is\n|\n| A Line\n","template":"| This Is\n{{#boolean}}\n|\n{{/boolean}}\n| A Line\n","desc":"Standalone lines should be removed from the template."},{"name":"Indented Standalone Lines","data":{"boolean":true},"expected":"| This Is\n|\n| A Line\n","template":"| This Is\n {{#boolean}}\n|\n {{/boolean}}\n| A Line\n","desc":"Indented standalone lines should be removed from the template."},{"name":"Padding","data":{"boolean":true},"expected":"|=|","template":"|{{# boolean }}={{/ boolean }}|","desc":"Superfluous in-tag whitespace should be ignored."}]} \ No newline at end of file +{"__ATTN__":"Do not edit this file; changes belong in the appropriate YAML file.","tests":[{"name":"Truthy","data":{"boolean":true},"expected":"\"This should be rendered.\"","template":"\"{{#boolean}}This should be rendered.{{/boolean}}\"","desc":"Truthy sections should have their contents rendered."},{"name":"Falsey","data":{"boolean":false},"expected":"\"\"","template":"\"{{#boolean}}This should not be rendered.{{/boolean}}\"","desc":"Falsey sections should have their contents omitted."},{"name":"Context","data":{"context":{"name":"Joe"}},"expected":"\"Hi Joe.\"","template":"\"{{#context}}Hi {{name}}.{{/context}}\"","desc":"Objects and hashes should be pushed onto the context stack."},{"name":"Deeply Nested Contexts","data":{"a":{"one":1},"b":{"two":2},"c":{"three":3},"d":{"four":4},"e":{"five":5}},"expected":"1\n121\n12321\n1234321\n123454321\n1234321\n12321\n121\n1\n","template":"{{#a}}\n{{one}}\n{{#b}}\n{{one}}{{two}}{{one}}\n{{#c}}\n{{one}}{{two}}{{three}}{{two}}{{one}}\n{{#d}}\n{{one}}{{two}}{{three}}{{four}}{{three}}{{two}}{{one}}\n{{#e}}\n{{one}}{{two}}{{three}}{{four}}{{five}}{{four}}{{three}}{{two}}{{one}}\n{{/e}}\n{{one}}{{two}}{{three}}{{four}}{{three}}{{two}}{{one}}\n{{/d}}\n{{one}}{{two}}{{three}}{{two}}{{one}}\n{{/c}}\n{{one}}{{two}}{{one}}\n{{/b}}\n{{one}}\n{{/a}}\n","desc":"All elements on the context stack should be accessible."},{"name":"List","data":{"list":[{"item":1},{"item":2},{"item":3}]},"expected":"\"123\"","template":"\"{{#list}}{{item}}{{/list}}\"","desc":"Lists should be iterated; list items should visit the context stack."},{"name":"Empty List","data":{"list":[]},"expected":"\"\"","template":"\"{{#list}}Yay lists!{{/list}}\"","desc":"Empty lists should behave like falsey values."},{"name":"Doubled","data":{"two":"second","bool":true},"expected":"* first\n* second\n* third\n","template":"{{#bool}}\n* first\n{{/bool}}\n* {{two}}\n{{#bool}}\n* third\n{{/bool}}\n","desc":"Multiple sections per template should be permitted."},{"name":"Nested (Truthy)","data":{"bool":true},"expected":"| A B C D E |","template":"| A {{#bool}}B {{#bool}}C{{/bool}} D{{/bool}} E |","desc":"Nested truthy sections should have their contents rendered."},{"name":"Nested (Falsey)","data":{"bool":false},"expected":"| A E |","template":"| A {{#bool}}B {{#bool}}C{{/bool}} D{{/bool}} E |","desc":"Nested falsey sections should be omitted."},{"name":"Implicit Iterator - String","data":{"list":["a","b","c","d","e"]},"expected":"\"(a)(b)(c)(d)(e)\"","template":"\"{{#list}}({{.}}){{/list}}\"","desc":"Implicit iterators should directly interpolate strings."},{"name":"Implicit Iterator - Integer","data":{"list":[1,2,3,4,5]},"expected":"\"(1)(2)(3)(4)(5)\"","template":"\"{{#list}}({{.}}){{/list}}\"","desc":"Implicit iterators should cast integers to strings and interpolate."},{"name":"Implicit Iterator - Decimal","data":{"list":[1.1,2.2,3.3,4.4,5.5]},"expected":"\"(1.1)(2.2)(3.3)(4.4)(5.5)\"","template":"\"{{#list}}({{.}}){{/list}}\"","desc":"Implicit iterators should cast decimals to strings and interpolate."},{"name":"Surrounding Whitespace","data":{"boolean":true},"expected":" | \t|\t | \n","template":" | {{#boolean}}\t|\t{{/boolean}} | \n","desc":"Sections should not alter surrounding whitespace."},{"name":"Internal Whitespace","data":{"boolean":true},"expected":" | \n | \n","template":" | {{#boolean}} {{! Important Whitespace }}\n {{/boolean}} | \n","desc":"Sections should not alter internal whitespace."},{"name":"Standalone Lines","data":{"boolean":true},"expected":"| This Is\n|\n| A Line\n","template":"| This Is\n{{#boolean}}\n|\n{{/boolean}}\n| A Line\n","desc":"Standalone lines should be removed from the template."},{"name":"Indented Standalone Lines","data":{"boolean":true},"expected":"| This Is\n|\n| A Line\n","template":"| This Is\n {{#boolean}}\n|\n {{/boolean}}\n| A Line\n","desc":"Indented standalone lines should be removed from the template."},{"name":"Padding","data":{"boolean":true},"expected":"|=|","template":"|{{# boolean }}={{/ boolean }}|","desc":"Superfluous in-tag whitespace should be ignored."}]} \ No newline at end of file diff --git a/specs/sections.yml b/specs/sections.yml index 5d61227..c79a782 100644 --- a/specs/sections.yml +++ b/specs/sections.yml @@ -96,6 +96,29 @@ tests: template: "| A {{#bool}}B {{#bool}}C{{/bool}} D{{/bool}} E |" expected: "| A E |" + # Implicit Iterators + + - name: Implicit Iterator - String + desc: Implicit iterators should directly interpolate strings. + data: + list: [ 'a', 'b', 'c', 'd', 'e' ] + template: '"{{#list}}({{.}}){{/list}}"' + expected: '"(a)(b)(c)(d)(e)"' + + - name: Implicit Iterator - Integer + desc: Implicit iterators should cast integers to strings and interpolate. + data: + list: [ 1, 2, 3, 4, 5 ] + template: '"{{#list}}({{.}}){{/list}}"' + expected: '"(1)(2)(3)(4)(5)"' + + - name: Implicit Iterator - Decimal + desc: Implicit iterators should cast decimals to strings and interpolate. + data: + list: [ 1.10, 2.20, 3.30, 4.40, 5.50 ] + template: '"{{#list}}({{.}}){{/list}}"' + expected: '"(1.1)(2.2)(3.3)(4.4)(5.5)"' + # Whitespace Sensitivity - name: Surrounding Whitespace -- cgit v1.2.1