summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Gonggrijp <dev@juliangonggrijp.com>2021-04-19 02:17:07 +0200
committerJulian Gonggrijp <dev@juliangonggrijp.com>2021-04-19 02:17:07 +0200
commitba7c42376ac52b3d3cc1e4f9d3a52756b30112cd (patch)
tree51bd7f7eda71385381ff2a79a0cec64bd50955c4
parentab227509e64961943ca374c09c08b63f59da014a (diff)
parentb1329a25e6d265ff360267d23f7c6327bbf59f52 (diff)
downloadmustache-spec-ba7c42376ac52b3d3cc1e4f9d3a52756b30112cd.tar.gz
Merge branch 'master' into optional-inheritance-spec
-rw-r--r--LICENSE20
-rw-r--r--Rakefile12
-rw-r--r--TESTING.md51
-rw-r--r--specs/comments.json95
-rw-r--r--specs/delimiters.json133
-rw-r--r--specs/interpolation.json330
-rw-r--r--specs/inverted.json219
-rw-r--r--specs/partials.json140
-rw-r--r--specs/sections.json359
-rw-r--r--specs/sections.yml49
-rw-r--r--specs/~lambdas.json203
-rw-r--r--specs/~lambdas.yml20
12 files changed, 1590 insertions, 41 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..c6d17a3
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2021 Mustache Contributors
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/Rakefile b/Rakefile
index 5254ce6..c745f99 100644
--- a/Rakefile
+++ b/Rakefile
@@ -2,10 +2,15 @@ require 'json'
require 'yaml'
# Our custom YAML tags must retain their magic.
-%w[ code ].each do |tag|
- YAML::add_builtin_type(tag) { |_,val| val.merge(:__tag__ => tag) }
+class TaggedMap < Hash
+ yaml_tag '!code'
+ def init_with(psych_coder)
+ self.replace({:__tag__ => 'code'}.merge(psych_coder.map))
+ end
end
+YAML::add_tag('code', TaggedMap)
+
desc 'Build all alternate versions of the specs.'
multitask :build => [ 'build:json' ]
@@ -19,8 +24,9 @@ namespace :build do
json_file = filename.gsub('.yml', '.json')
File.open(json_file, 'w') do |file|
+ warning = {:__ATTN__ => note}
doc = YAML.load_file(filename)
- file << doc.merge(:__ATTN__ => note).to_json()
+ file << JSON.pretty_generate(warning.merge(doc)) << "\n"
end
end
end
diff --git a/TESTING.md b/TESTING.md
index d2ca374..0befd53 100644
--- a/TESTING.md
+++ b/TESTING.md
@@ -6,41 +6,40 @@ In general, the process for each `.yml` file is as follows:
1. Use a YAML parser to load the file.
-2. For each test in the 'tests' array:
+2. For each test in the `tests` array:
- 1. Ensure that each element of the 'partials' hash (if it exists) is
- stored in a place where the interpreter will look for it.
+ 1. Ensure that each element of the `partials` hash (if it exists) is
+ stored in a place where the interpreter will look for it.
- 2. If your implementation will not support lambdas, feel free to skip over
- the optional '~lambdas.yml' file.
+ 2. If your implementation will not support lambdas, feel free to skip
+ over the optional `~lambdas.yml` file.
- 2.1. If your implementation will support lambdas, ensure that each member of
- 'data' tagged with '!code' is properly processed into a language-
- specific lambda reference.
+ Otherwise, ensure that each member of `data` tagged with `!code` is
+ properly processed into a language-specific lambda reference.
- * e.g. Given this YAML data hash:
+ * e.g. Given this YAML data hash:
- `{ x: !code { ruby: 'proc { "x" }', perl: 'sub { "x" }' } }`
+ `{ x: !code { ruby: 'proc { "x" }', perl: 'sub { "x" }' } }`
- a Ruby-based Mustache implementation would process it such that it
- was equivalent to this Ruby hash:
+ a Ruby-based Mustache implementation would process it such that it
+ was equivalent to this Ruby hash:
- `{ 'x' => proc { "x" } }`
+ `{ 'x' => proc { "x" } }`
- * If your implementation language does not currently have lambda
- examples in the spec, feel free to implement them and send a pull
- request.
+ * If your implementation language does not currently have lambda
+ examples in the spec, feel free to implement them and send a pull
+ request.
- * The JSON version of the spec represents these tagged values as a hash
- with a '`__tag__`' key of 'code'.
+ * The JSON version of the spec represents these tagged values as a
+ hash with a `__tag__` key of `code`.
- 3. Render the template (stored in the 'template' key) with the given 'data'
- hash.
+ 3. Render the template (stored in the `template` key) with the given
+ `data` hash.
- 4. Compare the results of your rendering against the 'expected' value; any
- differences should be reported, along with any useful debugging
- information.
+ 4. Compare the results of your rendering against the `expected` value;
+ any differences should be reported, along with any useful debugging
+ information.
- * Of note, the 'desc' key contains a rough one-line description of the
- behavior being tested -- this is most useful in conjunction with the
- file name and test 'name'.
+ * Of note, the `desc` key contains a rough one-line description of
+ the behavior being tested – this is most useful in conjunction with
+ the file name and test `name`.
diff --git a/specs/comments.json b/specs/comments.json
index 30cb927..60a4929 100644
--- a/specs/comments.json
+++ b/specs/comments.json
@@ -1 +1,94 @@
-{"__ATTN__":"Do not edit this file; changes belong in the appropriate YAML file.","overview":"Comment tags represent content that should never appear in the resulting\noutput.\n\nThe tag's content may contain any substring (including newlines) EXCEPT the\nclosing delimiter.\n\nComment tags SHOULD be treated as standalone when appropriate.\n","tests":[{"name":"Inline","data":{},"expected":"1234567890","template":"12345{{! Comment Block! }}67890","desc":"Comment blocks should be removed from the template."},{"name":"Multiline","data":{},"expected":"1234567890\n","template":"12345{{!\n This is a\n multi-line comment...\n}}67890\n","desc":"Multiline comments should be permitted."},{"name":"Standalone","data":{},"expected":"Begin.\nEnd.\n","template":"Begin.\n{{! Comment Block! }}\nEnd.\n","desc":"All standalone comment lines should be removed."},{"name":"Indented Standalone","data":{},"expected":"Begin.\nEnd.\n","template":"Begin.\n {{! Indented Comment Block! }}\nEnd.\n","desc":"All standalone comment lines should be removed."},{"name":"Standalone Line Endings","data":{},"expected":"|\r\n|","template":"|\r\n{{! Standalone Comment }}\r\n|","desc":"\"\\r\\n\" should be considered a newline for standalone tags."},{"name":"Standalone Without Previous Line","data":{},"expected":"!","template":" {{! I'm Still Standalone }}\n!","desc":"Standalone tags should not require a newline to precede them."},{"name":"Standalone Without Newline","data":{},"expected":"!\n","template":"!\n {{! I'm Still Standalone }}","desc":"Standalone tags should not require a newline to follow them."},{"name":"Multiline Standalone","data":{},"expected":"Begin.\nEnd.\n","template":"Begin.\n{{!\nSomething's going on here...\n}}\nEnd.\n","desc":"All standalone comment lines should be removed."},{"name":"Indented Multiline Standalone","data":{},"expected":"Begin.\nEnd.\n","template":"Begin.\n {{!\n Something's going on here...\n }}\nEnd.\n","desc":"All standalone comment lines should be removed."},{"name":"Indented Inline","data":{},"expected":" 12 \n","template":" 12 {{! 34 }}\n","desc":"Inline comments should not strip whitespace"},{"name":"Surrounding Whitespace","data":{},"expected":"12345 67890","template":"12345 {{! Comment Block! }} 67890","desc":"Comment removal should preserve surrounding whitespace."}]} \ No newline at end of file
+{
+ "__ATTN__": "Do not edit this file; changes belong in the appropriate YAML file.",
+ "overview": "Comment tags represent content that should never appear in the resulting\noutput.\n\nThe tag's content may contain any substring (including newlines) EXCEPT the\nclosing delimiter.\n\nComment tags SHOULD be treated as standalone when appropriate.\n",
+ "tests": [
+ {
+ "name": "Inline",
+ "desc": "Comment blocks should be removed from the template.",
+ "data": {
+ },
+ "template": "12345{{! Comment Block! }}67890",
+ "expected": "1234567890"
+ },
+ {
+ "name": "Multiline",
+ "desc": "Multiline comments should be permitted.",
+ "data": {
+ },
+ "template": "12345{{!\n This is a\n multi-line comment...\n}}67890\n",
+ "expected": "1234567890\n"
+ },
+ {
+ "name": "Standalone",
+ "desc": "All standalone comment lines should be removed.",
+ "data": {
+ },
+ "template": "Begin.\n{{! Comment Block! }}\nEnd.\n",
+ "expected": "Begin.\nEnd.\n"
+ },
+ {
+ "name": "Indented Standalone",
+ "desc": "All standalone comment lines should be removed.",
+ "data": {
+ },
+ "template": "Begin.\n {{! Indented Comment Block! }}\nEnd.\n",
+ "expected": "Begin.\nEnd.\n"
+ },
+ {
+ "name": "Standalone Line Endings",
+ "desc": "\"\\r\\n\" should be considered a newline for standalone tags.",
+ "data": {
+ },
+ "template": "|\r\n{{! Standalone Comment }}\r\n|",
+ "expected": "|\r\n|"
+ },
+ {
+ "name": "Standalone Without Previous Line",
+ "desc": "Standalone tags should not require a newline to precede them.",
+ "data": {
+ },
+ "template": " {{! I'm Still Standalone }}\n!",
+ "expected": "!"
+ },
+ {
+ "name": "Standalone Without Newline",
+ "desc": "Standalone tags should not require a newline to follow them.",
+ "data": {
+ },
+ "template": "!\n {{! I'm Still Standalone }}",
+ "expected": "!\n"
+ },
+ {
+ "name": "Multiline Standalone",
+ "desc": "All standalone comment lines should be removed.",
+ "data": {
+ },
+ "template": "Begin.\n{{!\nSomething's going on here...\n}}\nEnd.\n",
+ "expected": "Begin.\nEnd.\n"
+ },
+ {
+ "name": "Indented Multiline Standalone",
+ "desc": "All standalone comment lines should be removed.",
+ "data": {
+ },
+ "template": "Begin.\n {{!\n Something's going on here...\n }}\nEnd.\n",
+ "expected": "Begin.\nEnd.\n"
+ },
+ {
+ "name": "Indented Inline",
+ "desc": "Inline comments should not strip whitespace",
+ "data": {
+ },
+ "template": " 12 {{! 34 }}\n",
+ "expected": " 12 \n"
+ },
+ {
+ "name": "Surrounding Whitespace",
+ "desc": "Comment removal should preserve surrounding whitespace.",
+ "data": {
+ },
+ "template": "12345 {{! Comment Block! }} 67890",
+ "expected": "12345 67890"
+ }
+ ]
+}
diff --git a/specs/delimiters.json b/specs/delimiters.json
index fcf9588..485e84b 100644
--- a/specs/delimiters.json
+++ b/specs/delimiters.json
@@ -1 +1,132 @@
-{"__ATTN__":"Do not edit this file; changes belong in the appropriate YAML file.","overview":"Set Delimiter tags are used to change the tag delimiters for all content\nfollowing the tag in the current compilation unit.\n\nThe tag's content MUST be any two non-whitespace sequences (separated by\nwhitespace) EXCEPT an equals sign ('=') followed by the current closing\ndelimiter.\n\nSet Delimiter tags SHOULD be treated as standalone when appropriate.\n","tests":[{"name":"Pair Behavior","data":{"text":"Hey!"},"expected":"(Hey!)","template":"{{=<% %>=}}(<%text%>)","desc":"The equals sign (used on both sides) should permit delimiter changes."},{"name":"Special Characters","data":{"text":"It worked!"},"expected":"(It worked!)","template":"({{=[ ]=}}[text])","desc":"Characters with special meaning regexen should be valid delimiters."},{"name":"Sections","data":{"section":true,"data":"I got interpolated."},"expected":"[\n I got interpolated.\n |data|\n\n {{data}}\n I got interpolated.\n]\n","template":"[\n{{#section}}\n {{data}}\n |data|\n{{/section}}\n\n{{= | | =}}\n|#section|\n {{data}}\n |data|\n|/section|\n]\n","desc":"Delimiters set outside sections should persist."},{"name":"Inverted Sections","data":{"section":false,"data":"I got interpolated."},"expected":"[\n I got interpolated.\n |data|\n\n {{data}}\n I got interpolated.\n]\n","template":"[\n{{^section}}\n {{data}}\n |data|\n{{/section}}\n\n{{= | | =}}\n|^section|\n {{data}}\n |data|\n|/section|\n]\n","desc":"Delimiters set outside inverted sections should persist."},{"name":"Partial Inheritence","data":{"value":"yes"},"expected":"[ .yes. ]\n[ .yes. ]\n","template":"[ {{>include}} ]\n{{= | | =}}\n[ |>include| ]\n","desc":"Delimiters set in a parent template should not affect a partial.","partials":{"include":".{{value}}."}},{"name":"Post-Partial Behavior","data":{"value":"yes"},"expected":"[ .yes. .yes. ]\n[ .yes. .|value|. ]\n","template":"[ {{>include}} ]\n[ .{{value}}. .|value|. ]\n","desc":"Delimiters set in a partial should not affect the parent template.","partials":{"include":".{{value}}. {{= | | =}} .|value|."}},{"name":"Surrounding Whitespace","data":{},"expected":"| |","template":"| {{=@ @=}} |","desc":"Surrounding whitespace should be left untouched."},{"name":"Outlying Whitespace (Inline)","data":{},"expected":" | \n","template":" | {{=@ @=}}\n","desc":"Whitespace should be left untouched."},{"name":"Standalone Tag","data":{},"expected":"Begin.\nEnd.\n","template":"Begin.\n{{=@ @=}}\nEnd.\n","desc":"Standalone lines should be removed from the template."},{"name":"Indented Standalone Tag","data":{},"expected":"Begin.\nEnd.\n","template":"Begin.\n {{=@ @=}}\nEnd.\n","desc":"Indented standalone lines should be removed from the template."},{"name":"Standalone Line Endings","data":{},"expected":"|\r\n|","template":"|\r\n{{= @ @ =}}\r\n|","desc":"\"\\r\\n\" should be considered a newline for standalone tags."},{"name":"Standalone Without Previous Line","data":{},"expected":"=","template":" {{=@ @=}}\n=","desc":"Standalone tags should not require a newline to precede them."},{"name":"Standalone Without Newline","data":{},"expected":"=\n","template":"=\n {{=@ @=}}","desc":"Standalone tags should not require a newline to follow them."},{"name":"Pair with Padding","data":{},"expected":"||","template":"|{{= @ @ =}}|","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.",
+ "overview": "Set Delimiter tags are used to change the tag delimiters for all content\nfollowing the tag in the current compilation unit.\n\nThe tag's content MUST be any two non-whitespace sequences (separated by\nwhitespace) EXCEPT an equals sign ('=') followed by the current closing\ndelimiter.\n\nSet Delimiter tags SHOULD be treated as standalone when appropriate.\n",
+ "tests": [
+ {
+ "name": "Pair Behavior",
+ "desc": "The equals sign (used on both sides) should permit delimiter changes.",
+ "data": {
+ "text": "Hey!"
+ },
+ "template": "{{=<% %>=}}(<%text%>)",
+ "expected": "(Hey!)"
+ },
+ {
+ "name": "Special Characters",
+ "desc": "Characters with special meaning regexen should be valid delimiters.",
+ "data": {
+ "text": "It worked!"
+ },
+ "template": "({{=[ ]=}}[text])",
+ "expected": "(It worked!)"
+ },
+ {
+ "name": "Sections",
+ "desc": "Delimiters set outside sections should persist.",
+ "data": {
+ "section": true,
+ "data": "I got interpolated."
+ },
+ "template": "[\n{{#section}}\n {{data}}\n |data|\n{{/section}}\n\n{{= | | =}}\n|#section|\n {{data}}\n |data|\n|/section|\n]\n",
+ "expected": "[\n I got interpolated.\n |data|\n\n {{data}}\n I got interpolated.\n]\n"
+ },
+ {
+ "name": "Inverted Sections",
+ "desc": "Delimiters set outside inverted sections should persist.",
+ "data": {
+ "section": false,
+ "data": "I got interpolated."
+ },
+ "template": "[\n{{^section}}\n {{data}}\n |data|\n{{/section}}\n\n{{= | | =}}\n|^section|\n {{data}}\n |data|\n|/section|\n]\n",
+ "expected": "[\n I got interpolated.\n |data|\n\n {{data}}\n I got interpolated.\n]\n"
+ },
+ {
+ "name": "Partial Inheritence",
+ "desc": "Delimiters set in a parent template should not affect a partial.",
+ "data": {
+ "value": "yes"
+ },
+ "partials": {
+ "include": ".{{value}}."
+ },
+ "template": "[ {{>include}} ]\n{{= | | =}}\n[ |>include| ]\n",
+ "expected": "[ .yes. ]\n[ .yes. ]\n"
+ },
+ {
+ "name": "Post-Partial Behavior",
+ "desc": "Delimiters set in a partial should not affect the parent template.",
+ "data": {
+ "value": "yes"
+ },
+ "partials": {
+ "include": ".{{value}}. {{= | | =}} .|value|."
+ },
+ "template": "[ {{>include}} ]\n[ .{{value}}. .|value|. ]\n",
+ "expected": "[ .yes. .yes. ]\n[ .yes. .|value|. ]\n"
+ },
+ {
+ "name": "Surrounding Whitespace",
+ "desc": "Surrounding whitespace should be left untouched.",
+ "data": {
+ },
+ "template": "| {{=@ @=}} |",
+ "expected": "| |"
+ },
+ {
+ "name": "Outlying Whitespace (Inline)",
+ "desc": "Whitespace should be left untouched.",
+ "data": {
+ },
+ "template": " | {{=@ @=}}\n",
+ "expected": " | \n"
+ },
+ {
+ "name": "Standalone Tag",
+ "desc": "Standalone lines should be removed from the template.",
+ "data": {
+ },
+ "template": "Begin.\n{{=@ @=}}\nEnd.\n",
+ "expected": "Begin.\nEnd.\n"
+ },
+ {
+ "name": "Indented Standalone Tag",
+ "desc": "Indented standalone lines should be removed from the template.",
+ "data": {
+ },
+ "template": "Begin.\n {{=@ @=}}\nEnd.\n",
+ "expected": "Begin.\nEnd.\n"
+ },
+ {
+ "name": "Standalone Line Endings",
+ "desc": "\"\\r\\n\" should be considered a newline for standalone tags.",
+ "data": {
+ },
+ "template": "|\r\n{{= @ @ =}}\r\n|",
+ "expected": "|\r\n|"
+ },
+ {
+ "name": "Standalone Without Previous Line",
+ "desc": "Standalone tags should not require a newline to precede them.",
+ "data": {
+ },
+ "template": " {{=@ @=}}\n=",
+ "expected": "="
+ },
+ {
+ "name": "Standalone Without Newline",
+ "desc": "Standalone tags should not require a newline to follow them.",
+ "data": {
+ },
+ "template": "=\n {{=@ @=}}",
+ "expected": "=\n"
+ },
+ {
+ "name": "Pair with Padding",
+ "desc": "Superfluous in-tag whitespace should be ignored.",
+ "data": {
+ },
+ "template": "|{{= @ @ =}}|",
+ "expected": "||"
+ }
+ ]
+}
diff --git a/specs/interpolation.json b/specs/interpolation.json
index d1a1a32..1718e1c 100644
--- a/specs/interpolation.json
+++ b/specs/interpolation.json
@@ -1 +1,329 @@
-{"__ATTN__":"Do not edit this file; changes belong in the appropriate YAML file.","overview":"Interpolation tags are used to integrate dynamic content into the template.\n\nThe tag's content MUST be a non-whitespace character sequence NOT containing\nthe current closing delimiter.\n\nThis tag's content names the data to replace the tag. A single period (`.`)\nindicates that the item currently sitting atop the context stack should be\nused; otherwise, name resolution is as follows:\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, the data is the value returned by the\n method with the given name.\n 5) 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.\nData should be coerced into a string (and escaped, if appropriate) before\ninterpolation.\n\nThe Interpolation tags MUST NOT be treated as standalone.\n","tests":[{"name":"No Interpolation","data":{},"expected":"Hello from {Mustache}!\n","template":"Hello from {Mustache}!\n","desc":"Mustache-free templates should render as-is."},{"name":"Basic Interpolation","data":{"subject":"world"},"expected":"Hello, world!\n","template":"Hello, {{subject}}!\n","desc":"Unadorned tags should interpolate content into the template."},{"name":"HTML Escaping","data":{"forbidden":"& \" < >"},"expected":"These characters should be HTML escaped: &amp; &quot; &lt; &gt;\n","template":"These characters should be HTML escaped: {{forbidden}}\n","desc":"Basic interpolation should be HTML escaped."},{"name":"Triple Mustache","data":{"forbidden":"& \" < >"},"expected":"These characters should not be HTML escaped: & \" < >\n","template":"These characters should not be HTML escaped: {{{forbidden}}}\n","desc":"Triple mustaches should interpolate without HTML escaping."},{"name":"Ampersand","data":{"forbidden":"& \" < >"},"expected":"These characters should not be HTML escaped: & \" < >\n","template":"These characters should not be HTML escaped: {{&forbidden}}\n","desc":"Ampersand should interpolate without HTML escaping."},{"name":"Basic Integer Interpolation","data":{"mph":85},"expected":"\"85 miles an hour!\"","template":"\"{{mph}} miles an hour!\"","desc":"Integers should interpolate seamlessly."},{"name":"Triple Mustache Integer Interpolation","data":{"mph":85},"expected":"\"85 miles an hour!\"","template":"\"{{{mph}}} miles an hour!\"","desc":"Integers should interpolate seamlessly."},{"name":"Ampersand Integer Interpolation","data":{"mph":85},"expected":"\"85 miles an hour!\"","template":"\"{{&mph}} miles an hour!\"","desc":"Integers should interpolate seamlessly."},{"name":"Basic Decimal Interpolation","data":{"power":1.21},"expected":"\"1.21 jiggawatts!\"","template":"\"{{power}} jiggawatts!\"","desc":"Decimals should interpolate seamlessly with proper significance."},{"name":"Triple Mustache Decimal Interpolation","data":{"power":1.21},"expected":"\"1.21 jiggawatts!\"","template":"\"{{{power}}} jiggawatts!\"","desc":"Decimals should interpolate seamlessly with proper significance."},{"name":"Ampersand Decimal Interpolation","data":{"power":1.21},"expected":"\"1.21 jiggawatts!\"","template":"\"{{&power}} jiggawatts!\"","desc":"Decimals should interpolate seamlessly with proper significance."},{"name":"Basic Context Miss Interpolation","data":{},"expected":"I () be seen!","template":"I ({{cannot}}) be seen!","desc":"Failed context lookups should default to empty strings."},{"name":"Triple Mustache Context Miss Interpolation","data":{},"expected":"I () be seen!","template":"I ({{{cannot}}}) be seen!","desc":"Failed context lookups should default to empty strings."},{"name":"Ampersand Context Miss Interpolation","data":{},"expected":"I () be seen!","template":"I ({{&cannot}}) be seen!","desc":"Failed context lookups should default to empty strings."},{"name":"Dotted Names - Basic Interpolation","data":{"person":{"name":"Joe"}},"expected":"\"Joe\" == \"Joe\"","template":"\"{{person.name}}\" == \"{{#person}}{{name}}{{/person}}\"","desc":"Dotted names should be considered a form of shorthand for sections."},{"name":"Dotted Names - Triple Mustache Interpolation","data":{"person":{"name":"Joe"}},"expected":"\"Joe\" == \"Joe\"","template":"\"{{{person.name}}}\" == \"{{#person}}{{{name}}}{{/person}}\"","desc":"Dotted names should be considered a form of shorthand for sections."},{"name":"Dotted Names - Ampersand Interpolation","data":{"person":{"name":"Joe"}},"expected":"\"Joe\" == \"Joe\"","template":"\"{{&person.name}}\" == \"{{#person}}{{&name}}{{/person}}\"","desc":"Dotted names should be considered a form of shorthand for sections."},{"name":"Dotted Names - Arbitrary Depth","data":{"a":{"b":{"c":{"d":{"e":{"name":"Phil"}}}}}},"expected":"\"Phil\" == \"Phil\"","template":"\"{{a.b.c.d.e.name}}\" == \"Phil\"","desc":"Dotted names should be functional to any level of nesting."},{"name":"Dotted Names - Broken Chains","data":{"a":{}},"expected":"\"\" == \"\"","template":"\"{{a.b.c}}\" == \"\"","desc":"Any falsey value prior to the last part of the name should yield ''."},{"name":"Dotted Names - Broken Chain Resolution","data":{"a":{"b":{}},"c":{"name":"Jim"}},"expected":"\"\" == \"\"","template":"\"{{a.b.c.name}}\" == \"\"","desc":"Each part of a dotted name should resolve only against its parent."},{"name":"Dotted Names - Initial Resolution","data":{"a":{"b":{"c":{"d":{"e":{"name":"Phil"}}}}},"b":{"c":{"d":{"e":{"name":"Wrong"}}}}},"expected":"\"Phil\" == \"Phil\"","template":"\"{{#a}}{{b.c.d.e.name}}{{/a}}\" == \"Phil\"","desc":"The first part of a dotted name should resolve as any other name."},{"name":"Interpolation - Surrounding Whitespace","data":{"string":"---"},"expected":"| --- |","template":"| {{string}} |","desc":"Interpolation should not alter surrounding whitespace."},{"name":"Triple Mustache - Surrounding Whitespace","data":{"string":"---"},"expected":"| --- |","template":"| {{{string}}} |","desc":"Interpolation should not alter surrounding whitespace."},{"name":"Ampersand - Surrounding Whitespace","data":{"string":"---"},"expected":"| --- |","template":"| {{&string}} |","desc":"Interpolation should not alter surrounding whitespace."},{"name":"Interpolation - Standalone","data":{"string":"---"},"expected":" ---\n","template":" {{string}}\n","desc":"Standalone interpolation should not alter surrounding whitespace."},{"name":"Triple Mustache - Standalone","data":{"string":"---"},"expected":" ---\n","template":" {{{string}}}\n","desc":"Standalone interpolation should not alter surrounding whitespace."},{"name":"Ampersand - Standalone","data":{"string":"---"},"expected":" ---\n","template":" {{&string}}\n","desc":"Standalone interpolation should not alter surrounding whitespace."},{"name":"Interpolation With Padding","data":{"string":"---"},"expected":"|---|","template":"|{{ string }}|","desc":"Superfluous in-tag whitespace should be ignored."},{"name":"Triple Mustache With Padding","data":{"string":"---"},"expected":"|---|","template":"|{{{ string }}}|","desc":"Superfluous in-tag whitespace should be ignored."},{"name":"Ampersand With Padding","data":{"string":"---"},"expected":"|---|","template":"|{{& string }}|","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.",
+ "overview": "Interpolation tags are used to integrate dynamic content into the template.\n\nThe tag's content MUST be a non-whitespace character sequence NOT containing\nthe current closing delimiter.\n\nThis tag's content names the data to replace the tag. A single period (`.`)\nindicates that the item currently sitting atop the context stack should be\nused; otherwise, name resolution is as follows:\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, the data is the value returned by the\n method with the given name.\n 5) 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.\nData should be coerced into a string (and escaped, if appropriate) before\ninterpolation.\n\nThe Interpolation tags MUST NOT be treated as standalone.\n",
+ "tests": [
+ {
+ "name": "No Interpolation",
+ "desc": "Mustache-free templates should render as-is.",
+ "data": {
+ },
+ "template": "Hello from {Mustache}!\n",
+ "expected": "Hello from {Mustache}!\n"
+ },
+ {
+ "name": "Basic Interpolation",
+ "desc": "Unadorned tags should interpolate content into the template.",
+ "data": {
+ "subject": "world"
+ },
+ "template": "Hello, {{subject}}!\n",
+ "expected": "Hello, world!\n"
+ },
+ {
+ "name": "HTML Escaping",
+ "desc": "Basic interpolation should be HTML escaped.",
+ "data": {
+ "forbidden": "& \" < >"
+ },
+ "template": "These characters should be HTML escaped: {{forbidden}}\n",
+ "expected": "These characters should be HTML escaped: &amp; &quot; &lt; &gt;\n"
+ },
+ {
+ "name": "Triple Mustache",
+ "desc": "Triple mustaches should interpolate without HTML escaping.",
+ "data": {
+ "forbidden": "& \" < >"
+ },
+ "template": "These characters should not be HTML escaped: {{{forbidden}}}\n",
+ "expected": "These characters should not be HTML escaped: & \" < >\n"
+ },
+ {
+ "name": "Ampersand",
+ "desc": "Ampersand should interpolate without HTML escaping.",
+ "data": {
+ "forbidden": "& \" < >"
+ },
+ "template": "These characters should not be HTML escaped: {{&forbidden}}\n",
+ "expected": "These characters should not be HTML escaped: & \" < >\n"
+ },
+ {
+ "name": "Basic Integer Interpolation",
+ "desc": "Integers should interpolate seamlessly.",
+ "data": {
+ "mph": 85
+ },
+ "template": "\"{{mph}} miles an hour!\"",
+ "expected": "\"85 miles an hour!\""
+ },
+ {
+ "name": "Triple Mustache Integer Interpolation",
+ "desc": "Integers should interpolate seamlessly.",
+ "data": {
+ "mph": 85
+ },
+ "template": "\"{{{mph}}} miles an hour!\"",
+ "expected": "\"85 miles an hour!\""
+ },
+ {
+ "name": "Ampersand Integer Interpolation",
+ "desc": "Integers should interpolate seamlessly.",
+ "data": {
+ "mph": 85
+ },
+ "template": "\"{{&mph}} miles an hour!\"",
+ "expected": "\"85 miles an hour!\""
+ },
+ {
+ "name": "Basic Decimal Interpolation",
+ "desc": "Decimals should interpolate seamlessly with proper significance.",
+ "data": {
+ "power": 1.21
+ },
+ "template": "\"{{power}} jiggawatts!\"",
+ "expected": "\"1.21 jiggawatts!\""
+ },
+ {
+ "name": "Triple Mustache Decimal Interpolation",
+ "desc": "Decimals should interpolate seamlessly with proper significance.",
+ "data": {
+ "power": 1.21
+ },
+ "template": "\"{{{power}}} jiggawatts!\"",
+ "expected": "\"1.21 jiggawatts!\""
+ },
+ {
+ "name": "Ampersand Decimal Interpolation",
+ "desc": "Decimals should interpolate seamlessly with proper significance.",
+ "data": {
+ "power": 1.21
+ },
+ "template": "\"{{&power}} jiggawatts!\"",
+ "expected": "\"1.21 jiggawatts!\""
+ },
+ {
+ "name": "Basic Context Miss Interpolation",
+ "desc": "Failed context lookups should default to empty strings.",
+ "data": {
+ },
+ "template": "I ({{cannot}}) be seen!",
+ "expected": "I () be seen!"
+ },
+ {
+ "name": "Triple Mustache Context Miss Interpolation",
+ "desc": "Failed context lookups should default to empty strings.",
+ "data": {
+ },
+ "template": "I ({{{cannot}}}) be seen!",
+ "expected": "I () be seen!"
+ },
+ {
+ "name": "Ampersand Context Miss Interpolation",
+ "desc": "Failed context lookups should default to empty strings.",
+ "data": {
+ },
+ "template": "I ({{&cannot}}) be seen!",
+ "expected": "I () be seen!"
+ },
+ {
+ "name": "Dotted Names - Basic Interpolation",
+ "desc": "Dotted names should be considered a form of shorthand for sections.",
+ "data": {
+ "person": {
+ "name": "Joe"
+ }
+ },
+ "template": "\"{{person.name}}\" == \"{{#person}}{{name}}{{/person}}\"",
+ "expected": "\"Joe\" == \"Joe\""
+ },
+ {
+ "name": "Dotted Names - Triple Mustache Interpolation",
+ "desc": "Dotted names should be considered a form of shorthand for sections.",
+ "data": {
+ "person": {
+ "name": "Joe"
+ }
+ },
+ "template": "\"{{{person.name}}}\" == \"{{#person}}{{{name}}}{{/person}}\"",
+ "expected": "\"Joe\" == \"Joe\""
+ },
+ {
+ "name": "Dotted Names - Ampersand Interpolation",
+ "desc": "Dotted names should be considered a form of shorthand for sections.",
+ "data": {
+ "person": {
+ "name": "Joe"
+ }
+ },
+ "template": "\"{{&person.name}}\" == \"{{#person}}{{&name}}{{/person}}\"",
+ "expected": "\"Joe\" == \"Joe\""
+ },
+ {
+ "name": "Dotted Names - Arbitrary Depth",
+ "desc": "Dotted names should be functional to any level of nesting.",
+ "data": {
+ "a": {
+ "b": {
+ "c": {
+ "d": {
+ "e": {
+ "name": "Phil"
+ }
+ }
+ }
+ }
+ }
+ },
+ "template": "\"{{a.b.c.d.e.name}}\" == \"Phil\"",
+ "expected": "\"Phil\" == \"Phil\""
+ },
+ {
+ "name": "Dotted Names - Broken Chains",
+ "desc": "Any falsey value prior to the last part of the name should yield ''.",
+ "data": {
+ "a": {
+ }
+ },
+ "template": "\"{{a.b.c}}\" == \"\"",
+ "expected": "\"\" == \"\""
+ },
+ {
+ "name": "Dotted Names - Broken Chain Resolution",
+ "desc": "Each part of a dotted name should resolve only against its parent.",
+ "data": {
+ "a": {
+ "b": {
+ }
+ },
+ "c": {
+ "name": "Jim"
+ }
+ },
+ "template": "\"{{a.b.c.name}}\" == \"\"",
+ "expected": "\"\" == \"\""
+ },
+ {
+ "name": "Dotted Names - Initial Resolution",
+ "desc": "The first part of a dotted name should resolve as any other name.",
+ "data": {
+ "a": {
+ "b": {
+ "c": {
+ "d": {
+ "e": {
+ "name": "Phil"
+ }
+ }
+ }
+ }
+ },
+ "b": {
+ "c": {
+ "d": {
+ "e": {
+ "name": "Wrong"
+ }
+ }
+ }
+ }
+ },
+ "template": "\"{{#a}}{{b.c.d.e.name}}{{/a}}\" == \"Phil\"",
+ "expected": "\"Phil\" == \"Phil\""
+ },
+ {
+ "name": "Dotted Names - Context Precedence",
+ "desc": "Dotted names should be resolved against former resolutions.",
+ "data": {
+ "a": {
+ "b": {
+ }
+ },
+ "b": {
+ "c": "ERROR"
+ }
+ },
+ "template": "{{#a}}{{b.c}}{{/a}}",
+ "expected": ""
+ },
+ {
+ "name": "Interpolation - Surrounding Whitespace",
+ "desc": "Interpolation should not alter surrounding whitespace.",
+ "data": {
+ "string": "---"
+ },
+ "template": "| {{string}} |",
+ "expected": "| --- |"
+ },
+ {
+ "name": "Triple Mustache - Surrounding Whitespace",
+ "desc": "Interpolation should not alter surrounding whitespace.",
+ "data": {
+ "string": "---"
+ },
+ "template": "| {{{string}}} |",
+ "expected": "| --- |"
+ },
+ {
+ "name": "Ampersand - Surrounding Whitespace",
+ "desc": "Interpolation should not alter surrounding whitespace.",
+ "data": {
+ "string": "---"
+ },
+ "template": "| {{&string}} |",
+ "expected": "| --- |"
+ },
+ {
+ "name": "Interpolation - Standalone",
+ "desc": "Standalone interpolation should not alter surrounding whitespace.",
+ "data": {
+ "string": "---"
+ },
+ "template": " {{string}}\n",
+ "expected": " ---\n"
+ },
+ {
+ "name": "Triple Mustache - Standalone",
+ "desc": "Standalone interpolation should not alter surrounding whitespace.",
+ "data": {
+ "string": "---"
+ },
+ "template": " {{{string}}}\n",
+ "expected": " ---\n"
+ },
+ {
+ "name": "Ampersand - Standalone",
+ "desc": "Standalone interpolation should not alter surrounding whitespace.",
+ "data": {
+ "string": "---"
+ },
+ "template": " {{&string}}\n",
+ "expected": " ---\n"
+ },
+ {
+ "name": "Interpolation With Padding",
+ "desc": "Superfluous in-tag whitespace should be ignored.",
+ "data": {
+ "string": "---"
+ },
+ "template": "|{{ string }}|",
+ "expected": "|---|"
+ },
+ {
+ "name": "Triple Mustache With Padding",
+ "desc": "Superfluous in-tag whitespace should be ignored.",
+ "data": {
+ "string": "---"
+ },
+ "template": "|{{{ string }}}|",
+ "expected": "|---|"
+ },
+ {
+ "name": "Ampersand With Padding",
+ "desc": "Superfluous in-tag whitespace should be ignored.",
+ "data": {
+ "string": "---"
+ },
+ "template": "|{{& string }}|",
+ "expected": "|---|"
+ }
+ ]
+}
diff --git a/specs/inverted.json b/specs/inverted.json
index c9b550b..d9a7c15 100644
--- a/specs/inverted.json
+++ b/specs/inverted.json
@@ -1 +1,218 @@
-{"__ATTN__":"Do not edit this file; changes belong in the appropriate YAML file.","overview":"Inverted Section tags and End Section tags are used in combination to wrap a\nsection of the template.\n\nThese tags' content MUST be a non-whitespace character sequence NOT\ncontaining the current closing delimiter; each Inverted Section tag MUST be\nfollowed by an End Section tag with the same content within the same\nsection.\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\nThis section MUST NOT be rendered unless the data list is empty.\n\nInverted Section and End Section tags SHOULD be treated as standalone when\nappropriate.\n","tests":[{"name":"Falsey","data":{"boolean":false},"expected":"\"This should be rendered.\"","template":"\"{{^boolean}}This should be rendered.{{/boolean}}\"","desc":"Falsey sections should have their contents rendered."},{"name":"Truthy","data":{"boolean":true},"expected":"\"\"","template":"\"{{^boolean}}This should not be rendered.{{/boolean}}\"","desc":"Truthy sections should have their contents omitted."},{"name":"Context","data":{"context":{"name":"Joe"}},"expected":"\"\"","template":"\"{{^context}}Hi {{name}}.{{/context}}\"","desc":"Objects and hashes should behave like truthy values."},{"name":"List","data":{"list":[{"n":1},{"n":2},{"n":3}]},"expected":"\"\"","template":"\"{{^list}}{{n}}{{/list}}\"","desc":"Lists should behave like truthy values."},{"name":"Empty List","data":{"list":[]},"expected":"\"Yay lists!\"","template":"\"{{^list}}Yay lists!{{/list}}\"","desc":"Empty lists should behave like falsey values."},{"name":"Doubled","data":{"two":"second","bool":false},"expected":"* first\n* second\n* third\n","template":"{{^bool}}\n* first\n{{/bool}}\n* {{two}}\n{{^bool}}\n* third\n{{/bool}}\n","desc":"Multiple inverted sections per template should be permitted."},{"name":"Nested (Falsey)","data":{"bool":false},"expected":"| A B C D E |","template":"| A {{^bool}}B {{^bool}}C{{/bool}} D{{/bool}} E |","desc":"Nested falsey sections should have their contents rendered."},{"name":"Nested (Truthy)","data":{"bool":true},"expected":"| A E |","template":"| A {{^bool}}B {{^bool}}C{{/bool}} D{{/bool}} E |","desc":"Nested truthy sections should be omitted."},{"name":"Context Misses","data":{},"expected":"[Cannot find key 'missing'!]","template":"[{{^missing}}Cannot find key 'missing'!{{/missing}}]","desc":"Failed context lookups should be considered falsey."},{"name":"Dotted Names - Truthy","data":{"a":{"b":{"c":true}}},"expected":"\"\" == \"\"","template":"\"{{^a.b.c}}Not Here{{/a.b.c}}\" == \"\"","desc":"Dotted names should be valid for Inverted Section tags."},{"name":"Dotted Names - Falsey","data":{"a":{"b":{"c":false}}},"expected":"\"Not Here\" == \"Not Here\"","template":"\"{{^a.b.c}}Not Here{{/a.b.c}}\" == \"Not Here\"","desc":"Dotted names should be valid for Inverted Section tags."},{"name":"Dotted Names - Broken Chains","data":{"a":{}},"expected":"\"Not Here\" == \"Not Here\"","template":"\"{{^a.b.c}}Not Here{{/a.b.c}}\" == \"Not Here\"","desc":"Dotted names that cannot be resolved should be considered falsey."},{"name":"Surrounding Whitespace","data":{"boolean":false},"expected":" | \t|\t | \n","template":" | {{^boolean}}\t|\t{{/boolean}} | \n","desc":"Inverted sections should not alter surrounding whitespace."},{"name":"Internal Whitespace","data":{"boolean":false},"expected":" | \n | \n","template":" | {{^boolean}} {{! Important Whitespace }}\n {{/boolean}} | \n","desc":"Inverted should not alter internal whitespace."},{"name":"Indented Inline Sections","data":{"boolean":false},"expected":" NO\n WAY\n","template":" {{^boolean}}NO{{/boolean}}\n {{^boolean}}WAY{{/boolean}}\n","desc":"Single-line sections should not alter surrounding whitespace."},{"name":"Standalone Lines","data":{"boolean":false},"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":"Standalone Indented Lines","data":{"boolean":false},"expected":"| This Is\n|\n| A Line\n","template":"| This Is\n {{^boolean}}\n|\n {{/boolean}}\n| A Line\n","desc":"Standalone indented lines should be removed from the template."},{"name":"Standalone Line Endings","data":{"boolean":false},"expected":"|\r\n|","template":"|\r\n{{^boolean}}\r\n{{/boolean}}\r\n|","desc":"\"\\r\\n\" should be considered a newline for standalone tags."},{"name":"Standalone Without Previous Line","data":{"boolean":false},"expected":"^\n/","template":" {{^boolean}}\n^{{/boolean}}\n/","desc":"Standalone tags should not require a newline to precede them."},{"name":"Standalone Without Newline","data":{"boolean":false},"expected":"^\n/\n","template":"^{{^boolean}}\n/\n {{/boolean}}","desc":"Standalone tags should not require a newline to follow them."},{"name":"Padding","data":{"boolean":false},"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.",
+ "overview": "Inverted Section tags and End Section tags are used in combination to wrap a\nsection of the template.\n\nThese tags' content MUST be a non-whitespace character sequence NOT\ncontaining the current closing delimiter; each Inverted Section tag MUST be\nfollowed by an End Section tag with the same content within the same\nsection.\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\nThis section MUST NOT be rendered unless the data list is empty.\n\nInverted Section and End Section tags SHOULD be treated as standalone when\nappropriate.\n",
+ "tests": [
+ {
+ "name": "Falsey",
+ "desc": "Falsey sections should have their contents rendered.",
+ "data": {
+ "boolean": false
+ },
+ "template": "\"{{^boolean}}This should be rendered.{{/boolean}}\"",
+ "expected": "\"This should be rendered.\""
+ },
+ {
+ "name": "Truthy",
+ "desc": "Truthy sections should have their contents omitted.",
+ "data": {
+ "boolean": true
+ },
+ "template": "\"{{^boolean}}This should not be rendered.{{/boolean}}\"",
+ "expected": "\"\""
+ },
+ {
+ "name": "Context",
+ "desc": "Objects and hashes should behave like truthy values.",
+ "data": {
+ "context": {
+ "name": "Joe"
+ }
+ },
+ "template": "\"{{^context}}Hi {{name}}.{{/context}}\"",
+ "expected": "\"\""
+ },
+ {
+ "name": "List",
+ "desc": "Lists should behave like truthy values.",
+ "data": {
+ "list": [
+ {
+ "n": 1
+ },
+ {
+ "n": 2
+ },
+ {
+ "n": 3
+ }
+ ]
+ },
+ "template": "\"{{^list}}{{n}}{{/list}}\"",
+ "expected": "\"\""
+ },
+ {
+ "name": "Empty List",
+ "desc": "Empty lists should behave like falsey values.",
+ "data": {
+ "list": [
+
+ ]
+ },
+ "template": "\"{{^list}}Yay lists!{{/list}}\"",
+ "expected": "\"Yay lists!\""
+ },
+ {
+ "name": "Doubled",
+ "desc": "Multiple inverted sections per template should be permitted.",
+ "data": {
+ "bool": false,
+ "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 (Falsey)",
+ "desc": "Nested falsey sections should have their contents rendered.",
+ "data": {
+ "bool": false
+ },
+ "template": "| A {{^bool}}B {{^bool}}C{{/bool}} D{{/bool}} E |",
+ "expected": "| A B C D E |"
+ },
+ {
+ "name": "Nested (Truthy)",
+ "desc": "Nested truthy sections should be omitted.",
+ "data": {
+ "bool": true
+ },
+ "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}}Cannot find key 'missing'!{{/missing}}]",
+ "expected": "[Cannot find key 'missing'!]"
+ },
+ {
+ "name": "Dotted Names - Truthy",
+ "desc": "Dotted names should be valid for Inverted Section tags.",
+ "data": {
+ "a": {
+ "b": {
+ "c": true
+ }
+ }
+ },
+ "template": "\"{{^a.b.c}}Not Here{{/a.b.c}}\" == \"\"",
+ "expected": "\"\" == \"\""
+ },
+ {
+ "name": "Dotted Names - Falsey",
+ "desc": "Dotted names should be valid for Inverted Section tags.",
+ "data": {
+ "a": {
+ "b": {
+ "c": false
+ }
+ }
+ },
+ "template": "\"{{^a.b.c}}Not Here{{/a.b.c}}\" == \"Not Here\"",
+ "expected": "\"Not Here\" == \"Not Here\""
+ },
+ {
+ "name": "Dotted Names - Broken Chains",
+ "desc": "Dotted names that cannot be resolved should be considered falsey.",
+ "data": {
+ "a": {
+ }
+ },
+ "template": "\"{{^a.b.c}}Not Here{{/a.b.c}}\" == \"Not Here\"",
+ "expected": "\"Not Here\" == \"Not Here\""
+ },
+ {
+ "name": "Surrounding Whitespace",
+ "desc": "Inverted sections should not alter surrounding whitespace.",
+ "data": {
+ "boolean": false
+ },
+ "template": " | {{^boolean}}\t|\t{{/boolean}} | \n",
+ "expected": " | \t|\t | \n"
+ },
+ {
+ "name": "Internal Whitespace",
+ "desc": "Inverted should not alter internal whitespace.",
+ "data": {
+ "boolean": false
+ },
+ "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": false
+ },
+ "template": " {{^boolean}}NO{{/boolean}}\n {{^boolean}}WAY{{/boolean}}\n",
+ "expected": " NO\n WAY\n"
+ },
+ {
+ "name": "Standalone Lines",
+ "desc": "Standalone lines should be removed from the template.",
+ "data": {
+ "boolean": false
+ },
+ "template": "| This Is\n{{^boolean}}\n|\n{{/boolean}}\n| A Line\n",
+ "expected": "| This Is\n|\n| A Line\n"
+ },
+ {
+ "name": "Standalone Indented Lines",
+ "desc": "Standalone indented lines should be removed from the template.",
+ "data": {
+ "boolean": false
+ },
+ "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": false
+ },
+ "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": false
+ },
+ "template": " {{^boolean}}\n^{{/boolean}}\n/",
+ "expected": "^\n/"
+ },
+ {
+ "name": "Standalone Without Newline",
+ "desc": "Standalone tags should not require a newline to follow them.",
+ "data": {
+ "boolean": false
+ },
+ "template": "^{{^boolean}}\n/\n {{/boolean}}",
+ "expected": "^\n/\n"
+ },
+ {
+ "name": "Padding",
+ "desc": "Superfluous in-tag whitespace should be ignored.",
+ "data": {
+ "boolean": false
+ },
+ "template": "|{{^ boolean }}={{/ boolean }}|",
+ "expected": "|=|"
+ }
+ ]
+}
diff --git a/specs/partials.json b/specs/partials.json
index e5f21a2..89dde46 100644
--- a/specs/partials.json
+++ b/specs/partials.json
@@ -1 +1,139 @@
-{"__ATTN__":"Do not edit this file; changes belong in the appropriate YAML file.","overview":"Partial tags are used to expand an external template into the current\ntemplate.\n\nThe tag's content MUST be a non-whitespace character sequence NOT containing\nthe current closing delimiter.\n\nThis tag's content names the partial to inject. Set Delimiter tags MUST NOT\naffect the parsing of a partial. The partial MUST be rendered against the\ncontext stack local to the tag. If the named partial cannot be found, the\nempty string SHOULD be used instead, as in interpolations.\n\nPartial tags SHOULD be treated as standalone when appropriate. If this tag\nis used standalone, any whitespace preceding the tag should treated as\nindentation, and prepended to each line of the partial before rendering.\n","tests":[{"name":"Basic Behavior","data":{},"expected":"\"from partial\"","template":"\"{{>text}}\"","desc":"The greater-than operator should expand to the named partial.","partials":{"text":"from partial"}},{"name":"Failed Lookup","data":{},"expected":"\"\"","template":"\"{{>text}}\"","desc":"The empty string should be used when the named partial is not found.","partials":{}},{"name":"Context","data":{"text":"content"},"expected":"\"*content*\"","template":"\"{{>partial}}\"","desc":"The greater-than operator should operate within the current context.","partials":{"partial":"*{{text}}*"}},{"name":"Recursion","data":{"content":"X","nodes":[{"content":"Y","nodes":[]}]},"expected":"X<Y<>>","template":"{{>node}}","desc":"The greater-than operator should properly recurse.","partials":{"node":"{{content}}<{{#nodes}}{{>node}}{{/nodes}}>"}},{"name":"Surrounding Whitespace","data":{},"expected":"| \t|\t |","template":"| {{>partial}} |","desc":"The greater-than operator should not alter surrounding whitespace.","partials":{"partial":"\t|\t"}},{"name":"Inline Indentation","data":{"data":"|"},"expected":" | >\n>\n","template":" {{data}} {{> partial}}\n","desc":"Whitespace should be left untouched.","partials":{"partial":">\n>"}},{"name":"Standalone Line Endings","data":{},"expected":"|\r\n>|","template":"|\r\n{{>partial}}\r\n|","desc":"\"\\r\\n\" should be considered a newline for standalone tags.","partials":{"partial":">"}},{"name":"Standalone Without Previous Line","data":{},"expected":" >\n >>","template":" {{>partial}}\n>","desc":"Standalone tags should not require a newline to precede them.","partials":{"partial":">\n>"}},{"name":"Standalone Without Newline","data":{},"expected":">\n >\n >","template":">\n {{>partial}}","desc":"Standalone tags should not require a newline to follow them.","partials":{"partial":">\n>"}},{"name":"Standalone Indentation","data":{"content":"<\n->"},"expected":"\\\n |\n <\n->\n |\n/\n","template":"\\\n {{>partial}}\n/\n","desc":"Each line of the partial should be indented before rendering.","partials":{"partial":"|\n{{{content}}}\n|\n"}},{"name":"Padding Whitespace","data":{"boolean":true},"expected":"|[]|","template":"|{{> partial }}|","desc":"Superfluous in-tag whitespace should be ignored.","partials":{"partial":"[]"}}]} \ No newline at end of file
+{
+ "__ATTN__": "Do not edit this file; changes belong in the appropriate YAML file.",
+ "overview": "Partial tags are used to expand an external template into the current\ntemplate.\n\nThe tag's content MUST be a non-whitespace character sequence NOT containing\nthe current closing delimiter.\n\nThis tag's content names the partial to inject. Set Delimiter tags MUST NOT\naffect the parsing of a partial. The partial MUST be rendered against the\ncontext stack local to the tag. If the named partial cannot be found, the\nempty string SHOULD be used instead, as in interpolations.\n\nPartial tags SHOULD be treated as standalone when appropriate. If this tag\nis used standalone, any whitespace preceding the tag should treated as\nindentation, and prepended to each line of the partial before rendering.\n",
+ "tests": [
+ {
+ "name": "Basic Behavior",
+ "desc": "The greater-than operator should expand to the named partial.",
+ "data": {
+ },
+ "template": "\"{{>text}}\"",
+ "partials": {
+ "text": "from partial"
+ },
+ "expected": "\"from partial\""
+ },
+ {
+ "name": "Failed Lookup",
+ "desc": "The empty string should be used when the named partial is not found.",
+ "data": {
+ },
+ "template": "\"{{>text}}\"",
+ "partials": {
+ },
+ "expected": "\"\""
+ },
+ {
+ "name": "Context",
+ "desc": "The greater-than operator should operate within the current context.",
+ "data": {
+ "text": "content"
+ },
+ "template": "\"{{>partial}}\"",
+ "partials": {
+ "partial": "*{{text}}*"
+ },
+ "expected": "\"*content*\""
+ },
+ {
+ "name": "Recursion",
+ "desc": "The greater-than operator should properly recurse.",
+ "data": {
+ "content": "X",
+ "nodes": [
+ {
+ "content": "Y",
+ "nodes": [
+
+ ]
+ }
+ ]
+ },
+ "template": "{{>node}}",
+ "partials": {
+ "node": "{{content}}<{{#nodes}}{{>node}}{{/nodes}}>"
+ },
+ "expected": "X<Y<>>"
+ },
+ {
+ "name": "Surrounding Whitespace",
+ "desc": "The greater-than operator should not alter surrounding whitespace.",
+ "data": {
+ },
+ "template": "| {{>partial}} |",
+ "partials": {
+ "partial": "\t|\t"
+ },
+ "expected": "| \t|\t |"
+ },
+ {
+ "name": "Inline Indentation",
+ "desc": "Whitespace should be left untouched.",
+ "data": {
+ "data": "|"
+ },
+ "template": " {{data}} {{> partial}}\n",
+ "partials": {
+ "partial": ">\n>"
+ },
+ "expected": " | >\n>\n"
+ },
+ {
+ "name": "Standalone Line Endings",
+ "desc": "\"\\r\\n\" should be considered a newline for standalone tags.",
+ "data": {
+ },
+ "template": "|\r\n{{>partial}}\r\n|",
+ "partials": {
+ "partial": ">"
+ },
+ "expected": "|\r\n>|"
+ },
+ {
+ "name": "Standalone Without Previous Line",
+ "desc": "Standalone tags should not require a newline to precede them.",
+ "data": {
+ },
+ "template": " {{>partial}}\n>",
+ "partials": {
+ "partial": ">\n>"
+ },
+ "expected": " >\n >>"
+ },
+ {
+ "name": "Standalone Without Newline",
+ "desc": "Standalone tags should not require a newline to follow them.",
+ "data": {
+ },
+ "template": ">\n {{>partial}}",
+ "partials": {
+ "partial": ">\n>"
+ },
+ "expected": ">\n >\n >"
+ },
+ {
+ "name": "Standalone Indentation",
+ "desc": "Each line of the partial should be indented before rendering.",
+ "data": {
+ "content": "<\n->"
+ },
+ "template": "\\\n {{>partial}}\n/\n",
+ "partials": {
+ "partial": "|\n{{{content}}}\n|\n"
+ },
+ "expected": "\\\n |\n <\n->\n |\n/\n"
+ },
+ {
+ "name": "Padding Whitespace",
+ "desc": "Superfluous in-tag whitespace should be ignored.",
+ "data": {
+ "boolean": true
+ },
+ "template": "|{{> partial }}|",
+ "partials": {
+ "partial": "[]"
+ },
+ "expected": "|[]|"
+ }
+ ]
+}
diff --git a/specs/sections.json b/specs/sections.json
index b0aa352..73eb2a4 100644
--- a/specs/sections.json
+++ b/specs/sections.json
@@ -1 +1,358 @@
-{"__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","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":"Context Misses","data":{},"expected":"[]","template":"[{{#missing}}Found key 'missing'!{{/missing}}]","desc":"Failed context lookups should be considered falsey."},{"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":"Dotted Names - Truthy","data":{"a":{"b":{"c":true}}},"expected":"\"Here\" == \"Here\"","template":"\"{{#a.b.c}}Here{{/a.b.c}}\" == \"Here\"","desc":"Dotted names should be valid for Section tags."},{"name":"Dotted Names - Falsey","data":{"a":{"b":{"c":false}}},"expected":"\"\" == \"\"","template":"\"{{#a.b.c}}Here{{/a.b.c}}\" == \"\"","desc":"Dotted names should be valid for Section tags."},{"name":"Dotted Names - Broken Chains","data":{"a":{}},"expected":"\"\" == \"\"","template":"\"{{#a.b.c}}Here{{/a.b.c}}\" == \"\"","desc":"Dotted names that cannot be resolved should be considered falsey."},{"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":"Indented Inline Sections","data":{"boolean":true},"expected":" YES\n GOOD\n","template":" {{#boolean}}YES{{/boolean}}\n {{#boolean}}GOOD{{/boolean}}\n","desc":"Single-line sections should not alter surrounding 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":"Standalone Line Endings","data":{"boolean":true},"expected":"|\r\n|","template":"|\r\n{{#boolean}}\r\n{{/boolean}}\r\n|","desc":"\"\\r\\n\" should be considered a newline for standalone tags."},{"name":"Standalone Without Previous Line","data":{"boolean":true},"expected":"#\n/","template":" {{#boolean}}\n#{{/boolean}}\n/","desc":"Standalone tags should not require a newline to precede them."},{"name":"Standalone Without Newline","data":{"boolean":true},"expected":"#\n/\n","template":"#{{#boolean}}\n/\n {{/boolean}}","desc":"Standalone tags should not require a newline to follow them."},{"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.",
+ "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": "|=|"
+ }
+ ]
+}
diff --git a/specs/sections.yml b/specs/sections.yml
index f62d9cb..40021c0 100644
--- a/specs/sections.yml
+++ b/specs/sections.yml
@@ -53,14 +53,42 @@ tests:
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,
+ 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}}"'
+ 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 }
- e: { five: 5 }
+ c: { three: 3, d : { four : 4, five : 5 } }
template: |
{{#a}}
{{one}}
@@ -70,9 +98,11 @@ tests:
{{one}}{{two}}{{three}}{{two}}{{one}}
{{#d}}
{{one}}{{two}}{{three}}{{four}}{{three}}{{two}}{{one}}
- {{#e}}
+ {{#five}}
+ {{one}}{{two}}{{three}}{{four}}{{five}}{{four}}{{three}}{{two}}{{one}}
+ {{one}}{{two}}{{three}}{{four}}{{.}}6{{.}}{{four}}{{three}}{{two}}{{one}}
{{one}}{{two}}{{three}}{{four}}{{five}}{{four}}{{three}}{{two}}{{one}}
- {{/e}}
+ {{/five}}
{{one}}{{two}}{{three}}{{four}}{{three}}{{two}}{{one}}
{{/d}}
{{one}}{{two}}{{three}}{{two}}{{one}}
@@ -87,6 +117,8 @@ tests:
12321
1234321
123454321
+ 12345654321
+ 123454321
1234321
12321
121
@@ -161,6 +193,13 @@ tests:
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)"'
+
# Dotted Names
- name: Dotted Names - Truthy
diff --git a/specs/~lambdas.json b/specs/~lambdas.json
index 3c58bf8..7b6d59c 100644
--- a/specs/~lambdas.json
+++ b/specs/~lambdas.json
@@ -1 +1,202 @@
-{"__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","data":{"lambda":{"php":"return \"world\";","clojure":"(fn [] \"world\")","__tag__":"code","perl":"sub { \"world\" }","python":"lambda: \"world\"","ruby":"proc { \"world\" }","js":"function() { return \"world\" }"}},"expected":"Hello, world!","template":"Hello, {{lambda}}!","desc":"A lambda's return value should be interpolated."},{"name":"Interpolation - Expansion","data":{"planet":"world","lambda":{"php":"return \"{{planet}}\";","clojure":"(fn [] \"{{planet}}\")","__tag__":"code","perl":"sub { \"{{planet}}\" }","python":"lambda: \"{{planet}}\"","ruby":"proc { \"{{planet}}\" }","js":"function() { return \"{{planet}}\" }"}},"expected":"Hello, world!","template":"Hello, {{lambda}}!","desc":"A lambda's return value should be parsed."},{"name":"Interpolation - Alternate Delimiters","data":{"planet":"world","lambda":{"php":"return \"|planet| => {{planet}}\";","clojure":"(fn [] \"|planet| => {{planet}}\")","__tag__":"code","perl":"sub { \"|planet| => {{planet}}\" }","python":"lambda: \"|planet| => {{planet}}\"","ruby":"proc { \"|planet| => {{planet}}\" }","js":"function() { return \"|planet| => {{planet}}\" }"}},"expected":"Hello, (|planet| => world)!","template":"{{= | | =}}\nHello, (|&lambda|)!","desc":"A lambda's return value should parse with the default delimiters."},{"name":"Interpolation - Multiple Calls","data":{"lambda":{"php":"global $calls; return ++$calls;","clojure":"(def g (atom 0)) (fn [] (swap! g inc))","__tag__":"code","perl":"sub { no strict; $calls += 1 }","python":"lambda: globals().update(calls=globals().get(\"calls\",0)+1) or calls","ruby":"proc { $calls ||= 0; $calls += 1 }","js":"function() { return (g=(function(){return this})()).calls=(g.calls||0)+1 }"}},"expected":"1 == 2 == 3","template":"{{lambda}} == {{{lambda}}} == {{lambda}}","desc":"Interpolated lambdas should not be cached."},{"name":"Escaping","data":{"lambda":{"php":"return \">\";","clojure":"(fn [] \">\")","__tag__":"code","perl":"sub { \">\" }","python":"lambda: \">\"","ruby":"proc { \">\" }","js":"function() { return \">\" }"}},"expected":"<&gt;>","template":"<{{lambda}}{{{lambda}}}","desc":"Lambda results should be appropriately escaped."},{"name":"Section","data":{"x":"Error!","lambda":{"php":"return ($text == \"{{x}}\") ? \"yes\" : \"no\";","clojure":"(fn [text] (if (= text \"{{x}}\") \"yes\" \"no\"))","__tag__":"code","perl":"sub { $_[0] eq \"{{x}}\" ? \"yes\" : \"no\" }","python":"lambda text: text == \"{{x}}\" and \"yes\" or \"no\"","ruby":"proc { |text| text == \"{{x}}\" ? \"yes\" : \"no\" }","js":"function(txt) { return (txt == \"{{x}}\" ? \"yes\" : \"no\") }"}},"expected":"<yes>","template":"<{{#lambda}}{{x}}{{/lambda}}>","desc":"Lambdas used for sections should receive the raw section string."},{"name":"Section - Expansion","data":{"planet":"Earth","lambda":{"php":"return $text . \"{{planet}}\" . $text;","clojure":"(fn [text] (str text \"{{planet}}\" text))","__tag__":"code","perl":"sub { $_[0] . \"{{planet}}\" . $_[0] }","python":"lambda text: \"%s{{planet}}%s\" % (text, text)","ruby":"proc { |text| \"#{text}{{planet}}#{text}\" }","js":"function(txt) { return txt + \"{{planet}}\" + txt }"}},"expected":"<-Earth->","template":"<{{#lambda}}-{{/lambda}}>","desc":"Lambdas used for sections should have their results parsed."},{"name":"Section - Alternate Delimiters","data":{"planet":"Earth","lambda":{"php":"return $text . \"{{planet}} => |planet|\" . $text;","clojure":"(fn [text] (str text \"{{planet}} => |planet|\" text))","__tag__":"code","perl":"sub { $_[0] . \"{{planet}} => |planet|\" . $_[0] }","python":"lambda text: \"%s{{planet}} => |planet|%s\" % (text, text)","ruby":"proc { |text| \"#{text}{{planet}} => |planet|#{text}\" }","js":"function(txt) { return txt + \"{{planet}} => |planet|\" + txt }"}},"expected":"<-{{planet}} => Earth->","template":"{{= | | =}}<|#lambda|-|/lambda|>","desc":"Lambdas used for sections should parse with the current delimiters."},{"name":"Section - Multiple Calls","data":{"lambda":{"php":"return \"__\" . $text . \"__\";","clojure":"(fn [text] (str \"__\" text \"__\"))","__tag__":"code","perl":"sub { \"__\" . $_[0] . \"__\" }","python":"lambda text: \"__%s__\" % (text)","ruby":"proc { |text| \"__#{text}__\" }","js":"function(txt) { return \"__\" + txt + \"__\" }"}},"expected":"__FILE__ != __LINE__","template":"{{#lambda}}FILE{{/lambda}} != {{#lambda}}LINE{{/lambda}}","desc":"Lambdas used for sections should not be cached."},{"name":"Inverted Section","data":{"static":"static","lambda":{"php":"return false;","clojure":"(fn [text] false)","__tag__":"code","perl":"sub { 0 }","python":"lambda text: 0","ruby":"proc { |text| false }","js":"function(txt) { return false }"}},"expected":"<>","template":"<{{^lambda}}{{static}}{{/lambda}}>","desc":"Lambdas used for inverted sections should be considered truthy."}]} \ 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": {
+ "__tag__": "code",
+ "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": {
+ "__tag__": "code",
+ "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": {
+ "__tag__": "code",
+ "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": {
+ "__tag__": "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;",
+ "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": {
+ "__tag__": "code",
+ "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": {
+ "__tag__": "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\";",
+ "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": {
+ "__tag__": "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;",
+ "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": {
+ "__tag__": "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;",
+ "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": {
+ "__tag__": "code",
+ "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": {
+ "__tag__": "code",
+ "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": "<>"
+ }
+ ]
+}
diff --git a/specs/~lambdas.yml b/specs/~lambdas.yml
index b9fb4d0..e4eea42 100644
--- a/specs/~lambdas.yml
+++ b/specs/~lambdas.yml
@@ -17,11 +17,13 @@ tests:
data:
lambda: !code
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!"
@@ -31,11 +33,13 @@ tests:
planet: "world"
lambda: !code
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!"
@@ -45,11 +49,13 @@ 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}}";'
python: 'lambda: "|planet| => {{planet}}"'
clojure: '(fn [] "|planet| => {{planet}}")'
+ lisp: '(lambda () "|planet| => {{planet}}")'
template: "{{= | | =}}\nHello, (|&lambda|)!"
expected: "Hello, (|planet| => world)!"
@@ -58,11 +64,13 @@ 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;'
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'
@@ -71,11 +79,13 @@ tests:
data:
lambda: !code
ruby: 'proc { ">" }'
+ raku: 'sub { ">" }'
perl: 'sub { ">" }'
js: 'function() { return ">" }'
php: 'return ">";'
python: 'lambda: ">"'
clojure: '(fn [] ">")'
+ lisp: '(lambda () ">")'
template: "<{{lambda}}{{{lambda}}}"
expected: "<&gt;>"
@@ -85,11 +95,13 @@ 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";'
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>"
@@ -99,11 +111,13 @@ 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;'
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->"
@@ -113,11 +127,13 @@ 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;'
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->"
@@ -126,11 +142,13 @@ tests:
data:
lambda: !code
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__'
@@ -140,10 +158,12 @@ tests:
static: 'static'
lambda: !code
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: "<>"