summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoranomal00us <95467104+anomal00us@users.noreply.github.com>2022-07-25 20:20:39 +0200
committerroot <root@delphi.lan>2022-08-08 21:08:57 +0200
commit2030fff3d513b93f527711afc7467a89cab88737 (patch)
treef58b2e090de0b98c967f4f81f715660b4d2ea0c6
parent736472c77b398771c711f91e62b4feb05bd7f5ea (diff)
downloadmustache-spec-2030fff3d513b93f527711afc7467a89cab88737.tar.gz
Adding two more tests, updating operator precedence desc + typo fix
-rw-r--r--specs/~dynamic-names.json37
-rw-r--r--specs/~dynamic-names.yml20
2 files changed, 51 insertions, 6 deletions
diff --git a/specs/~dynamic-names.json b/specs/~dynamic-names.json
index 9c80402..194162d 100644
--- a/specs/~dynamic-names.json
+++ b/specs/~dynamic-names.json
@@ -1,5 +1,5 @@
{
- "overview": "Rationale: this special notation was introduced specifically to allow the\ndynamic loading of partials. The main advantage that this new special notation\noffers is to allow dynamic loading of partials, which is particularly useful\nin cases where there needs to be rendered polymorphic data or in cases where\nthere is a child template shared by multiple parent templates; cases which\notherwise would be possible to render only by using either complex (and\noptional) features such as lambdas, or by using solutions that are inefficient\nboth in terms of space and in terms of computational efficiency, such as:\noverloading the template with if blocks or preprocessing the template.\n\nDynamic Names are a special notation to dynamically determine a tag's content.\n\nDynamic Names MUST be a non-whitespace character sequence NOT containing\nthe current closing delimiter. A Dynamic Name consists of an asterisk,\nfollowed by a dotted name. The latter follows the same notation as in an\nInterpolation tag.\n\nThis tag's dotted name, which is equal to the Dynamic Name excluding the\nleading asterisk, refers to a key in the context whose value will be used in\nplace of the Dynamic Name itself as content of the tag. The dotted name\nresolution produces the same value as an Interpolation tag and does not affect\nthe context for further processing.\n\nSet Delimiter tags MUST NOT affect the resolution of a Dynamic Name. The\nDynamic Names MUST be resolved against the context stack local to the tag.\nFailed resolution of the dynamic name should result in nothing being rendered.\n\nEngines that implement Dynamic Names MUST support their use in Partial tags.\nIn engines that also implement the optional inheritance spec, Dynamic Names\ninside Parent tags should be supported as well. Dynamic Names cannot be\nresolved more than once (Dynamic Names cannot be nested).\n",
+ "overview": "Rationale: this special notation was introduced specifically to allow the\ndynamic loading of partials. The main advantage that this notation\noffers is to allow dynamic loading of partials, which is particularly useful\nin cases where polymorphic data needs to be rendered, or in cases where\na child template is shared by multiple parent templates; cases which\notherwise would be possible to render only by using either complex (and\noptional) features such as lambdas, or by using solutions that are inefficient\nboth in terms of space and in terms of computational efficiency, such as:\noverloading the template with if blocks or preprocessing the template.\n\nDynamic Names are a special notation to dynamically determine a tag's content.\n\nDynamic Names MUST be a non-whitespace character sequence NOT containing\nthe current closing delimiter. A Dynamic Name consists of an asterisk,\nfollowed by a dotted name. The dotted name follows the same notation as in an\nInterpolation tag.\n\nThis tag's dotted name, which is the Dynamic Name excluding the\nleading asterisk, references a key in the context whose value will be used in\nplace of the Dynamic Name itself as content of the tag. The dotted name\nresolution produces the same value as an Interpolation tag and does not affect\nthe context for further processing.\n\nSet Delimiter tags MUST NOT affect the resolution of a Dynamic Name. The\nDynamic Names MUST be resolved against the context stack local to the tag.\nFailed resolution of the dynamic name SHOULD result in nothing being rendered.\n\nEngines that implement Dynamic Names MUST support their use in Partial tags.\nIn engines that also implement the optional inheritance spec, Dynamic Names\ninside Parent tags SHOULD be supported as well. Dynamic Names cannot be\nresolved more than once (Dynamic Names cannot be nested).\n",
"tests": [
{
"name": "Basic Behavior - Partial",
@@ -15,7 +15,7 @@
},
{
"name": "Basic Behavior - Name Resolution",
- "desc": "The asterisk is not part of the name that will be resolved in the contex.\n",
+ "desc": "The asterisk is not part of the name that will be resolved in the context.\n",
"data": {
"dynamic": "content",
"*dynamic": "wrong"
@@ -81,7 +81,7 @@
},
{
"name": "Dotted Names - Operator Precedence",
- "desc": "The dynamic partial should operate within the current context.",
+ "desc": "The dotted name should be resolved entirely before being dereferenced.",
"data": {
"text": "Hello, world!",
"foo": "test",
@@ -191,6 +191,37 @@
"expected": "X<Y<>>"
},
{
+ "name": "Dynamic Names - Dobule Dereferencing",
+ "desc": "Dynamic Names can't be dereferenced more than once.",
+ "data": {
+ "dynamic": "test",
+ "test": "content"
+ },
+ "template": "\"{{>**dynamic}}\"",
+ "partials": {
+ "content": "Hello, world!"
+ },
+ "expected": "\"\""
+ },
+ {
+ "name": "Dynamic Names - Composed Dereferencing",
+ "desc": "Dynamic Names cannot have composed dereferencing.",
+ "data": {
+ "foo": "fizz",
+ "bar": "buzz",
+ "fizz": {
+ "buzz": {
+ "content": null
+ }
+ }
+ },
+ "template": "\"{{>*foo.*bar}}\"",
+ "partials": {
+ "content": "Hello, world!"
+ },
+ "expected": "\"\""
+ },
+ {
"name": "Surrounding Whitespace",
"desc": "A dynamic partial should not alter surrounding whitespace; any\nwhitespace preceding the tag should be treated as indentation while any\nwhitespace succeding the tag should be left untouched.\n",
"data": {
diff --git a/specs/~dynamic-names.yml b/specs/~dynamic-names.yml
index a1177e7..d60ef2b 100644
--- a/specs/~dynamic-names.yml
+++ b/specs/~dynamic-names.yml
@@ -13,7 +13,7 @@ overview: |
Dynamic Names MUST be a non-whitespace character sequence NOT containing
the current closing delimiter. A Dynamic Name consists of an asterisk,
- followed by a dotted name. The latter follows the same notation as in an
+ followed by a dotted name. The dotted name follows the same notation as in an
Interpolation tag.
This tag's dotted name, which is the Dynamic Name excluding the
@@ -41,7 +41,7 @@ tests:
- name: Basic Behavior - Name Resolution
desc: |
- The asterisk is not part of the name that will be resolved in the contex.
+ The asterisk is not part of the name that will be resolved in the context.
data: { dynamic: 'content', '*dynamic': 'wrong' }
template: '"{{>*dynamic}}"'
partials: { content: 'Hello, world!', wrong: 'Invisible' }
@@ -76,7 +76,7 @@ tests:
expected: '"*Hello, world!*"'
- name: Dotted Names - Operator Precedence
- desc: The dynamic partial should operate within the current context.
+ desc: The dotted name should be resolved entirely before being dereferenced.
data:
text: 'Hello, world!'
foo: 'test'
@@ -139,6 +139,20 @@ tests:
partials: { node: '{{content}}<{{#nodes}}{{>*template}}{{/nodes}}>' }
expected: 'X<Y<>>'
+ - name: Dynamic Names - Dobule Dereferencing
+ desc: Dynamic Names can't be dereferenced more than once.
+ data: { dynamic: 'test', 'test': 'content' }
+ template: '"{{>**dynamic}}"'
+ partials: { content: 'Hello, world!' }
+ expected: '""'
+
+ - name: Dynamic Names - Composed Dereferencing
+ desc: Dynamic Names cannot have composed dereferencing.
+ data: { foo: 'fizz', bar: 'buzz', fizz: { buzz: { 'content' } } }
+ template: '"{{>*foo.*bar}}"'
+ partials: { content: 'Hello, world!' }
+ expected: '""'
+
# Whitespace Sensitivity
- name: Surrounding Whitespace