summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Appel <Dan.appel00@gmail.com>2021-03-30 18:03:46 -0700
committerGitHub <noreply@github.com>2021-03-30 18:03:46 -0700
commit86fe766daff2cd776af016af6ce101f0d0b00a77 (patch)
tree219da01c4ba286d40f068ff8649896d817a306fd
parente349314b156b61ec1a2f7d0dab30aaa9fe07ed6a (diff)
parent1d5972335e539d1f32566d4fce4ea3e215871409 (diff)
downloadmustache-spec-86fe766daff2cd776af016af6ce101f0d0b00a77.tar.gz
Merge pull request #119 from softmoth/json-newline
Pretty print JSON files, and terminate with newline
-rw-r--r--Rakefile2
-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/~lambdas.json193
8 files changed, 1463 insertions, 8 deletions
diff --git a/Rakefile b/Rakefile
index 1bbcc72..6c6008f 100644
--- a/Rakefile
+++ b/Rakefile
@@ -21,7 +21,7 @@ namespace :build do
File.open(json_file, 'w') do |file|
warning = {:__ATTN__ => note}
doc = YAML.load_file(filename)
- file << warning.merge(doc).to_json()
+ file << JSON.pretty_generate(warning.merge(doc)) << "\n"
end
end
end
diff --git a/specs/comments.json b/specs/comments.json
index 2fbddef..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","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"}]} \ 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 e41a93e..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","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":"||"}]} \ 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 462dbce..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","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":"|---|"}]} \ 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 5ce5c80..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","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":"|=|"}]} \ 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 f816fce..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","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":"|[]|"}]} \ 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 1dfcff0..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","desc":"Truthy sections should have their contents rendered.","data":{"boolean":true},"template":"\"{{#boolean}}This should be rendered.{{/boolean}}\"","expected":"\"This should be rendered.\""},{"name":"Falsey","desc":"Falsey sections should have their contents omitted.","data":{"boolean":false},"template":"\"{{#boolean}}This should not be rendered.{{/boolean}}\"","expected":"\"\""},{"name":"Context","desc":"Objects and hashes should be pushed onto the context stack.","data":{"context":{"name":"Joe"}},"template":"\"{{#context}}Hi {{name}}.{{/context}}\"","expected":"\"Hi Joe.\""},{"name":"Parent contexts","desc":"Names missing in the current context are looked up in the stack.","data":{"a":"foo","b":"wrong","sec":{"b":"bar"},"c":{"d":"baz"}},"template":"\"{{#sec}}{{a}}, {{b}}, {{c.d}}{{/sec}}\"","expected":"\"foo, bar, baz\""},{"name":"Variable test","desc":"Non-false sections have their value at the top of context,\naccessible as {{.}} or through the parent context. This gives\na simple way to display content conditionally if a variable exists.\n","data":{"foo":"bar"},"template":"\"{{#foo}}{{.}} is {{foo}}{{/foo}}\"","expected":"\"bar is bar\""},{"name":"List Contexts","desc":"All elements on the context stack should be accessible within lists.","data":{"tops":[{"tname":{"upper":"A","lower":"a"},"middles":[{"mname":"1","bottoms":[{"bname":"x"},{"bname":"y"}]}]}]},"template":"{{#tops}}{{#middles}}{{tname.lower}}{{mname}}.{{#bottoms}}{{tname.upper}}{{mname}}{{bname}}.{{/bottoms}}{{/middles}}{{/tops}}","expected":"a1.A1x.A1y."},{"name":"Deeply Nested Contexts","desc":"All elements on the context stack should be accessible.","data":{"a":{"one":1},"b":{"two":2},"c":{"three":3,"d":{"four":4,"five":5}}},"template":"{{#a}}\n{{one}}\n{{#b}}\n{{one}}{{two}}{{one}}\n{{#c}}\n{{one}}{{two}}{{three}}{{two}}{{one}}\n{{#d}}\n{{one}}{{two}}{{three}}{{four}}{{three}}{{two}}{{one}}\n{{#five}}\n{{one}}{{two}}{{three}}{{four}}{{five}}{{four}}{{three}}{{two}}{{one}}\n{{one}}{{two}}{{three}}{{four}}{{.}}6{{.}}{{four}}{{three}}{{two}}{{one}}\n{{one}}{{two}}{{three}}{{four}}{{five}}{{four}}{{three}}{{two}}{{one}}\n{{/five}}\n{{one}}{{two}}{{three}}{{four}}{{three}}{{two}}{{one}}\n{{/d}}\n{{one}}{{two}}{{three}}{{two}}{{one}}\n{{/c}}\n{{one}}{{two}}{{one}}\n{{/b}}\n{{one}}\n{{/a}}\n","expected":"1\n121\n12321\n1234321\n123454321\n12345654321\n123454321\n1234321\n12321\n121\n1\n"},{"name":"List","desc":"Lists should be iterated; list items should visit the context stack.","data":{"list":[{"item":1},{"item":2},{"item":3}]},"template":"\"{{#list}}{{item}}{{/list}}\"","expected":"\"123\""},{"name":"Empty List","desc":"Empty lists should behave like falsey values.","data":{"list":[]},"template":"\"{{#list}}Yay lists!{{/list}}\"","expected":"\"\""},{"name":"Doubled","desc":"Multiple sections per template should be permitted.","data":{"bool":true,"two":"second"},"template":"{{#bool}}\n* first\n{{/bool}}\n* {{two}}\n{{#bool}}\n* third\n{{/bool}}\n","expected":"* first\n* second\n* third\n"},{"name":"Nested (Truthy)","desc":"Nested truthy sections should have their contents rendered.","data":{"bool":true},"template":"| A {{#bool}}B {{#bool}}C{{/bool}} D{{/bool}} E |","expected":"| A B C D E |"},{"name":"Nested (Falsey)","desc":"Nested falsey sections should be omitted.","data":{"bool":false},"template":"| A {{#bool}}B {{#bool}}C{{/bool}} D{{/bool}} E |","expected":"| A E |"},{"name":"Context Misses","desc":"Failed context lookups should be considered falsey.","data":{},"template":"[{{#missing}}Found key 'missing'!{{/missing}}]","expected":"[]"},{"name":"Implicit Iterator - String","desc":"Implicit iterators should directly interpolate strings.","data":{"list":["a","b","c","d","e"]},"template":"\"{{#list}}({{.}}){{/list}}\"","expected":"\"(a)(b)(c)(d)(e)\""},{"name":"Implicit Iterator - Integer","desc":"Implicit iterators should cast integers to strings and interpolate.","data":{"list":[1,2,3,4,5]},"template":"\"{{#list}}({{.}}){{/list}}\"","expected":"\"(1)(2)(3)(4)(5)\""},{"name":"Implicit Iterator - Decimal","desc":"Implicit iterators should cast decimals to strings and interpolate.","data":{"list":[1.1,2.2,3.3,4.4,5.5]},"template":"\"{{#list}}({{.}}){{/list}}\"","expected":"\"(1.1)(2.2)(3.3)(4.4)(5.5)\""},{"name":"Implicit Iterator - Array","desc":"Implicit iterators should allow iterating over nested arrays.","data":{"list":[[1,2,3],["a","b","c"]]},"template":"\"{{#list}}({{#.}}{{.}}{{/.}}){{/list}}\"","expected":"\"(123)(abc)\""},{"name":"Dotted Names - Truthy","desc":"Dotted names should be valid for Section tags.","data":{"a":{"b":{"c":true}}},"template":"\"{{#a.b.c}}Here{{/a.b.c}}\" == \"Here\"","expected":"\"Here\" == \"Here\""},{"name":"Dotted Names - Falsey","desc":"Dotted names should be valid for Section tags.","data":{"a":{"b":{"c":false}}},"template":"\"{{#a.b.c}}Here{{/a.b.c}}\" == \"\"","expected":"\"\" == \"\""},{"name":"Dotted Names - Broken Chains","desc":"Dotted names that cannot be resolved should be considered falsey.","data":{"a":{}},"template":"\"{{#a.b.c}}Here{{/a.b.c}}\" == \"\"","expected":"\"\" == \"\""},{"name":"Surrounding Whitespace","desc":"Sections should not alter surrounding whitespace.","data":{"boolean":true},"template":" | {{#boolean}}\t|\t{{/boolean}} | \n","expected":" | \t|\t | \n"},{"name":"Internal Whitespace","desc":"Sections should not alter internal whitespace.","data":{"boolean":true},"template":" | {{#boolean}} {{! Important Whitespace }}\n {{/boolean}} | \n","expected":" | \n | \n"},{"name":"Indented Inline Sections","desc":"Single-line sections should not alter surrounding whitespace.","data":{"boolean":true},"template":" {{#boolean}}YES{{/boolean}}\n {{#boolean}}GOOD{{/boolean}}\n","expected":" YES\n GOOD\n"},{"name":"Standalone Lines","desc":"Standalone lines should be removed from the template.","data":{"boolean":true},"template":"| This Is\n{{#boolean}}\n|\n{{/boolean}}\n| A Line\n","expected":"| This Is\n|\n| A Line\n"},{"name":"Indented Standalone Lines","desc":"Indented standalone lines should be removed from the template.","data":{"boolean":true},"template":"| This Is\n {{#boolean}}\n|\n {{/boolean}}\n| A Line\n","expected":"| This Is\n|\n| A Line\n"},{"name":"Standalone Line Endings","desc":"\"\\r\\n\" should be considered a newline for standalone tags.","data":{"boolean":true},"template":"|\r\n{{#boolean}}\r\n{{/boolean}}\r\n|","expected":"|\r\n|"},{"name":"Standalone Without Previous Line","desc":"Standalone tags should not require a newline to precede them.","data":{"boolean":true},"template":" {{#boolean}}\n#{{/boolean}}\n/","expected":"#\n/"},{"name":"Standalone Without Newline","desc":"Standalone tags should not require a newline to follow them.","data":{"boolean":true},"template":"#{{#boolean}}\n/\n {{/boolean}}","expected":"#\n/\n"},{"name":"Padding","desc":"Superfluous in-tag whitespace should be ignored.","data":{"boolean":true},"template":"|{{# boolean }}={{/ boolean }}|","expected":"|=|"}]} \ No newline at end of file
+{
+ "__ATTN__": "Do not edit this file; changes belong in the appropriate YAML file.",
+ "overview": "Section tags and End Section tags are used in combination to wrap a section\nof the template for iteration\n\nThese tags' content MUST be a non-whitespace character sequence NOT\ncontaining the current closing delimiter; each Section tag MUST be followed\nby an End Section tag with the same content within the same section.\n\nThis tag's content names the data to replace the tag. Name resolution is as\nfollows:\n 1) Split the name on periods; the first part is the name to resolve, any\n remaining parts should be retained.\n 2) Walk the context stack from top to bottom, finding the first context\n that is a) a hash containing the name as a key OR b) an object responding\n to a method with the given name.\n 3) If the context is a hash, the data is the value associated with the\n name.\n 4) If the context is an object and the method with the given name has an\n arity of 1, the method SHOULD be called with a String containing the\n unprocessed contents of the sections; the data is the value returned.\n 5) Otherwise, the data is the value returned by calling the method with\n the given name.\n 6) If any name parts were retained in step 1, each should be resolved\n against a context stack containing only the result from the former\n resolution. If any part fails resolution, the result should be considered\n falsey, and should interpolate as the empty string.\nIf the data is not of a list type, it is coerced into a list as follows: if\nthe data is truthy (e.g. `!!data == true`), use a single-element list\ncontaining the data, otherwise use an empty list.\n\nFor each element in the data list, the element MUST be pushed onto the\ncontext stack, the section MUST be rendered, and the element MUST be popped\noff the context stack.\n\nSection and End Section tags SHOULD be treated as standalone when\nappropriate.\n",
+ "tests": [
+ {
+ "name": "Truthy",
+ "desc": "Truthy sections should have their contents rendered.",
+ "data": {
+ "boolean": true
+ },
+ "template": "\"{{#boolean}}This should be rendered.{{/boolean}}\"",
+ "expected": "\"This should be rendered.\""
+ },
+ {
+ "name": "Falsey",
+ "desc": "Falsey sections should have their contents omitted.",
+ "data": {
+ "boolean": false
+ },
+ "template": "\"{{#boolean}}This should not be rendered.{{/boolean}}\"",
+ "expected": "\"\""
+ },
+ {
+ "name": "Context",
+ "desc": "Objects and hashes should be pushed onto the context stack.",
+ "data": {
+ "context": {
+ "name": "Joe"
+ }
+ },
+ "template": "\"{{#context}}Hi {{name}}.{{/context}}\"",
+ "expected": "\"Hi Joe.\""
+ },
+ {
+ "name": "Parent contexts",
+ "desc": "Names missing in the current context are looked up in the stack.",
+ "data": {
+ "a": "foo",
+ "b": "wrong",
+ "sec": {
+ "b": "bar"
+ },
+ "c": {
+ "d": "baz"
+ }
+ },
+ "template": "\"{{#sec}}{{a}}, {{b}}, {{c.d}}{{/sec}}\"",
+ "expected": "\"foo, bar, baz\""
+ },
+ {
+ "name": "Variable test",
+ "desc": "Non-false sections have their value at the top of context,\naccessible as {{.}} or through the parent context. This gives\na simple way to display content conditionally if a variable exists.\n",
+ "data": {
+ "foo": "bar"
+ },
+ "template": "\"{{#foo}}{{.}} is {{foo}}{{/foo}}\"",
+ "expected": "\"bar is bar\""
+ },
+ {
+ "name": "List Contexts",
+ "desc": "All elements on the context stack should be accessible within lists.",
+ "data": {
+ "tops": [
+ {
+ "tname": {
+ "upper": "A",
+ "lower": "a"
+ },
+ "middles": [
+ {
+ "mname": "1",
+ "bottoms": [
+ {
+ "bname": "x"
+ },
+ {
+ "bname": "y"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+ },
+ "template": "{{#tops}}{{#middles}}{{tname.lower}}{{mname}}.{{#bottoms}}{{tname.upper}}{{mname}}{{bname}}.{{/bottoms}}{{/middles}}{{/tops}}",
+ "expected": "a1.A1x.A1y."
+ },
+ {
+ "name": "Deeply Nested Contexts",
+ "desc": "All elements on the context stack should be accessible.",
+ "data": {
+ "a": {
+ "one": 1
+ },
+ "b": {
+ "two": 2
+ },
+ "c": {
+ "three": 3,
+ "d": {
+ "four": 4,
+ "five": 5
+ }
+ }
+ },
+ "template": "{{#a}}\n{{one}}\n{{#b}}\n{{one}}{{two}}{{one}}\n{{#c}}\n{{one}}{{two}}{{three}}{{two}}{{one}}\n{{#d}}\n{{one}}{{two}}{{three}}{{four}}{{three}}{{two}}{{one}}\n{{#five}}\n{{one}}{{two}}{{three}}{{four}}{{five}}{{four}}{{three}}{{two}}{{one}}\n{{one}}{{two}}{{three}}{{four}}{{.}}6{{.}}{{four}}{{three}}{{two}}{{one}}\n{{one}}{{two}}{{three}}{{four}}{{five}}{{four}}{{three}}{{two}}{{one}}\n{{/five}}\n{{one}}{{two}}{{three}}{{four}}{{three}}{{two}}{{one}}\n{{/d}}\n{{one}}{{two}}{{three}}{{two}}{{one}}\n{{/c}}\n{{one}}{{two}}{{one}}\n{{/b}}\n{{one}}\n{{/a}}\n",
+ "expected": "1\n121\n12321\n1234321\n123454321\n12345654321\n123454321\n1234321\n12321\n121\n1\n"
+ },
+ {
+ "name": "List",
+ "desc": "Lists should be iterated; list items should visit the context stack.",
+ "data": {
+ "list": [
+ {
+ "item": 1
+ },
+ {
+ "item": 2
+ },
+ {
+ "item": 3
+ }
+ ]
+ },
+ "template": "\"{{#list}}{{item}}{{/list}}\"",
+ "expected": "\"123\""
+ },
+ {
+ "name": "Empty List",
+ "desc": "Empty lists should behave like falsey values.",
+ "data": {
+ "list": [
+
+ ]
+ },
+ "template": "\"{{#list}}Yay lists!{{/list}}\"",
+ "expected": "\"\""
+ },
+ {
+ "name": "Doubled",
+ "desc": "Multiple sections per template should be permitted.",
+ "data": {
+ "bool": true,
+ "two": "second"
+ },
+ "template": "{{#bool}}\n* first\n{{/bool}}\n* {{two}}\n{{#bool}}\n* third\n{{/bool}}\n",
+ "expected": "* first\n* second\n* third\n"
+ },
+ {
+ "name": "Nested (Truthy)",
+ "desc": "Nested truthy sections should have their contents rendered.",
+ "data": {
+ "bool": true
+ },
+ "template": "| A {{#bool}}B {{#bool}}C{{/bool}} D{{/bool}} E |",
+ "expected": "| A B C D E |"
+ },
+ {
+ "name": "Nested (Falsey)",
+ "desc": "Nested falsey sections should be omitted.",
+ "data": {
+ "bool": false
+ },
+ "template": "| A {{#bool}}B {{#bool}}C{{/bool}} D{{/bool}} E |",
+ "expected": "| A E |"
+ },
+ {
+ "name": "Context Misses",
+ "desc": "Failed context lookups should be considered falsey.",
+ "data": {
+ },
+ "template": "[{{#missing}}Found key 'missing'!{{/missing}}]",
+ "expected": "[]"
+ },
+ {
+ "name": "Implicit Iterator - String",
+ "desc": "Implicit iterators should directly interpolate strings.",
+ "data": {
+ "list": [
+ "a",
+ "b",
+ "c",
+ "d",
+ "e"
+ ]
+ },
+ "template": "\"{{#list}}({{.}}){{/list}}\"",
+ "expected": "\"(a)(b)(c)(d)(e)\""
+ },
+ {
+ "name": "Implicit Iterator - Integer",
+ "desc": "Implicit iterators should cast integers to strings and interpolate.",
+ "data": {
+ "list": [
+ 1,
+ 2,
+ 3,
+ 4,
+ 5
+ ]
+ },
+ "template": "\"{{#list}}({{.}}){{/list}}\"",
+ "expected": "\"(1)(2)(3)(4)(5)\""
+ },
+ {
+ "name": "Implicit Iterator - Decimal",
+ "desc": "Implicit iterators should cast decimals to strings and interpolate.",
+ "data": {
+ "list": [
+ 1.1,
+ 2.2,
+ 3.3,
+ 4.4,
+ 5.5
+ ]
+ },
+ "template": "\"{{#list}}({{.}}){{/list}}\"",
+ "expected": "\"(1.1)(2.2)(3.3)(4.4)(5.5)\""
+ },
+ {
+ "name": "Implicit Iterator - Array",
+ "desc": "Implicit iterators should allow iterating over nested arrays.",
+ "data": {
+ "list": [
+ [
+ 1,
+ 2,
+ 3
+ ],
+ [
+ "a",
+ "b",
+ "c"
+ ]
+ ]
+ },
+ "template": "\"{{#list}}({{#.}}{{.}}{{/.}}){{/list}}\"",
+ "expected": "\"(123)(abc)\""
+ },
+ {
+ "name": "Dotted Names - Truthy",
+ "desc": "Dotted names should be valid for Section tags.",
+ "data": {
+ "a": {
+ "b": {
+ "c": true
+ }
+ }
+ },
+ "template": "\"{{#a.b.c}}Here{{/a.b.c}}\" == \"Here\"",
+ "expected": "\"Here\" == \"Here\""
+ },
+ {
+ "name": "Dotted Names - Falsey",
+ "desc": "Dotted names should be valid for Section tags.",
+ "data": {
+ "a": {
+ "b": {
+ "c": false
+ }
+ }
+ },
+ "template": "\"{{#a.b.c}}Here{{/a.b.c}}\" == \"\"",
+ "expected": "\"\" == \"\""
+ },
+ {
+ "name": "Dotted Names - Broken Chains",
+ "desc": "Dotted names that cannot be resolved should be considered falsey.",
+ "data": {
+ "a": {
+ }
+ },
+ "template": "\"{{#a.b.c}}Here{{/a.b.c}}\" == \"\"",
+ "expected": "\"\" == \"\""
+ },
+ {
+ "name": "Surrounding Whitespace",
+ "desc": "Sections should not alter surrounding whitespace.",
+ "data": {
+ "boolean": true
+ },
+ "template": " | {{#boolean}}\t|\t{{/boolean}} | \n",
+ "expected": " | \t|\t | \n"
+ },
+ {
+ "name": "Internal Whitespace",
+ "desc": "Sections should not alter internal whitespace.",
+ "data": {
+ "boolean": true
+ },
+ "template": " | {{#boolean}} {{! Important Whitespace }}\n {{/boolean}} | \n",
+ "expected": " | \n | \n"
+ },
+ {
+ "name": "Indented Inline Sections",
+ "desc": "Single-line sections should not alter surrounding whitespace.",
+ "data": {
+ "boolean": true
+ },
+ "template": " {{#boolean}}YES{{/boolean}}\n {{#boolean}}GOOD{{/boolean}}\n",
+ "expected": " YES\n GOOD\n"
+ },
+ {
+ "name": "Standalone Lines",
+ "desc": "Standalone lines should be removed from the template.",
+ "data": {
+ "boolean": true
+ },
+ "template": "| This Is\n{{#boolean}}\n|\n{{/boolean}}\n| A Line\n",
+ "expected": "| This Is\n|\n| A Line\n"
+ },
+ {
+ "name": "Indented Standalone Lines",
+ "desc": "Indented standalone lines should be removed from the template.",
+ "data": {
+ "boolean": true
+ },
+ "template": "| This Is\n {{#boolean}}\n|\n {{/boolean}}\n| A Line\n",
+ "expected": "| This Is\n|\n| A Line\n"
+ },
+ {
+ "name": "Standalone Line Endings",
+ "desc": "\"\\r\\n\" should be considered a newline for standalone tags.",
+ "data": {
+ "boolean": true
+ },
+ "template": "|\r\n{{#boolean}}\r\n{{/boolean}}\r\n|",
+ "expected": "|\r\n|"
+ },
+ {
+ "name": "Standalone Without Previous Line",
+ "desc": "Standalone tags should not require a newline to precede them.",
+ "data": {
+ "boolean": true
+ },
+ "template": " {{#boolean}}\n#{{/boolean}}\n/",
+ "expected": "#\n/"
+ },
+ {
+ "name": "Standalone Without Newline",
+ "desc": "Standalone tags should not require a newline to follow them.",
+ "data": {
+ "boolean": true
+ },
+ "template": "#{{#boolean}}\n/\n {{/boolean}}",
+ "expected": "#\n/\n"
+ },
+ {
+ "name": "Padding",
+ "desc": "Superfluous in-tag whitespace should be ignored.",
+ "data": {
+ "boolean": true
+ },
+ "template": "|{{# boolean }}={{/ boolean }}|",
+ "expected": "|=|"
+ }
+ ]
+}
diff --git a/specs/~lambdas.json b/specs/~lambdas.json
index 760c733..c0362ac 100644
--- a/specs/~lambdas.json
+++ b/specs/~lambdas.json
@@ -1 +1,192 @@
-{"__ATTN__":"Do not edit this file; changes belong in the appropriate YAML file.","overview":"Lambdas are a special-cased data type for use in interpolations and\nsections.\n\nWhen used as the data value for an Interpolation tag, the lambda MUST be\ntreatable as an arity 0 function, and invoked as such. The returned value\nMUST be rendered against the default delimiters, then interpolated in place\nof the lambda.\n\nWhen used as the data value for a Section tag, the lambda MUST be treatable\nas an arity 1 function, and invoked as such (passing a String containing the\nunprocessed section contents). The returned value MUST be rendered against\nthe current delimiters, then interpolated in place of the section.\n","tests":[{"name":"Interpolation","desc":"A lambda's return value should be interpolated.","data":{"lambda":{"ruby":"proc { \"world\" }","raku":"sub { \"world\" }","perl":"sub { \"world\" }","js":"function() { return \"world\" }","php":"return \"world\";","python":"lambda: \"world\"","clojure":"(fn [] \"world\")","lisp":"(lambda () \"world\")"}},"template":"Hello, {{lambda}}!","expected":"Hello, world!"},{"name":"Interpolation - Expansion","desc":"A lambda's return value should be parsed.","data":{"planet":"world","lambda":{"ruby":"proc { \"{{planet}}\" }","raku":"sub { q+{{planet}}+ }","perl":"sub { \"{{planet}}\" }","js":"function() { return \"{{planet}}\" }","php":"return \"{{planet}}\";","python":"lambda: \"{{planet}}\"","clojure":"(fn [] \"{{planet}}\")","lisp":"(lambda () \"{{planet}}\")"}},"template":"Hello, {{lambda}}!","expected":"Hello, world!"},{"name":"Interpolation - Alternate Delimiters","desc":"A lambda's return value should parse with the default delimiters.","data":{"planet":"world","lambda":{"ruby":"proc { \"|planet| => {{planet}}\" }","raku":"sub { q+|planet| => {{planet}}+ }","perl":"sub { \"|planet| => {{planet}}\" }","js":"function() { return \"|planet| => {{planet}}\" }","php":"return \"|planet| => {{planet}}\";","python":"lambda: \"|planet| => {{planet}}\"","clojure":"(fn [] \"|planet| => {{planet}}\")","lisp":"(lambda () \"|planet| => {{planet}}\")"}},"template":"{{= | | =}}\nHello, (|&lambda|)!","expected":"Hello, (|planet| => world)!"},{"name":"Interpolation - Multiple Calls","desc":"Interpolated lambdas should not be cached.","data":{"lambda":{"ruby":"proc { $calls ||= 0; $calls += 1 }","raku":"sub { state $calls += 1 }","perl":"sub { no strict; $calls += 1 }","js":"function() { return (g=(function(){return this})()).calls=(g.calls||0)+1 }","php":"global $calls; return ++$calls;","python":"lambda: globals().update(calls=globals().get(\"calls\",0)+1) or calls","clojure":"(def g (atom 0)) (fn [] (swap! g inc))","lisp":"(let ((g 0)) (lambda () (incf g)))"}},"template":"{{lambda}} == {{{lambda}}} == {{lambda}}","expected":"1 == 2 == 3"},{"name":"Escaping","desc":"Lambda results should be appropriately escaped.","data":{"lambda":{"ruby":"proc { \">\" }","raku":"sub { \">\" }","perl":"sub { \">\" }","js":"function() { return \">\" }","php":"return \">\";","python":"lambda: \">\"","clojure":"(fn [] \">\")","lisp":"(lambda () \">\")"}},"template":"<{{lambda}}{{{lambda}}}","expected":"<&gt;>"},{"name":"Section","desc":"Lambdas used for sections should receive the raw section string.","data":{"x":"Error!","lambda":{"ruby":"proc { |text| text == \"{{x}}\" ? \"yes\" : \"no\" }","raku":"sub { $^section eq q+{{x}}+ ?? \"yes\" !! \"no\" }","perl":"sub { $_[0] eq \"{{x}}\" ? \"yes\" : \"no\" }","js":"function(txt) { return (txt == \"{{x}}\" ? \"yes\" : \"no\") }","php":"return ($text == \"{{x}}\") ? \"yes\" : \"no\";","python":"lambda text: text == \"{{x}}\" and \"yes\" or \"no\"","clojure":"(fn [text] (if (= text \"{{x}}\") \"yes\" \"no\"))","lisp":"(lambda (text) (if (string= text \"{{x}}\") \"yes\" \"no\"))"}},"template":"<{{#lambda}}{{x}}{{/lambda}}>","expected":"<yes>"},{"name":"Section - Expansion","desc":"Lambdas used for sections should have their results parsed.","data":{"planet":"Earth","lambda":{"ruby":"proc { |text| \"#{text}{{planet}}#{text}\" }","raku":"sub { $^section ~ q+{{planet}}+ ~ $^section }","perl":"sub { $_[0] . \"{{planet}}\" . $_[0] }","js":"function(txt) { return txt + \"{{planet}}\" + txt }","php":"return $text . \"{{planet}}\" . $text;","python":"lambda text: \"%s{{planet}}%s\" % (text, text)","clojure":"(fn [text] (str text \"{{planet}}\" text))","lisp":"(lambda (text) (format nil \"~a{{planet}}~a\" text text))"}},"template":"<{{#lambda}}-{{/lambda}}>","expected":"<-Earth->"},{"name":"Section - Alternate Delimiters","desc":"Lambdas used for sections should parse with the current delimiters.","data":{"planet":"Earth","lambda":{"ruby":"proc { |text| \"#{text}{{planet}} => |planet|#{text}\" }","raku":"sub { $^section ~ q+{{planet}} => |planet|+ ~ $^section }","perl":"sub { $_[0] . \"{{planet}} => |planet|\" . $_[0] }","js":"function(txt) { return txt + \"{{planet}} => |planet|\" + txt }","php":"return $text . \"{{planet}} => |planet|\" . $text;","python":"lambda text: \"%s{{planet}} => |planet|%s\" % (text, text)","clojure":"(fn [text] (str text \"{{planet}} => |planet|\" text))","lisp":"(lambda (text) (format nil \"~a{{planet}} => |planet|~a\" text text))"}},"template":"{{= | | =}}<|#lambda|-|/lambda|>","expected":"<-{{planet}} => Earth->"},{"name":"Section - Multiple Calls","desc":"Lambdas used for sections should not be cached.","data":{"lambda":{"ruby":"proc { |text| \"__#{text}__\" }","raku":"sub { \"__\" ~ $^section ~ \"__\" }","perl":"sub { \"__\" . $_[0] . \"__\" }","js":"function(txt) { return \"__\" + txt + \"__\" }","php":"return \"__\" . $text . \"__\";","python":"lambda text: \"__%s__\" % (text)","clojure":"(fn [text] (str \"__\" text \"__\"))","lisp":"(lambda (text) (format nil \"__~a__\" text))"}},"template":"{{#lambda}}FILE{{/lambda}} != {{#lambda}}LINE{{/lambda}}","expected":"__FILE__ != __LINE__"},{"name":"Inverted Section","desc":"Lambdas used for inverted sections should be considered truthy.","data":{"static":"static","lambda":{"ruby":"proc { |text| false }","raku":"sub { 0 }","perl":"sub { 0 }","js":"function(txt) { return false }","php":"return false;","python":"lambda text: 0","clojure":"(fn [text] false)","lisp":"(lambda (text) (declare (ignore text)) nil)"}},"template":"<{{^lambda}}{{static}}{{/lambda}}>","expected":"<>"}]} \ No newline at end of file
+{
+ "__ATTN__": "Do not edit this file; changes belong in the appropriate YAML file.",
+ "overview": "Lambdas are a special-cased data type for use in interpolations and\nsections.\n\nWhen used as the data value for an Interpolation tag, the lambda MUST be\ntreatable as an arity 0 function, and invoked as such. The returned value\nMUST be rendered against the default delimiters, then interpolated in place\nof the lambda.\n\nWhen used as the data value for a Section tag, the lambda MUST be treatable\nas an arity 1 function, and invoked as such (passing a String containing the\nunprocessed section contents). The returned value MUST be rendered against\nthe current delimiters, then interpolated in place of the section.\n",
+ "tests": [
+ {
+ "name": "Interpolation",
+ "desc": "A lambda's return value should be interpolated.",
+ "data": {
+ "lambda": {
+ "ruby": "proc { \"world\" }",
+ "raku": "sub { \"world\" }",
+ "perl": "sub { \"world\" }",
+ "js": "function() { return \"world\" }",
+ "php": "return \"world\";",
+ "python": "lambda: \"world\"",
+ "clojure": "(fn [] \"world\")",
+ "lisp": "(lambda () \"world\")"
+ }
+ },
+ "template": "Hello, {{lambda}}!",
+ "expected": "Hello, world!"
+ },
+ {
+ "name": "Interpolation - Expansion",
+ "desc": "A lambda's return value should be parsed.",
+ "data": {
+ "planet": "world",
+ "lambda": {
+ "ruby": "proc { \"{{planet}}\" }",
+ "raku": "sub { q+{{planet}}+ }",
+ "perl": "sub { \"{{planet}}\" }",
+ "js": "function() { return \"{{planet}}\" }",
+ "php": "return \"{{planet}}\";",
+ "python": "lambda: \"{{planet}}\"",
+ "clojure": "(fn [] \"{{planet}}\")",
+ "lisp": "(lambda () \"{{planet}}\")"
+ }
+ },
+ "template": "Hello, {{lambda}}!",
+ "expected": "Hello, world!"
+ },
+ {
+ "name": "Interpolation - Alternate Delimiters",
+ "desc": "A lambda's return value should parse with the default delimiters.",
+ "data": {
+ "planet": "world",
+ "lambda": {
+ "ruby": "proc { \"|planet| => {{planet}}\" }",
+ "raku": "sub { q+|planet| => {{planet}}+ }",
+ "perl": "sub { \"|planet| => {{planet}}\" }",
+ "js": "function() { return \"|planet| => {{planet}}\" }",
+ "php": "return \"|planet| => {{planet}}\";",
+ "python": "lambda: \"|planet| => {{planet}}\"",
+ "clojure": "(fn [] \"|planet| => {{planet}}\")",
+ "lisp": "(lambda () \"|planet| => {{planet}}\")"
+ }
+ },
+ "template": "{{= | | =}}\nHello, (|&lambda|)!",
+ "expected": "Hello, (|planet| => world)!"
+ },
+ {
+ "name": "Interpolation - Multiple Calls",
+ "desc": "Interpolated lambdas should not be cached.",
+ "data": {
+ "lambda": {
+ "ruby": "proc { $calls ||= 0; $calls += 1 }",
+ "raku": "sub { state $calls += 1 }",
+ "perl": "sub { no strict; $calls += 1 }",
+ "js": "function() { return (g=(function(){return this})()).calls=(g.calls||0)+1 }",
+ "php": "global $calls; return ++$calls;",
+ "python": "lambda: globals().update(calls=globals().get(\"calls\",0)+1) or calls",
+ "clojure": "(def g (atom 0)) (fn [] (swap! g inc))",
+ "lisp": "(let ((g 0)) (lambda () (incf g)))"
+ }
+ },
+ "template": "{{lambda}} == {{{lambda}}} == {{lambda}}",
+ "expected": "1 == 2 == 3"
+ },
+ {
+ "name": "Escaping",
+ "desc": "Lambda results should be appropriately escaped.",
+ "data": {
+ "lambda": {
+ "ruby": "proc { \">\" }",
+ "raku": "sub { \">\" }",
+ "perl": "sub { \">\" }",
+ "js": "function() { return \">\" }",
+ "php": "return \">\";",
+ "python": "lambda: \">\"",
+ "clojure": "(fn [] \">\")",
+ "lisp": "(lambda () \">\")"
+ }
+ },
+ "template": "<{{lambda}}{{{lambda}}}",
+ "expected": "<&gt;>"
+ },
+ {
+ "name": "Section",
+ "desc": "Lambdas used for sections should receive the raw section string.",
+ "data": {
+ "x": "Error!",
+ "lambda": {
+ "ruby": "proc { |text| text == \"{{x}}\" ? \"yes\" : \"no\" }",
+ "raku": "sub { $^section eq q+{{x}}+ ?? \"yes\" !! \"no\" }",
+ "perl": "sub { $_[0] eq \"{{x}}\" ? \"yes\" : \"no\" }",
+ "js": "function(txt) { return (txt == \"{{x}}\" ? \"yes\" : \"no\") }",
+ "php": "return ($text == \"{{x}}\") ? \"yes\" : \"no\";",
+ "python": "lambda text: text == \"{{x}}\" and \"yes\" or \"no\"",
+ "clojure": "(fn [text] (if (= text \"{{x}}\") \"yes\" \"no\"))",
+ "lisp": "(lambda (text) (if (string= text \"{{x}}\") \"yes\" \"no\"))"
+ }
+ },
+ "template": "<{{#lambda}}{{x}}{{/lambda}}>",
+ "expected": "<yes>"
+ },
+ {
+ "name": "Section - Expansion",
+ "desc": "Lambdas used for sections should have their results parsed.",
+ "data": {
+ "planet": "Earth",
+ "lambda": {
+ "ruby": "proc { |text| \"#{text}{{planet}}#{text}\" }",
+ "raku": "sub { $^section ~ q+{{planet}}+ ~ $^section }",
+ "perl": "sub { $_[0] . \"{{planet}}\" . $_[0] }",
+ "js": "function(txt) { return txt + \"{{planet}}\" + txt }",
+ "php": "return $text . \"{{planet}}\" . $text;",
+ "python": "lambda text: \"%s{{planet}}%s\" % (text, text)",
+ "clojure": "(fn [text] (str text \"{{planet}}\" text))",
+ "lisp": "(lambda (text) (format nil \"~a{{planet}}~a\" text text))"
+ }
+ },
+ "template": "<{{#lambda}}-{{/lambda}}>",
+ "expected": "<-Earth->"
+ },
+ {
+ "name": "Section - Alternate Delimiters",
+ "desc": "Lambdas used for sections should parse with the current delimiters.",
+ "data": {
+ "planet": "Earth",
+ "lambda": {
+ "ruby": "proc { |text| \"#{text}{{planet}} => |planet|#{text}\" }",
+ "raku": "sub { $^section ~ q+{{planet}} => |planet|+ ~ $^section }",
+ "perl": "sub { $_[0] . \"{{planet}} => |planet|\" . $_[0] }",
+ "js": "function(txt) { return txt + \"{{planet}} => |planet|\" + txt }",
+ "php": "return $text . \"{{planet}} => |planet|\" . $text;",
+ "python": "lambda text: \"%s{{planet}} => |planet|%s\" % (text, text)",
+ "clojure": "(fn [text] (str text \"{{planet}} => |planet|\" text))",
+ "lisp": "(lambda (text) (format nil \"~a{{planet}} => |planet|~a\" text text))"
+ }
+ },
+ "template": "{{= | | =}}<|#lambda|-|/lambda|>",
+ "expected": "<-{{planet}} => Earth->"
+ },
+ {
+ "name": "Section - Multiple Calls",
+ "desc": "Lambdas used for sections should not be cached.",
+ "data": {
+ "lambda": {
+ "ruby": "proc { |text| \"__#{text}__\" }",
+ "raku": "sub { \"__\" ~ $^section ~ \"__\" }",
+ "perl": "sub { \"__\" . $_[0] . \"__\" }",
+ "js": "function(txt) { return \"__\" + txt + \"__\" }",
+ "php": "return \"__\" . $text . \"__\";",
+ "python": "lambda text: \"__%s__\" % (text)",
+ "clojure": "(fn [text] (str \"__\" text \"__\"))",
+ "lisp": "(lambda (text) (format nil \"__~a__\" text))"
+ }
+ },
+ "template": "{{#lambda}}FILE{{/lambda}} != {{#lambda}}LINE{{/lambda}}",
+ "expected": "__FILE__ != __LINE__"
+ },
+ {
+ "name": "Inverted Section",
+ "desc": "Lambdas used for inverted sections should be considered truthy.",
+ "data": {
+ "static": "static",
+ "lambda": {
+ "ruby": "proc { |text| false }",
+ "raku": "sub { 0 }",
+ "perl": "sub { 0 }",
+ "js": "function(txt) { return false }",
+ "php": "return false;",
+ "python": "lambda text: 0",
+ "clojure": "(fn [text] false)",
+ "lisp": "(lambda (text) (declare (ignore text)) nil)"
+ }
+ },
+ "template": "<{{^lambda}}{{static}}{{/lambda}}>",
+ "expected": "<>"
+ }
+ ]
+}