From f5b2e9d722fe159a39860c65ab1bfbe7ccd3ee7e Mon Sep 17 00:00:00 2001 From: Chris Jerdonek Date: Sun, 29 Apr 2012 00:09:32 -0700 Subject: [PATCH 1/3] Added two tests that lambdas short-circuit the section rendering rules. --- specs/~lambdas.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/specs/~lambdas.yml b/specs/~lambdas.yml index b9fb4d0..bc82529 100644 --- a/specs/~lambdas.yml +++ b/specs/~lambdas.yml @@ -107,6 +107,28 @@ tests: template: "<{{#lambda}}-{{/lambda}}>" expected: "<-Earth->" + - name: Section - Context Stack + desc: | + Lambdas used for sections should not be pushed onto the context + stack before rendering their return value. + data: + planet: "Earth" + star: "Sun" + lambda: !code + python: 'lambda text: "~{{star}} %s {{.}}~" % text' + template: "<{{#planet}}{{#lambda}}&{{/lambda}}{{/planet}}>" + expected: "<~Sun & Earth~>" + + - name: Section - No Re-interpolation + desc: The lambda return value should not be re-interpolated. + data: + planet: "Earth" + dot: "{{.}}" + lambda: !code + python: 'lambda text: "{{%s}}" % text' + template: "<{{#planet}}{{#lambda}}dot{{/lambda}}{{/planet}}>" + expected: "<{{.}}>" + - name: Section - Alternate Delimiters desc: Lambdas used for sections should parse with the current delimiters. data: From 266747ac839d736f802b73bfda1c4217b3b852d5 Mon Sep 17 00:00:00 2001 From: Chris Jerdonek Date: Sun, 29 Apr 2012 02:16:27 -0700 Subject: [PATCH 2/3] Improved "Section - No Re-interpolation" test: This change strengthens the test case. In the previous version, if the string "{{.}}" was on the top of the context stack, the test could conceivably have passed with certain versions of bad code. --- specs/~lambdas.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/specs/~lambdas.yml b/specs/~lambdas.yml index bc82529..eb9387c 100644 --- a/specs/~lambdas.yml +++ b/specs/~lambdas.yml @@ -123,11 +123,11 @@ tests: desc: The lambda return value should not be re-interpolated. data: planet: "Earth" - dot: "{{.}}" + dot: "#{{.}}#" lambda: !code - python: 'lambda text: "{{%s}}" % text' + python: 'lambda text: "~{{%s}}~" % text' template: "<{{#planet}}{{#lambda}}dot{{/lambda}}{{/planet}}>" - expected: "<{{.}}>" + expected: "<~#{{.}}#~>" - name: Section - Alternate Delimiters desc: Lambdas used for sections should parse with the current delimiters. From 493283cb9904cbe8ba8a6cea7efe01b494dc65f1 Mon Sep 17 00:00:00 2001 From: Chris Jerdonek Date: Sun, 29 Apr 2012 08:26:44 -0700 Subject: [PATCH 3/3] Added a test that elements of a list of lambdas should each have their results parsed. --- specs/~lambdas.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/specs/~lambdas.yml b/specs/~lambdas.yml index eb9387c..41e09cb 100644 --- a/specs/~lambdas.yml +++ b/specs/~lambdas.yml @@ -107,6 +107,18 @@ tests: template: "<{{#lambda}}-{{/lambda}}>" expected: "<-Earth->" + - name: Section - Expansion of List Elements + desc: Lambdas used for sections in a list should each have their results parsed. + data: + planet: "Earth" + lambdas: + - !code + python: 'lambda text: "~{{%s}}~" % text' + - !code + python: 'lambda text: "#{{%s}}#" % text' + template: "<{{#lambdas}}planet{{/lambdas}}>" + expected: "<~Earth~#Earth#>" + - name: Section - Context Stack desc: | Lambdas used for sections should not be pushed onto the context