summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoranomal00us <95467104+anomal00us@users.noreply.github.com>2022-07-20 16:47:05 +0200
committerroot <root@delphi.lan>2022-08-08 21:07:58 +0200
commitc1449c20794609c21794d163a17b97370af67b92 (patch)
tree1a95bb4ff3df1b719b073cd8ccdde46dbb53e7e2
parentb32a4aef1fae82cb08c0b6c8e2e7584ef5ceb12d (diff)
downloadmustache-spec-c1449c20794609c21794d163a17b97370af67b92.tar.gz
Dotted names and context stacking tests
-rw-r--r--specs/~dynamic-names.json109
-rw-r--r--specs/~dynamic-names.yml61
2 files changed, 170 insertions, 0 deletions
diff --git a/specs/~dynamic-names.json b/specs/~dynamic-names.json
index 03f1c7a..c6aade6 100644
--- a/specs/~dynamic-names.json
+++ b/specs/~dynamic-names.json
@@ -49,6 +49,115 @@
"expected": "\"*Hello, world!*\""
},
{
+ "name": "Dotted Names",
+ "desc": "The dynamic partial should operate within the current context.",
+ "data": {
+ "text": "Hello, world!",
+ "foo": {
+ "bar": {
+ "baz": "partial"
+ }
+ }
+ },
+ "template": "\"{{>*foo.bar.baz}}\"",
+ "partials": {
+ "partial": "*{{text}}*"
+ },
+ "expected": "\"*Hello, world!*\""
+ },
+ {
+ "name": "Dotted Names - Failed Lookup",
+ "desc": "The dynamic partial should operate within the current context.",
+ "data": {
+ "text": "Hello, world!",
+ "foo": "test",
+ "test": {
+ "bar": {
+ "baz": "partial"
+ }
+ }
+ },
+ "template": "\"{{>*foo.bar.baz}}\"",
+ "partials": {
+ "partial": "*{{text}}*"
+ },
+ "expected": "\"\""
+ },
+ {
+ "name": "Dotted Names - Failed Lookup",
+ "desc": "The dynamic partial should operate within the current context.",
+ "data": {
+ "foo": {
+ "text": "Hello, world!",
+ "bar": {
+ "baz": "partial"
+ }
+ }
+ },
+ "template": "\"{{>*foo.bar.baz}}\"",
+ "partials": {
+ "partial": "*{{text}}*"
+ },
+ "expected": "\"**\""
+ },
+ {
+ "name": "Dotted names - Context Stacking",
+ "desc": "Dotted names should not push a new frame on the context stack.",
+ "data": {
+ "section1": {
+ "value": "section1"
+ },
+ "section2": {
+ "dynamic": "partial",
+ "value": "section2"
+ }
+ },
+ "template": "{{#section1}}{{>*section2.dynamic}}{{/section1}}",
+ "partials": {
+ "partial": "{{value}}"
+ },
+ "expected": "\"section1\""
+ },
+ {
+ "name": "Dotted names - Context Stacking Under Repetition",
+ "desc": "Dotted names should not push a new frame on the context stack.",
+ "data": {
+ "value": "test",
+ "section1": [
+ 1,
+ 2
+ ],
+ "section2": {
+ "dynamic": "partial",
+ "value": "section2"
+ }
+ },
+ "template": "{{#section1}}{{>*section2.dynamic}}{{/section1}}",
+ "partials": {
+ "partial": "{{value}}"
+ },
+ "expected": "testtest"
+ },
+ {
+ "name": "Dotted names - Context Stacking Failed Lookup",
+ "desc": "Dotted names should resolve against the proper context stack.",
+ "data": {
+ "section1": [
+ 1,
+ 2
+ ],
+ "section2": {
+ "dynamic": "partial",
+ "value": "section2"
+ }
+ },
+ "template": "{{#section1}}{{>*section2.dynamic}}{{/section1}}",
+ "partials": {
+ "partial": "\"{{value}}\""
+ },
+ "expected": "\"\""
+ },
+ {
"name": "Recursion",
"desc": "Dynamic partials should properly recurse.",
"data": {
diff --git a/specs/~dynamic-names.yml b/specs/~dynamic-names.yml
index 5923b13..a74cfc2 100644
--- a/specs/~dynamic-names.yml
+++ b/specs/~dynamic-names.yml
@@ -62,6 +62,67 @@ tests:
partials: { partial: '*{{text}}*' }
expected: '"*Hello, world!*"'
+ - name: Dotted Names
+ desc: The dynamic partial should operate within the current context.
+ data: { text: 'Hello, world!', foo: { bar: { baz: 'partial' } } }
+ template: '"{{>*foo.bar.baz}}"'
+ partials: { partial: '*{{text}}*' }
+ expected: '"*Hello, world!*"'
+
+ - name: Dotted Names - Failed Lookup
+ desc: The dynamic partial should operate within the current context.
+ data:
+ text: 'Hello, world!'
+ foo: 'test'
+ test:
+ bar:
+ baz: 'partial'
+ template: '"{{>*foo.bar.baz}}"'
+ partials: { partial: '*{{text}}*' }
+ expected: '""'
+
+ - name: Dotted Names - Failed Lookup
+ desc: The dynamic partial should operate within the current context.
+ data:
+ foo:
+ text: 'Hello, world!'
+ bar:
+ baz: 'partial'
+ template: '"{{>*foo.bar.baz}}"'
+ partials: { partial: '*{{text}}*' }
+ expected: '"**"'
+
+ - name: Dotted names - Context Stacking
+ desc: Dotted names should not push a new frame on the context stack.
+ data:
+ section1: { value: 'section1' }
+ section2: { dynamic: 'partial', value: 'section2' }
+ template: "{{#section1}}{{>*section2.dynamic}}{{/section1}}"
+ partials:
+ partial: "{{value}}"
+ expected: '"section1"'
+
+ - name: Dotted names - Context Stacking Under Repetition
+ desc: Dotted names should not push a new frame on the context stack.
+ data:
+ value: 'test'
+ section1: [ 1, 2 ]
+ section2: { dynamic: 'partial', value: 'section2' }
+ template: "{{#section1}}{{>*section2.dynamic}}{{/section1}}"
+ partials:
+ partial: "{{value}}"
+ expected: "testtest"
+
+ - name: Dotted names - Context Stacking Failed Lookup
+ desc: Dotted names should resolve against the proper context stack.
+ data:
+ section1: [ 1, 2 ]
+ section2: { dynamic: 'partial', value: 'section2' }
+ template: "{{#section1}}{{>*section2.dynamic}}{{/section1}}"
+ partials:
+ partial: '"{{value}}"'
+ expected: '""'
+
- name: Recursion
desc: Dynamic partials should properly recurse.
data: