From aad6725ea0ca928c50bde433a953fa094d1fd5e7 Mon Sep 17 00:00:00 2001 From: Julian Gonggrijp Date: Mon, 19 Apr 2021 01:44:47 +0200 Subject: Specify how to interpolate null (#101) --- specs/interpolation.json | 27 +++++++++++++++++++++++++++ specs/interpolation.yml | 18 ++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/specs/interpolation.json b/specs/interpolation.json index 1718e1c..d422dc3 100644 --- a/specs/interpolation.json +++ b/specs/interpolation.json @@ -100,6 +100,33 @@ "template": "\"{{&power}} jiggawatts!\"", "expected": "\"1.21 jiggawatts!\"" }, + { + "name": "Basic Null Interpolation", + "desc": "Nulls should interpolate as the empty string.", + "data": { + "cannot": null + }, + "template": "I ({{cannot}}) be seen!", + "expected": "I () be seen!" + }, + { + "name": "Triple Mustache Null Interpolation", + "desc": "Nulls should interpolate as the empty string.", + "data": { + "cannot": null + }, + "template": "I ({{{cannot}}}) be seen!", + "expected": "I () be seen!" + }, + { + "name": "Ampersand Null Interpolation", + "desc": "Nulls should interpolate as the empty string.", + "data": { + "cannot": null + }, + "template": "I ({{&cannot}}) be seen!", + "expected": "I () be seen!" + }, { "name": "Basic Context Miss Interpolation", "desc": "Failed context lookups should default to empty strings.", diff --git a/specs/interpolation.yml b/specs/interpolation.yml index 1b6fff1..9410a30 100644 --- a/specs/interpolation.yml +++ b/specs/interpolation.yml @@ -101,6 +101,24 @@ tests: template: '"{{&power}} jiggawatts!"' expected: '"1.21 jiggawatts!"' + - name: Basic Null Interpolation + desc: Nulls should interpolate as the empty string. + data: { cannot: null } + template: "I ({{cannot}}) be seen!" + expected: "I () be seen!" + + - name: Triple Mustache Null Interpolation + desc: Nulls should interpolate as the empty string. + data: { cannot: null } + template: "I ({{{cannot}}}) be seen!" + expected: "I () be seen!" + + - name: Ampersand Null Interpolation + desc: Nulls should interpolate as the empty string. + data: { cannot: null } + template: "I ({{&cannot}}) be seen!" + expected: "I () be seen!" + # Context Misses - name: Basic Context Miss Interpolation -- cgit v1.2.1 From 300984b04c0c1efafc75f4dcf7f7af5b64952882 Mon Sep 17 00:00:00 2001 From: Julian Gonggrijp Date: Fri, 23 Apr 2021 12:50:36 +0200 Subject: Specify null handling in (inverted) sections (@Danappelxx comment #123) --- specs/inverted.json | 9 +++++++++ specs/inverted.yml | 6 ++++++ specs/sections.json | 9 +++++++++ specs/sections.yml | 6 ++++++ 4 files changed, 30 insertions(+) diff --git a/specs/inverted.json b/specs/inverted.json index d9a7c15..5e881d1 100644 --- a/specs/inverted.json +++ b/specs/inverted.json @@ -20,6 +20,15 @@ "template": "\"{{^boolean}}This should not be rendered.{{/boolean}}\"", "expected": "\"\"" }, + { + "name": "Null is falsey", + "desc": "Null is falsey.", + "data": { + "null": null + }, + "template": "\"{{^null}}This should be rendered.{{/null}}\"", + "expected": "\"This should be rendered.\"" + }, { "name": "Context", "desc": "Objects and hashes should behave like truthy values.", diff --git a/specs/inverted.yml b/specs/inverted.yml index 5f8e2b2..148b3f5 100644 --- a/specs/inverted.yml +++ b/specs/inverted.yml @@ -46,6 +46,12 @@ tests: template: '"{{^boolean}}This should not be rendered.{{/boolean}}"' expected: '""' + - name: Null is falsey + desc: Null is falsey. + data: { "null": null } + template: '"{{^null}}This should be rendered.{{/null}}"' + expected: '"This should be rendered."' + - name: Context desc: Objects and hashes should behave like truthy values. data: { context: { name: 'Joe' } } diff --git a/specs/sections.json b/specs/sections.json index 73eb2a4..3acc414 100644 --- a/specs/sections.json +++ b/specs/sections.json @@ -20,6 +20,15 @@ "template": "\"{{#boolean}}This should not be rendered.{{/boolean}}\"", "expected": "\"\"" }, + { + "name": "Null is falsey", + "desc": "Null is falsey.", + "data": { + "null": null + }, + "template": "\"{{#null}}This should not be rendered.{{/null}}\"", + "expected": "\"\"" + }, { "name": "Context", "desc": "Objects and hashes should be pushed onto the context stack.", diff --git a/specs/sections.yml b/specs/sections.yml index 40021c0..fdfd799 100644 --- a/specs/sections.yml +++ b/specs/sections.yml @@ -47,6 +47,12 @@ tests: template: '"{{#boolean}}This should not be rendered.{{/boolean}}"' expected: '""' + - name: Null is falsey + desc: Null is falsey. + data: { "null": null } + template: '"{{#null}}This should not be rendered.{{/null}}"' + expected: '""' + - name: Context desc: Objects and hashes should be pushed onto the context stack. data: { context: { name: 'Joe' } } -- cgit v1.2.1