summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--specs/sections.json2
-rw-r--r--specs/sections.yml2
-rw-r--r--specs/~lambdas.json2
-rw-r--r--specs/~lambdas.yml10
4 files changed, 13 insertions, 3 deletions
diff --git a/specs/sections.json b/specs/sections.json
index f22c188..1dfcff0 100644
--- a/specs/sections.json
+++ b/specs/sections.json
@@ -1 +1 @@
-{"__ATTN__":"Do not edit this file; changes belong in the appropriate YAML file.","overview":"Section tags and End Section tags are used in combination to wrap a section\nof the template for iteration\n\nThese tags' content MUST be a non-whitespace character sequence NOT\ncontaining the current closing delimiter; each Section tag MUST be followed\nby an End Section tag with the same content within the same section.\n\nThis tag's content names the data to replace the tag. Name resolution is as\nfollows:\n 1) Split the name on periods; the first part is the name to resolve, any\n remaining parts should be retained.\n 2) Walk the context stack from top to bottom, finding the first context\n that is a) a hash containing the name as a key OR b) an object responding\n to a method with the given name.\n 3) If the context is a hash, the data is the value associated with the\n name.\n 4) If the context is an object and the method with the given name has an\n arity of 1, the method SHOULD be called with a String containing the\n unprocessed contents of the sections; the data is the value returned.\n 5) Otherwise, the data is the value returned by calling the method with\n the given name.\n 6) If any name parts were retained in step 1, each should be resolved\n against a context stack containing only the result from the former\n resolution. If any part fails resolution, the result should be considered\n falsey, and should interpolate as the empty string.\nIf the data is not of a list type, it is coerced into a list as follows: if\nthe data is truthy (e.g. `!!data == true`), use a single-element list\ncontaining the data, otherwise use an empty list.\n\nFor each element in the data list, the element MUST be pushed onto the\ncontext stack, the section MUST be rendered, and the element MUST be popped\noff the context stack.\n\nSection and End Section tags SHOULD be treated as standalone when\nappropriate.\n","tests":[{"name":"Truthy","desc":"Truthy sections should have their contents rendered.","data":{"boolean":true},"template":"\"{{#boolean}}This should be rendered.{{/boolean}}\"","expected":"\"This should be rendered.\""},{"name":"Falsey","desc":"Falsey sections should have their contents omitted.","data":{"boolean":false},"template":"\"{{#boolean}}This should not be rendered.{{/boolean}}\"","expected":"\"\""},{"name":"Context","desc":"Objects and hashes should be pushed onto the context stack.","data":{"context":{"name":"Joe"}},"template":"\"{{#context}}Hi {{name}}.{{/context}}\"","expected":"\"Hi Joe.\""},{"name":"Parent contexts","desc":"Names missing in the current context are looked up in the stack.","data":{"a":"foo","b":"wrong","sec":{"b":"bar"},"c":{"d":"baz"}},"template":"\"{{#sec}}{{a}}, {{b}}, {{c.d}}{{/sec}}\"","expected":"\"foo, bar, baz\""},{"name":"Variable test","desc":"Non-false sections have their value at the top of context,\naccessible as {{.}} or through the parent context. This gives\na simple way to display content conditionally if a variable exists.\n","data":{"foo":"bar"},"template":"\"{{#foo}} {{.}} is {{foo}} {{/foo}}\"","expected":"\"bar is bar\""},{"name":"List Contexts","desc":"All elements on the context stack should be accessible within lists.","data":{"tops":[{"tname":{"upper":"A","lower":"a"},"middles":[{"mname":"1","bottoms":[{"bname":"x"},{"bname":"y"}]}]}]},"template":"{{#tops}}{{#middles}}{{tname.lower}}{{mname}}.{{#bottoms}}{{tname.upper}}{{mname}}{{bname}}.{{/bottoms}}{{/middles}}{{/tops}}","expected":"a1.A1x.A1y."},{"name":"Deeply Nested Contexts","desc":"All elements on the context stack should be accessible.","data":{"a":{"one":1},"b":{"two":2},"c":{"three":3,"d":{"four":4,"five":5}}},"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{{#five}}\n{{one}}{{two}}{{three}}{{four}}{{five}}{{four}}{{three}}{{two}}{{one}}\n{{one}}{{two}}{{three}}{{four}}{{.}}6{{.}}{{four}}{{three}}{{two}}{{one}}\n{{one}}{{two}}{{three}}{{four}}{{five}}{{four}}{{three}}{{two}}{{one}}\n{{/five}}\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","expected":"1\n121\n12321\n1234321\n123454321\n12345654321\n123454321\n1234321\n12321\n121\n1\n"},{"name":"List","desc":"Lists should be iterated; list items should visit the context stack.","data":{"list":[{"item":1},{"item":2},{"item":3}]},"template":"\"{{#list}}{{item}}{{/list}}\"","expected":"\"123\""},{"name":"Empty List","desc":"Empty lists should behave like falsey values.","data":{"list":[]},"template":"\"{{#list}}Yay lists!{{/list}}\"","expected":"\"\""},{"name":"Doubled","desc":"Multiple sections per template should be permitted.","data":{"bool":true,"two":"second"},"template":"{{#bool}}\n* first\n{{/bool}}\n* {{two}}\n{{#bool}}\n* third\n{{/bool}}\n","expected":"* first\n* second\n* third\n"},{"name":"Nested (Truthy)","desc":"Nested truthy sections should have their contents rendered.","data":{"bool":true},"template":"| A {{#bool}}B {{#bool}}C{{/bool}} D{{/bool}} E |","expected":"| A B C D E |"},{"name":"Nested (Falsey)","desc":"Nested falsey sections should be omitted.","data":{"bool":false},"template":"| A {{#bool}}B {{#bool}}C{{/bool}} D{{/bool}} E |","expected":"| A E |"},{"name":"Context Misses","desc":"Failed context lookups should be considered falsey.","data":{},"template":"[{{#missing}}Found key 'missing'!{{/missing}}]","expected":"[]"},{"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.1,2.2,3.3,4.4,5.5]},"template":"\"{{#list}}({{.}}){{/list}}\"","expected":"\"(1.1)(2.2)(3.3)(4.4)(5.5)\""},{"name":"Implicit Iterator - Array","desc":"Implicit iterators should allow iterating over nested arrays.","data":{"list":[[1,2,3],["a","b","c"]]},"template":"\"{{#list}}({{#.}}{{.}}{{/.}}){{/list}}\"","expected":"\"(123)(abc)\""},{"name":"Dotted Names - Truthy","desc":"Dotted names should be valid for Section tags.","data":{"a":{"b":{"c":true}}},"template":"\"{{#a.b.c}}Here{{/a.b.c}}\" == \"Here\"","expected":"\"Here\" == \"Here\""},{"name":"Dotted Names - Falsey","desc":"Dotted names should be valid for Section tags.","data":{"a":{"b":{"c":false}}},"template":"\"{{#a.b.c}}Here{{/a.b.c}}\" == \"\"","expected":"\"\" == \"\""},{"name":"Dotted Names - Broken Chains","desc":"Dotted names that cannot be resolved should be considered falsey.","data":{"a":{}},"template":"\"{{#a.b.c}}Here{{/a.b.c}}\" == \"\"","expected":"\"\" == \"\""},{"name":"Surrounding Whitespace","desc":"Sections should not alter surrounding whitespace.","data":{"boolean":true},"template":" | {{#boolean}}\t|\t{{/boolean}} | \n","expected":" | \t|\t | \n"},{"name":"Internal Whitespace","desc":"Sections 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 sections 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\n{{#boolean}}\n|\n{{/boolean}}\n| A Line\n","expected":"| This Is\n|\n| A Line\n"},{"name":"Indented Standalone Lines","desc":"Indented standalone lines should be removed from the template.","data":{"boolean":true},"template":"| This Is\n {{#boolean}}\n|\n {{/boolean}}\n| A Line\n","expected":"| This Is\n|\n| A Line\n"},{"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"},{"name":"Padding","desc":"Superfluous in-tag whitespace should be ignored.","data":{"boolean":true},"template":"|{{# boolean }}={{/ boolean }}|","expected":"|=|"}]} \ No newline at end of file
+{"__ATTN__":"Do not edit this file; changes belong in the appropriate YAML file.","overview":"Section tags and End Section tags are used in combination to wrap a section\nof the template for iteration\n\nThese tags' content MUST be a non-whitespace character sequence NOT\ncontaining the current closing delimiter; each Section tag MUST be followed\nby an End Section tag with the same content within the same section.\n\nThis tag's content names the data to replace the tag. Name resolution is as\nfollows:\n 1) Split the name on periods; the first part is the name to resolve, any\n remaining parts should be retained.\n 2) Walk the context stack from top to bottom, finding the first context\n that is a) a hash containing the name as a key OR b) an object responding\n to a method with the given name.\n 3) If the context is a hash, the data is the value associated with the\n name.\n 4) If the context is an object and the method with the given name has an\n arity of 1, the method SHOULD be called with a String containing the\n unprocessed contents of the sections; the data is the value returned.\n 5) Otherwise, the data is the value returned by calling the method with\n the given name.\n 6) If any name parts were retained in step 1, each should be resolved\n against a context stack containing only the result from the former\n resolution. If any part fails resolution, the result should be considered\n falsey, and should interpolate as the empty string.\nIf the data is not of a list type, it is coerced into a list as follows: if\nthe data is truthy (e.g. `!!data == true`), use a single-element list\ncontaining the data, otherwise use an empty list.\n\nFor each element in the data list, the element MUST be pushed onto the\ncontext stack, the section MUST be rendered, and the element MUST be popped\noff the context stack.\n\nSection and End Section tags SHOULD be treated as standalone when\nappropriate.\n","tests":[{"name":"Truthy","desc":"Truthy sections should have their contents rendered.","data":{"boolean":true},"template":"\"{{#boolean}}This should be rendered.{{/boolean}}\"","expected":"\"This should be rendered.\""},{"name":"Falsey","desc":"Falsey sections should have their contents omitted.","data":{"boolean":false},"template":"\"{{#boolean}}This should not be rendered.{{/boolean}}\"","expected":"\"\""},{"name":"Context","desc":"Objects and hashes should be pushed onto the context stack.","data":{"context":{"name":"Joe"}},"template":"\"{{#context}}Hi {{name}}.{{/context}}\"","expected":"\"Hi Joe.\""},{"name":"Parent contexts","desc":"Names missing in the current context are looked up in the stack.","data":{"a":"foo","b":"wrong","sec":{"b":"bar"},"c":{"d":"baz"}},"template":"\"{{#sec}}{{a}}, {{b}}, {{c.d}}{{/sec}}\"","expected":"\"foo, bar, baz\""},{"name":"Variable test","desc":"Non-false sections have their value at the top of context,\naccessible as {{.}} or through the parent context. This gives\na simple way to display content conditionally if a variable exists.\n","data":{"foo":"bar"},"template":"\"{{#foo}}{{.}} is {{foo}}{{/foo}}\"","expected":"\"bar is bar\""},{"name":"List Contexts","desc":"All elements on the context stack should be accessible within lists.","data":{"tops":[{"tname":{"upper":"A","lower":"a"},"middles":[{"mname":"1","bottoms":[{"bname":"x"},{"bname":"y"}]}]}]},"template":"{{#tops}}{{#middles}}{{tname.lower}}{{mname}}.{{#bottoms}}{{tname.upper}}{{mname}}{{bname}}.{{/bottoms}}{{/middles}}{{/tops}}","expected":"a1.A1x.A1y."},{"name":"Deeply Nested Contexts","desc":"All elements on the context stack should be accessible.","data":{"a":{"one":1},"b":{"two":2},"c":{"three":3,"d":{"four":4,"five":5}}},"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{{#five}}\n{{one}}{{two}}{{three}}{{four}}{{five}}{{four}}{{three}}{{two}}{{one}}\n{{one}}{{two}}{{three}}{{four}}{{.}}6{{.}}{{four}}{{three}}{{two}}{{one}}\n{{one}}{{two}}{{three}}{{four}}{{five}}{{four}}{{three}}{{two}}{{one}}\n{{/five}}\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","expected":"1\n121\n12321\n1234321\n123454321\n12345654321\n123454321\n1234321\n12321\n121\n1\n"},{"name":"List","desc":"Lists should be iterated; list items should visit the context stack.","data":{"list":[{"item":1},{"item":2},{"item":3}]},"template":"\"{{#list}}{{item}}{{/list}}\"","expected":"\"123\""},{"name":"Empty List","desc":"Empty lists should behave like falsey values.","data":{"list":[]},"template":"\"{{#list}}Yay lists!{{/list}}\"","expected":"\"\""},{"name":"Doubled","desc":"Multiple sections per template should be permitted.","data":{"bool":true,"two":"second"},"template":"{{#bool}}\n* first\n{{/bool}}\n* {{two}}\n{{#bool}}\n* third\n{{/bool}}\n","expected":"* first\n* second\n* third\n"},{"name":"Nested (Truthy)","desc":"Nested truthy sections should have their contents rendered.","data":{"bool":true},"template":"| A {{#bool}}B {{#bool}}C{{/bool}} D{{/bool}} E |","expected":"| A B C D E |"},{"name":"Nested (Falsey)","desc":"Nested falsey sections should be omitted.","data":{"bool":false},"template":"| A {{#bool}}B {{#bool}}C{{/bool}} D{{/bool}} E |","expected":"| A E |"},{"name":"Context Misses","desc":"Failed context lookups should be considered falsey.","data":{},"template":"[{{#missing}}Found key 'missing'!{{/missing}}]","expected":"[]"},{"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.1,2.2,3.3,4.4,5.5]},"template":"\"{{#list}}({{.}}){{/list}}\"","expected":"\"(1.1)(2.2)(3.3)(4.4)(5.5)\""},{"name":"Implicit Iterator - Array","desc":"Implicit iterators should allow iterating over nested arrays.","data":{"list":[[1,2,3],["a","b","c"]]},"template":"\"{{#list}}({{#.}}{{.}}{{/.}}){{/list}}\"","expected":"\"(123)(abc)\""},{"name":"Dotted Names - Truthy","desc":"Dotted names should be valid for Section tags.","data":{"a":{"b":{"c":true}}},"template":"\"{{#a.b.c}}Here{{/a.b.c}}\" == \"Here\"","expected":"\"Here\" == \"Here\""},{"name":"Dotted Names - Falsey","desc":"Dotted names should be valid for Section tags.","data":{"a":{"b":{"c":false}}},"template":"\"{{#a.b.c}}Here{{/a.b.c}}\" == \"\"","expected":"\"\" == \"\""},{"name":"Dotted Names - Broken Chains","desc":"Dotted names that cannot be resolved should be considered falsey.","data":{"a":{}},"template":"\"{{#a.b.c}}Here{{/a.b.c}}\" == \"\"","expected":"\"\" == \"\""},{"name":"Surrounding Whitespace","desc":"Sections should not alter surrounding whitespace.","data":{"boolean":true},"template":" | {{#boolean}}\t|\t{{/boolean}} | \n","expected":" | \t|\t | \n"},{"name":"Internal Whitespace","desc":"Sections 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 sections 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\n{{#boolean}}\n|\n{{/boolean}}\n| A Line\n","expected":"| This Is\n|\n| A Line\n"},{"name":"Indented Standalone Lines","desc":"Indented standalone lines should be removed from the template.","data":{"boolean":true},"template":"| This Is\n {{#boolean}}\n|\n {{/boolean}}\n| A Line\n","expected":"| This Is\n|\n| A Line\n"},{"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"},{"name":"Padding","desc":"Superfluous in-tag whitespace should be ignored.","data":{"boolean":true},"template":"|{{# boolean }}={{/ boolean }}|","expected":"|=|"}]} \ No newline at end of file
diff --git a/specs/sections.yml b/specs/sections.yml
index 2d1e982..40021c0 100644
--- a/specs/sections.yml
+++ b/specs/sections.yml
@@ -65,7 +65,7 @@ tests:
accessible as {{.}} or through the parent context. This gives
a simple way to display content conditionally if a variable exists.
data: { foo: "bar" }
- template: '"{{#foo}} {{.}} is {{foo}} {{/foo}}"'
+ template: '"{{#foo}}{{.}} is {{foo}}{{/foo}}"'
expected: '"bar is bar"'
- name: List Contexts
diff --git a/specs/~lambdas.json b/specs/~lambdas.json
index 57c116f..760c733 100644
--- a/specs/~lambdas.json
+++ b/specs/~lambdas.json
@@ -1 +1 @@
-{"__ATTN__":"Do not edit this file; changes belong in the appropriate YAML file.","overview":"Lambdas are a special-cased data type for use in interpolations and\nsections.\n\nWhen used as the data value for an Interpolation tag, the lambda MUST be\ntreatable as an arity 0 function, and invoked as such. The returned value\nMUST be rendered against the default delimiters, then interpolated in place\nof the lambda.\n\nWhen used as the data value for a Section tag, the lambda MUST be treatable\nas an arity 1 function, and invoked as such (passing a String containing the\nunprocessed section contents). The returned value MUST be rendered against\nthe current delimiters, then interpolated in place of the section.\n","tests":[{"name":"Interpolation","desc":"A lambda's return value should be interpolated.","data":{"lambda":{"ruby":"proc { \"world\" }","perl":"sub { \"world\" }","js":"function() { return \"world\" }","php":"return \"world\";","python":"lambda: \"world\"","clojure":"(fn [] \"world\")","lisp":"(lambda () \"world\")"}},"template":"Hello, {{lambda}}!","expected":"Hello, world!"},{"name":"Interpolation - Expansion","desc":"A lambda's return value should be parsed.","data":{"planet":"world","lambda":{"ruby":"proc { \"{{planet}}\" }","perl":"sub { \"{{planet}}\" }","js":"function() { return \"{{planet}}\" }","php":"return \"{{planet}}\";","python":"lambda: \"{{planet}}\"","clojure":"(fn [] \"{{planet}}\")","lisp":"(lambda () \"{{planet}}\")"}},"template":"Hello, {{lambda}}!","expected":"Hello, world!"},{"name":"Interpolation - Alternate Delimiters","desc":"A lambda's return value should parse with the default delimiters.","data":{"planet":"world","lambda":{"ruby":"proc { \"|planet| => {{planet}}\" }","perl":"sub { \"|planet| => {{planet}}\" }","js":"function() { return \"|planet| => {{planet}}\" }","php":"return \"|planet| => {{planet}}\";","python":"lambda: \"|planet| => {{planet}}\"","clojure":"(fn [] \"|planet| => {{planet}}\")","lisp":"(lambda () \"|planet| => {{planet}}\")"}},"template":"{{= | | =}}\nHello, (|&lambda|)!","expected":"Hello, (|planet| => world)!"},{"name":"Interpolation - Multiple Calls","desc":"Interpolated lambdas should not be cached.","data":{"lambda":{"ruby":"proc { $calls ||= 0; $calls += 1 }","perl":"sub { no strict; $calls += 1 }","js":"function() { return (g=(function(){return this})()).calls=(g.calls||0)+1 }","php":"global $calls; return ++$calls;","python":"lambda: globals().update(calls=globals().get(\"calls\",0)+1) or calls","clojure":"(def g (atom 0)) (fn [] (swap! g inc))","lisp":"(let ((g 0)) (lambda () (incf g)))"}},"template":"{{lambda}} == {{{lambda}}} == {{lambda}}","expected":"1 == 2 == 3"},{"name":"Escaping","desc":"Lambda results should be appropriately escaped.","data":{"lambda":{"ruby":"proc { \">\" }","perl":"sub { \">\" }","js":"function() { return \">\" }","php":"return \">\";","python":"lambda: \">\"","clojure":"(fn [] \">\")","lisp":"(lambda () \">\")"}},"template":"<{{lambda}}{{{lambda}}}","expected":"<&gt;>"},{"name":"Section","desc":"Lambdas used for sections should receive the raw section string.","data":{"x":"Error!","lambda":{"ruby":"proc { |text| text == \"{{x}}\" ? \"yes\" : \"no\" }","perl":"sub { $_[0] eq \"{{x}}\" ? \"yes\" : \"no\" }","js":"function(txt) { return (txt == \"{{x}}\" ? \"yes\" : \"no\") }","php":"return ($text == \"{{x}}\") ? \"yes\" : \"no\";","python":"lambda text: text == \"{{x}}\" and \"yes\" or \"no\"","clojure":"(fn [text] (if (= text \"{{x}}\") \"yes\" \"no\"))","lisp":"(lambda (text) (if (string= text \"{{x}}\") \"yes\" \"no\"))"}},"template":"<{{#lambda}}{{x}}{{/lambda}}>","expected":"<yes>"},{"name":"Section - Expansion","desc":"Lambdas used for sections should have their results parsed.","data":{"planet":"Earth","lambda":{"ruby":"proc { |text| \"#{text}{{planet}}#{text}\" }","perl":"sub { $_[0] . \"{{planet}}\" . $_[0] }","js":"function(txt) { return txt + \"{{planet}}\" + txt }","php":"return $text . \"{{planet}}\" . $text;","python":"lambda text: \"%s{{planet}}%s\" % (text, text)","clojure":"(fn [text] (str text \"{{planet}}\" text))","lisp":"(lambda (text) (format nil \"~a{{planet}}~a\" text text))"}},"template":"<{{#lambda}}-{{/lambda}}>","expected":"<-Earth->"},{"name":"Section - Alternate Delimiters","desc":"Lambdas used for sections should parse with the current delimiters.","data":{"planet":"Earth","lambda":{"ruby":"proc { |text| \"#{text}{{planet}} => |planet|#{text}\" }","perl":"sub { $_[0] . \"{{planet}} => |planet|\" . $_[0] }","js":"function(txt) { return txt + \"{{planet}} => |planet|\" + txt }","php":"return $text . \"{{planet}} => |planet|\" . $text;","python":"lambda text: \"%s{{planet}} => |planet|%s\" % (text, text)","clojure":"(fn [text] (str text \"{{planet}} => |planet|\" text))","lisp":"(lambda (text) (format nil \"~a{{planet}} => |planet|~a\" text text))"}},"template":"{{= | | =}}<|#lambda|-|/lambda|>","expected":"<-{{planet}} => Earth->"},{"name":"Section - Multiple Calls","desc":"Lambdas used for sections should not be cached.","data":{"lambda":{"ruby":"proc { |text| \"__#{text}__\" }","perl":"sub { \"__\" . $_[0] . \"__\" }","js":"function(txt) { return \"__\" + txt + \"__\" }","php":"return \"__\" . $text . \"__\";","python":"lambda text: \"__%s__\" % (text)","clojure":"(fn [text] (str \"__\" text \"__\"))","lisp":"(lambda (text) (format nil \"__~a__\" text))"}},"template":"{{#lambda}}FILE{{/lambda}} != {{#lambda}}LINE{{/lambda}}","expected":"__FILE__ != __LINE__"},{"name":"Inverted Section","desc":"Lambdas used for inverted sections should be considered truthy.","data":{"static":"static","lambda":{"ruby":"proc { |text| false }","perl":"sub { 0 }","js":"function(txt) { return false }","php":"return false;","python":"lambda text: 0","clojure":"(fn [text] false)","lisp":"(lambda (text) (declare (ignore text)) nil)"}},"template":"<{{^lambda}}{{static}}{{/lambda}}>","expected":"<>"}]} \ No newline at end of file
+{"__ATTN__":"Do not edit this file; changes belong in the appropriate YAML file.","overview":"Lambdas are a special-cased data type for use in interpolations and\nsections.\n\nWhen used as the data value for an Interpolation tag, the lambda MUST be\ntreatable as an arity 0 function, and invoked as such. The returned value\nMUST be rendered against the default delimiters, then interpolated in place\nof the lambda.\n\nWhen used as the data value for a Section tag, the lambda MUST be treatable\nas an arity 1 function, and invoked as such (passing a String containing the\nunprocessed section contents). The returned value MUST be rendered against\nthe current delimiters, then interpolated in place of the section.\n","tests":[{"name":"Interpolation","desc":"A lambda's return value should be interpolated.","data":{"lambda":{"ruby":"proc { \"world\" }","raku":"sub { \"world\" }","perl":"sub { \"world\" }","js":"function() { return \"world\" }","php":"return \"world\";","python":"lambda: \"world\"","clojure":"(fn [] \"world\")","lisp":"(lambda () \"world\")"}},"template":"Hello, {{lambda}}!","expected":"Hello, world!"},{"name":"Interpolation - Expansion","desc":"A lambda's return value should be parsed.","data":{"planet":"world","lambda":{"ruby":"proc { \"{{planet}}\" }","raku":"sub { q+{{planet}}+ }","perl":"sub { \"{{planet}}\" }","js":"function() { return \"{{planet}}\" }","php":"return \"{{planet}}\";","python":"lambda: \"{{planet}}\"","clojure":"(fn [] \"{{planet}}\")","lisp":"(lambda () \"{{planet}}\")"}},"template":"Hello, {{lambda}}!","expected":"Hello, world!"},{"name":"Interpolation - Alternate Delimiters","desc":"A lambda's return value should parse with the default delimiters.","data":{"planet":"world","lambda":{"ruby":"proc { \"|planet| => {{planet}}\" }","raku":"sub { q+|planet| => {{planet}}+ }","perl":"sub { \"|planet| => {{planet}}\" }","js":"function() { return \"|planet| => {{planet}}\" }","php":"return \"|planet| => {{planet}}\";","python":"lambda: \"|planet| => {{planet}}\"","clojure":"(fn [] \"|planet| => {{planet}}\")","lisp":"(lambda () \"|planet| => {{planet}}\")"}},"template":"{{= | | =}}\nHello, (|&lambda|)!","expected":"Hello, (|planet| => world)!"},{"name":"Interpolation - Multiple Calls","desc":"Interpolated lambdas should not be cached.","data":{"lambda":{"ruby":"proc { $calls ||= 0; $calls += 1 }","raku":"sub { state $calls += 1 }","perl":"sub { no strict; $calls += 1 }","js":"function() { return (g=(function(){return this})()).calls=(g.calls||0)+1 }","php":"global $calls; return ++$calls;","python":"lambda: globals().update(calls=globals().get(\"calls\",0)+1) or calls","clojure":"(def g (atom 0)) (fn [] (swap! g inc))","lisp":"(let ((g 0)) (lambda () (incf g)))"}},"template":"{{lambda}} == {{{lambda}}} == {{lambda}}","expected":"1 == 2 == 3"},{"name":"Escaping","desc":"Lambda results should be appropriately escaped.","data":{"lambda":{"ruby":"proc { \">\" }","raku":"sub { \">\" }","perl":"sub { \">\" }","js":"function() { return \">\" }","php":"return \">\";","python":"lambda: \">\"","clojure":"(fn [] \">\")","lisp":"(lambda () \">\")"}},"template":"<{{lambda}}{{{lambda}}}","expected":"<&gt;>"},{"name":"Section","desc":"Lambdas used for sections should receive the raw section string.","data":{"x":"Error!","lambda":{"ruby":"proc { |text| text == \"{{x}}\" ? \"yes\" : \"no\" }","raku":"sub { $^section eq q+{{x}}+ ?? \"yes\" !! \"no\" }","perl":"sub { $_[0] eq \"{{x}}\" ? \"yes\" : \"no\" }","js":"function(txt) { return (txt == \"{{x}}\" ? \"yes\" : \"no\") }","php":"return ($text == \"{{x}}\") ? \"yes\" : \"no\";","python":"lambda text: text == \"{{x}}\" and \"yes\" or \"no\"","clojure":"(fn [text] (if (= text \"{{x}}\") \"yes\" \"no\"))","lisp":"(lambda (text) (if (string= text \"{{x}}\") \"yes\" \"no\"))"}},"template":"<{{#lambda}}{{x}}{{/lambda}}>","expected":"<yes>"},{"name":"Section - Expansion","desc":"Lambdas used for sections should have their results parsed.","data":{"planet":"Earth","lambda":{"ruby":"proc { |text| \"#{text}{{planet}}#{text}\" }","raku":"sub { $^section ~ q+{{planet}}+ ~ $^section }","perl":"sub { $_[0] . \"{{planet}}\" . $_[0] }","js":"function(txt) { return txt + \"{{planet}}\" + txt }","php":"return $text . \"{{planet}}\" . $text;","python":"lambda text: \"%s{{planet}}%s\" % (text, text)","clojure":"(fn [text] (str text \"{{planet}}\" text))","lisp":"(lambda (text) (format nil \"~a{{planet}}~a\" text text))"}},"template":"<{{#lambda}}-{{/lambda}}>","expected":"<-Earth->"},{"name":"Section - Alternate Delimiters","desc":"Lambdas used for sections should parse with the current delimiters.","data":{"planet":"Earth","lambda":{"ruby":"proc { |text| \"#{text}{{planet}} => |planet|#{text}\" }","raku":"sub { $^section ~ q+{{planet}} => |planet|+ ~ $^section }","perl":"sub { $_[0] . \"{{planet}} => |planet|\" . $_[0] }","js":"function(txt) { return txt + \"{{planet}} => |planet|\" + txt }","php":"return $text . \"{{planet}} => |planet|\" . $text;","python":"lambda text: \"%s{{planet}} => |planet|%s\" % (text, text)","clojure":"(fn [text] (str text \"{{planet}} => |planet|\" text))","lisp":"(lambda (text) (format nil \"~a{{planet}} => |planet|~a\" text text))"}},"template":"{{= | | =}}<|#lambda|-|/lambda|>","expected":"<-{{planet}} => Earth->"},{"name":"Section - Multiple Calls","desc":"Lambdas used for sections should not be cached.","data":{"lambda":{"ruby":"proc { |text| \"__#{text}__\" }","raku":"sub { \"__\" ~ $^section ~ \"__\" }","perl":"sub { \"__\" . $_[0] . \"__\" }","js":"function(txt) { return \"__\" + txt + \"__\" }","php":"return \"__\" . $text . \"__\";","python":"lambda text: \"__%s__\" % (text)","clojure":"(fn [text] (str \"__\" text \"__\"))","lisp":"(lambda (text) (format nil \"__~a__\" text))"}},"template":"{{#lambda}}FILE{{/lambda}} != {{#lambda}}LINE{{/lambda}}","expected":"__FILE__ != __LINE__"},{"name":"Inverted Section","desc":"Lambdas used for inverted sections should be considered truthy.","data":{"static":"static","lambda":{"ruby":"proc { |text| false }","raku":"sub { 0 }","perl":"sub { 0 }","js":"function(txt) { return false }","php":"return false;","python":"lambda text: 0","clojure":"(fn [text] false)","lisp":"(lambda (text) (declare (ignore text)) nil)"}},"template":"<{{^lambda}}{{static}}{{/lambda}}>","expected":"<>"}]} \ No newline at end of file
diff --git a/specs/~lambdas.yml b/specs/~lambdas.yml
index f3f3b0b..e4eea42 100644
--- a/specs/~lambdas.yml
+++ b/specs/~lambdas.yml
@@ -17,6 +17,7 @@ tests:
data:
lambda: !code
ruby: 'proc { "world" }'
+ raku: 'sub { "world" }'
perl: 'sub { "world" }'
js: 'function() { return "world" }'
php: 'return "world";'
@@ -32,6 +33,7 @@ tests:
planet: "world"
lambda: !code
ruby: 'proc { "{{planet}}" }'
+ raku: 'sub { q+{{planet}}+ }'
perl: 'sub { "{{planet}}" }'
js: 'function() { return "{{planet}}" }'
php: 'return "{{planet}}";'
@@ -47,6 +49,7 @@ tests:
planet: "world"
lambda: !code
ruby: 'proc { "|planet| => {{planet}}" }'
+ raku: 'sub { q+|planet| => {{planet}}+ }'
perl: 'sub { "|planet| => {{planet}}" }'
js: 'function() { return "|planet| => {{planet}}" }'
php: 'return "|planet| => {{planet}}";'
@@ -61,6 +64,7 @@ tests:
data:
lambda: !code
ruby: 'proc { $calls ||= 0; $calls += 1 }'
+ raku: 'sub { state $calls += 1 }'
perl: 'sub { no strict; $calls += 1 }'
js: 'function() { return (g=(function(){return this})()).calls=(g.calls||0)+1 }'
php: 'global $calls; return ++$calls;'
@@ -75,6 +79,7 @@ tests:
data:
lambda: !code
ruby: 'proc { ">" }'
+ raku: 'sub { ">" }'
perl: 'sub { ">" }'
js: 'function() { return ">" }'
php: 'return ">";'
@@ -90,6 +95,7 @@ tests:
x: 'Error!'
lambda: !code
ruby: 'proc { |text| text == "{{x}}" ? "yes" : "no" }'
+ raku: 'sub { $^section eq q+{{x}}+ ?? "yes" !! "no" }'
perl: 'sub { $_[0] eq "{{x}}" ? "yes" : "no" }'
js: 'function(txt) { return (txt == "{{x}}" ? "yes" : "no") }'
php: 'return ($text == "{{x}}") ? "yes" : "no";'
@@ -105,6 +111,7 @@ tests:
planet: "Earth"
lambda: !code
ruby: 'proc { |text| "#{text}{{planet}}#{text}" }'
+ raku: 'sub { $^section ~ q+{{planet}}+ ~ $^section }'
perl: 'sub { $_[0] . "{{planet}}" . $_[0] }'
js: 'function(txt) { return txt + "{{planet}}" + txt }'
php: 'return $text . "{{planet}}" . $text;'
@@ -120,6 +127,7 @@ tests:
planet: "Earth"
lambda: !code
ruby: 'proc { |text| "#{text}{{planet}} => |planet|#{text}" }'
+ raku: 'sub { $^section ~ q+{{planet}} => |planet|+ ~ $^section }'
perl: 'sub { $_[0] . "{{planet}} => |planet|" . $_[0] }'
js: 'function(txt) { return txt + "{{planet}} => |planet|" + txt }'
php: 'return $text . "{{planet}} => |planet|" . $text;'
@@ -134,6 +142,7 @@ tests:
data:
lambda: !code
ruby: 'proc { |text| "__#{text}__" }'
+ raku: 'sub { "__" ~ $^section ~ "__" }'
perl: 'sub { "__" . $_[0] . "__" }'
js: 'function(txt) { return "__" + txt + "__" }'
php: 'return "__" . $text . "__";'
@@ -149,6 +158,7 @@ tests:
static: 'static'
lambda: !code
ruby: 'proc { |text| false }'
+ raku: 'sub { 0 }'
perl: 'sub { 0 }'
js: 'function(txt) { return false }'
php: 'return false;'