summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPieter van de Bruggen <pvande@gmail.com>2011-02-24 16:45:57 -0800
committerPieter van de Bruggen <pvande@gmail.com>2011-02-24 16:45:57 -0800
commitf6cadccc777d8f9bda86826f3dd213723e64b0fc (patch)
tree971fe98bb4cf4e2381b5432db8fab79e230c0a40
parentd833e98c6a98b58231c181b831a22e2de6453cc5 (diff)
downloadmustache-spec-f6cadccc777d8f9bda86826f3dd213723e64b0fc.tar.gz
Interpolated lambdas are no longer expected to be cached.
This should make implementing lambda support quite a bit simpler.
-rw-r--r--specs/~lambdas.json2
-rw-r--r--specs/~lambdas.yml31
2 files changed, 9 insertions, 24 deletions
diff --git a/specs/~lambdas.json b/specs/~lambdas.json
index b4246f6..a30d082 100644
--- a/specs/~lambdas.json
+++ b/specs/~lambdas.json
@@ -1 +1 @@
-{"__ATTN__":"Do not edit this file; changes belong in the appropriate YAML file.","tests":[{"name":"Interpolation","data":{"lambda":{"php":"return \"world\";","__tag__":"code","perl":"sub { \"world\" }","python":"lambda: \"world\"","ruby":"proc { \"world\" }","js":"function() { return \"world\" }"}},"expected":"Hello, world!","template":"Hello, {{lambda}}!","desc":"A lambda's return value should be interpolated."},{"name":"Interpolation - Expansion","data":{"planet":"world","lambda":{"php":"return \"{{planet}}\";","__tag__":"code","perl":"sub { \"{{planet}}\" }","python":"lambda: \"{{planet}}\"","ruby":"proc { \"{{planet}}\" }","js":"function() { return \"{{planet}}\" }"}},"expected":"Hello, world!","template":"Hello, {{lambda}}!","desc":"A lambda's return value should be parsed."},{"name":"Interpolation - Multiple Calls","data":{"lambda":{"php":"global $calls; return ++$calls;","__tag__":"code","perl":"sub { no strict; $calls += 1 }","python":"lambda: globals().update(calls=globals().get(\"calls\",0)+1) or calls","ruby":"proc { $calls ||= 0; $calls += 1 }","js":"function() { f = arguments.callee; return f.calls = (f.calls || 0) + 1 }"}},"expected":"1 == 1 == 1","template":"{{lambda}} == {{{lambda}}} == {{lambda}}","desc":"Interpolated lambdas should only be called once."},{"name":"Interpolation - Caches","data":{"context":{"lambda":{"php":"return \"Big\";","__tag__":"code","perl":"sub { \"Big\" }","python":"lambda: \"Big\"","ruby":"proc { \"Big\" }","js":"function() { return \"Big\" }"},"key":"Under"},"key":"Top"},"expected":"Under the Big Top","template":"{{#context}}{{key}} the {{lambda}}{{/context}} {{key}}","desc":"Lambda caches should not disrupt normal context operations."},{"name":"Escaping","data":{"lambda":{"php":"return \">\";","__tag__":"code","perl":"sub { \">\" }","python":"lambda: \">\"","ruby":"proc { \">\" }","js":"function() { return \">\" }"}},"expected":"<&gt;>","template":"<{{lambda}}{{{lambda}}}","desc":"Lambda results should be appropriately escaped."},{"name":"Section","data":{"x":"Error!","lambda":{"php":"return ($text == \"{{x}}\") ? \"yes\" : \"no\";","__tag__":"code","perl":"sub { $_[0] eq \"{{x}}\" ? \"yes\" : \"no\" }","python":"lambda text: text == \"{{x}}\" and \"yes\" or \"no\"","ruby":"proc { |text| text == \"{{x}}\" ? \"yes\" : \"no\" }","js":"function(txt) { return (txt == \"{{x}}\" ? \"yes\" : \"no\") }"}},"expected":"<yes>","template":"<{{#lambda}}{{x}}{{/lambda}}>","desc":"Lambdas used for sections should receive the raw section string."},{"name":"Section - Expansion","data":{"planet":"Earth","lambda":{"php":"return $text . \"{{planet}}\" . $text;","__tag__":"code","perl":"sub { $_[0] . \"{{planet}}\" . $_[0] }","python":"lambda text: \"%s{{planet}}%s\" % (text, text)","ruby":"proc { |text| \"#{text}{{planet}}#{text}\" }","js":"function(txt) { return txt + \"{{planet}}\" + txt }"}},"expected":"<-Earth->","template":"<{{#lambda}}-{{/lambda}}>","desc":"Lambdas used for sections should have their results parsed."},{"name":"Section - Multiple Calls","data":{"lambda":{"php":"return \"__\" . $text . \"__\";","__tag__":"code","perl":"sub { \"__\" . $_[0] . \"__\" }","python":"lambda text: \"__%s__\" % (text)","ruby":"proc { |text| \"__#{text}__\" }","js":"function(txt) { return \"__\" + txt + \"__\" }"}},"expected":"__FILE__ != __LINE__","template":"{{#lambda}}FILE{{/lambda}} != {{#lambda}}LINE{{/lambda}}","desc":"Lambdas used for sections should not simply cache the first response."},{"name":"Inverted Section","data":{"static":"static","lambda":{"php":"return $text;","__tag__":"code","perl":"sub { shift }","python":"lambda text: text","ruby":"proc { |text| text }","js":"function(txt) { return txt }"}},"expected":"<>","template":"<{{^lambda}}{{static}}{{/lambda}}>","desc":"Lambdas used for inverted sections should be considered truthy."}]} \ No newline at end of file
+{"__ATTN__":"Do not edit this file; changes belong in the appropriate YAML file.","tests":[{"name":"Interpolation","data":{"lambda":{"php":"return \"world\";","__tag__":"code","perl":"sub { \"world\" }","python":"lambda: \"world\"","ruby":"proc { \"world\" }","js":"function() { return \"world\" }"}},"expected":"Hello, world!","template":"Hello, {{lambda}}!","desc":"A lambda's return value should be interpolated."},{"name":"Interpolation - Expansion","data":{"planet":"world","lambda":{"php":"return \"{{planet}}\";","__tag__":"code","perl":"sub { \"{{planet}}\" }","python":"lambda: \"{{planet}}\"","ruby":"proc { \"{{planet}}\" }","js":"function() { return \"{{planet}}\" }"}},"expected":"Hello, world!","template":"Hello, {{lambda}}!","desc":"A lambda's return value should be parsed."},{"name":"Interpolation - Multiple Calls","data":{"lambda":{"php":"global $calls; return ++$calls;","__tag__":"code","perl":"sub { no strict; $calls += 1 }","python":"lambda: globals().update(calls=globals().get(\"calls\",0)+1) or calls","ruby":"proc { $calls ||= 0; $calls += 1 }","js":"function() { f = arguments.callee; return f.calls = (f.calls || 0) + 1 }"}},"expected":"1 == 2 == 3","template":"{{lambda}} == {{{lambda}}} == {{lambda}}","desc":"Interpolated lambdas should not be cached."},{"name":"Escaping","data":{"lambda":{"php":"return \">\";","__tag__":"code","perl":"sub { \">\" }","python":"lambda: \">\"","ruby":"proc { \">\" }","js":"function() { return \">\" }"}},"expected":"<&gt;>","template":"<{{lambda}}{{{lambda}}}","desc":"Lambda results should be appropriately escaped."},{"name":"Section","data":{"x":"Error!","lambda":{"php":"return ($text == \"{{x}}\") ? \"yes\" : \"no\";","__tag__":"code","perl":"sub { $_[0] eq \"{{x}}\" ? \"yes\" : \"no\" }","python":"lambda text: text == \"{{x}}\" and \"yes\" or \"no\"","ruby":"proc { |text| text == \"{{x}}\" ? \"yes\" : \"no\" }","js":"function(txt) { return (txt == \"{{x}}\" ? \"yes\" : \"no\") }"}},"expected":"<yes>","template":"<{{#lambda}}{{x}}{{/lambda}}>","desc":"Lambdas used for sections should receive the raw section string."},{"name":"Section - Expansion","data":{"planet":"Earth","lambda":{"php":"return $text . \"{{planet}}\" . $text;","__tag__":"code","perl":"sub { $_[0] . \"{{planet}}\" . $_[0] }","python":"lambda text: \"%s{{planet}}%s\" % (text, text)","ruby":"proc { |text| \"#{text}{{planet}}#{text}\" }","js":"function(txt) { return txt + \"{{planet}}\" + txt }"}},"expected":"<-Earth->","template":"<{{#lambda}}-{{/lambda}}>","desc":"Lambdas used for sections should have their results parsed."},{"name":"Section - Multiple Calls","data":{"lambda":{"php":"return \"__\" . $text . \"__\";","__tag__":"code","perl":"sub { \"__\" . $_[0] . \"__\" }","python":"lambda text: \"__%s__\" % (text)","ruby":"proc { |text| \"__#{text}__\" }","js":"function(txt) { return \"__\" + txt + \"__\" }"}},"expected":"__FILE__ != __LINE__","template":"{{#lambda}}FILE{{/lambda}} != {{#lambda}}LINE{{/lambda}}","desc":"Lambdas used for sections should not be cached."},{"name":"Inverted Section","data":{"static":"static","lambda":{"php":"return false;","__tag__":"code","perl":"sub { 0 }","python":"lambda text: 0","ruby":"proc { |text| false }","js":"function(txt) { return false }"}},"expected":"<>","template":"<{{^lambda}}{{static}}{{/lambda}}>","desc":"Lambdas used for inverted sections should be considered truthy."}]} \ No newline at end of file
diff --git a/specs/~lambdas.yml b/specs/~lambdas.yml
index 5b50ff0..1e7922a 100644
--- a/specs/~lambdas.yml
+++ b/specs/~lambdas.yml
@@ -25,7 +25,7 @@ tests:
expected: "Hello, world!"
- name: Interpolation - Multiple Calls
- desc: Interpolated lambdas should only be called once.
+ desc: Interpolated lambdas should not be cached.
data:
lambda: !code
ruby: 'proc { $calls ||= 0; $calls += 1 }'
@@ -34,22 +34,7 @@ tests:
php: 'global $calls; return ++$calls;'
python: 'lambda: globals().update(calls=globals().get("calls",0)+1) or calls'
template: '{{lambda}} == {{{lambda}}} == {{lambda}}'
- expected: '1 == 1 == 1'
-
- - name: Interpolation - Caches
- desc: Lambda caches should not disrupt normal context operations.
- data:
- key: Top
- context:
- key: Under
- lambda: !code
- ruby: 'proc { "Big" }'
- perl: 'sub { "Big" }'
- js: 'function() { return "Big" }'
- php: 'return "Big";'
- python: 'lambda: "Big"'
- template: "{{#context}}{{key}} the {{lambda}}{{/context}} {{key}}"
- expected: "Under the Big Top"
+ expected: '1 == 2 == 3'
- name: Escaping
desc: Lambda results should be appropriately escaped.
@@ -90,7 +75,7 @@ tests:
expected: "<-Earth->"
- name: Section - Multiple Calls
- desc: Lambdas used for sections should not simply cache the first response.
+ desc: Lambdas used for sections should not be cached.
data:
lambda: !code
ruby: 'proc { |text| "__#{text}__" }'
@@ -106,10 +91,10 @@ tests:
data:
static: 'static'
lambda: !code
- ruby: 'proc { |text| text }'
- perl: 'sub { shift }'
- js: 'function(txt) { return txt }'
- php: 'return $text;'
- python: 'lambda text: text'
+ ruby: 'proc { |text| false }'
+ perl: 'sub { 0 }'
+ js: 'function(txt) { return false }'
+ php: 'return false;'
+ python: 'lambda text: 0'
template: "<{{^lambda}}{{static}}{{/lambda}}>"
expected: "<>"