diff options
author | Pieter van de Bruggen <pvande@gmail.com> | 2011-05-23 19:38:03 -0700 |
---|---|---|
committer | Pieter van de Bruggen <pvande@gmail.com> | 2011-05-23 19:38:03 -0700 |
commit | 42b950425c1e8cef46d829128e32a6eda492e593 (patch) | |
tree | faaa685db9cd06c1fd52d81c7506e4ec38fc649e | |
parent | bf6288ed6bd0ce8ccea6f1dac070b3d779132c3b (diff) | |
parent | fcec43bca9bb41cb460a34459a21a59630b2ca4b (diff) | |
download | mustache-spec-42b950425c1e8cef46d829128e32a6eda492e593.tar.gz |
Merge remote-tracking branch 'davidsantiago/master'
-rw-r--r-- | specs/~lambdas.json | 2 | ||||
-rw-r--r-- | specs/~lambdas.yml | 110 |
2 files changed, 61 insertions, 51 deletions
diff --git a/specs/~lambdas.json b/specs/~lambdas.json index eac6429..3c58bf8 100644 --- a/specs/~lambdas.json +++ b/specs/~lambdas.json @@ -1 +1 @@ -{"__ATTN__":"Do not edit this file; changes belong in the appropriate YAML file.","overview":"Lambdas are a special-cased data type for use in interpolations and\nsections.\n\nWhen used as the data value for an Interpolation tag, the lambda MUST be\ntreatable as an arity 0 function, and invoked as such. The returned value\nMUST be rendered, then interpolated in place of the lambda.\n\nWhen used as the data value for a Section tag, the lambda MUST be treatable\nas an arity 1 function, and invoked as such (passing a String containing the\nunprocessed section contents). The returned value MUST be rendered, then\ninterpolated in place of the section.\n","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() { return (g=(function(){return this})()).calls=(g.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":"<>>","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 +{"__ATTN__":"Do not edit this file; changes belong in the appropriate YAML file.","overview":"Lambdas are a special-cased data type for use in interpolations and\nsections.\n\nWhen used as the data value for an Interpolation tag, the lambda MUST be\ntreatable as an arity 0 function, and invoked as such. The returned value\nMUST be rendered against the default delimiters, then interpolated in place\nof the lambda.\n\nWhen used as the data value for a Section tag, the lambda MUST be treatable\nas an arity 1 function, and invoked as such (passing a String containing the\nunprocessed section contents). The returned value MUST be rendered against\nthe current delimiters, then interpolated in place of the section.\n","tests":[{"name":"Interpolation","data":{"lambda":{"php":"return \"world\";","clojure":"(fn [] \"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}}\";","clojure":"(fn [] \"{{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 - Alternate Delimiters","data":{"planet":"world","lambda":{"php":"return \"|planet| => {{planet}}\";","clojure":"(fn [] \"|planet| => {{planet}}\")","__tag__":"code","perl":"sub { \"|planet| => {{planet}}\" }","python":"lambda: \"|planet| => {{planet}}\"","ruby":"proc { \"|planet| => {{planet}}\" }","js":"function() { return \"|planet| => {{planet}}\" }"}},"expected":"Hello, (|planet| => world)!","template":"{{= | | =}}\nHello, (|&lambda|)!","desc":"A lambda's return value should parse with the default delimiters."},{"name":"Interpolation - Multiple Calls","data":{"lambda":{"php":"global $calls; return ++$calls;","clojure":"(def g (atom 0)) (fn [] (swap! g inc))","__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() { return (g=(function(){return this})()).calls=(g.calls||0)+1 }"}},"expected":"1 == 2 == 3","template":"{{lambda}} == {{{lambda}}} == {{lambda}}","desc":"Interpolated lambdas should not be cached."},{"name":"Escaping","data":{"lambda":{"php":"return \">\";","clojure":"(fn [] \">\")","__tag__":"code","perl":"sub { \">\" }","python":"lambda: \">\"","ruby":"proc { \">\" }","js":"function() { return \">\" }"}},"expected":"<>>","template":"<{{lambda}}{{{lambda}}}","desc":"Lambda results should be appropriately escaped."},{"name":"Section","data":{"x":"Error!","lambda":{"php":"return ($text == \"{{x}}\") ? \"yes\" : \"no\";","clojure":"(fn [text] (if (= 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;","clojure":"(fn [text] (str 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 - Alternate Delimiters","data":{"planet":"Earth","lambda":{"php":"return $text . \"{{planet}} => |planet|\" . $text;","clojure":"(fn [text] (str text \"{{planet}} => |planet|\" text))","__tag__":"code","perl":"sub { $_[0] . \"{{planet}} => |planet|\" . $_[0] }","python":"lambda text: \"%s{{planet}} => |planet|%s\" % (text, text)","ruby":"proc { |text| \"#{text}{{planet}} => |planet|#{text}\" }","js":"function(txt) { return txt + \"{{planet}} => |planet|\" + txt }"}},"expected":"<-{{planet}} => Earth->","template":"{{= | | =}}<|#lambda|-|/lambda|>","desc":"Lambdas used for sections should parse with the current delimiters."},{"name":"Section - Multiple Calls","data":{"lambda":{"php":"return \"__\" . $text . \"__\";","clojure":"(fn [text] (str \"__\" 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;","clojure":"(fn [text] 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 e0e9bf3..b9fb4d0 100644 --- a/specs/~lambdas.yml +++ b/specs/~lambdas.yml @@ -16,11 +16,12 @@ tests: desc: A lambda's return value should be interpolated. data: lambda: !code - ruby: 'proc { "world" }' - perl: 'sub { "world" }' - js: 'function() { return "world" }' - php: 'return "world";' - python: 'lambda: "world"' + ruby: 'proc { "world" }' + perl: 'sub { "world" }' + js: 'function() { return "world" }' + php: 'return "world";' + python: 'lambda: "world"' + clojure: '(fn [] "world")' template: "Hello, {{lambda}}!" expected: "Hello, world!" @@ -29,11 +30,12 @@ tests: data: planet: "world" lambda: !code - ruby: 'proc { "{{planet}}" }' - perl: 'sub { "{{planet}}" }' - js: 'function() { return "{{planet}}" }' - php: 'return "{{planet}}";' - python: 'lambda: "{{planet}}"' + ruby: 'proc { "{{planet}}" }' + perl: 'sub { "{{planet}}" }' + js: 'function() { return "{{planet}}" }' + php: 'return "{{planet}}";' + python: 'lambda: "{{planet}}"' + clojure: '(fn [] "{{planet}}")' template: "Hello, {{lambda}}!" expected: "Hello, world!" @@ -42,11 +44,12 @@ tests: data: planet: "world" lambda: !code - ruby: 'proc { "|planet| => {{planet}}" }' - perl: 'sub { "|planet| => {{planet}}" }' - js: 'function() { return "|planet| => {{planet}}" }' - php: 'return "|planet| => {{planet}}";' - python: 'lambda: "|planet| => {{planet}}"' + ruby: 'proc { "|planet| => {{planet}}" }' + perl: 'sub { "|planet| => {{planet}}" }' + js: 'function() { return "|planet| => {{planet}}" }' + php: 'return "|planet| => {{planet}}";' + python: 'lambda: "|planet| => {{planet}}"' + clojure: '(fn [] "|planet| => {{planet}}")' template: "{{= | | =}}\nHello, (|&lambda|)!" expected: "Hello, (|planet| => world)!" @@ -54,11 +57,12 @@ tests: desc: Interpolated lambdas should not be cached. data: lambda: !code - ruby: 'proc { $calls ||= 0; $calls += 1 }' - perl: 'sub { no strict; $calls += 1 }' - js: 'function() { return (g=(function(){return this})()).calls=(g.calls||0)+1 }' - php: 'global $calls; return ++$calls;' - python: 'lambda: globals().update(calls=globals().get("calls",0)+1) or calls' + ruby: 'proc { $calls ||= 0; $calls += 1 }' + perl: 'sub { no strict; $calls += 1 }' + js: 'function() { return (g=(function(){return this})()).calls=(g.calls||0)+1 }' + php: 'global $calls; return ++$calls;' + python: 'lambda: globals().update(calls=globals().get("calls",0)+1) or calls' + clojure: '(def g (atom 0)) (fn [] (swap! g inc))' template: '{{lambda}} == {{{lambda}}} == {{lambda}}' expected: '1 == 2 == 3' @@ -66,11 +70,12 @@ tests: desc: Lambda results should be appropriately escaped. data: lambda: !code - ruby: 'proc { ">" }' - perl: 'sub { ">" }' - js: 'function() { return ">" }' - php: 'return ">";' - python: 'lambda: ">"' + ruby: 'proc { ">" }' + perl: 'sub { ">" }' + js: 'function() { return ">" }' + php: 'return ">";' + python: 'lambda: ">"' + clojure: '(fn [] ">")' template: "<{{lambda}}{{{lambda}}}" expected: "<>>" @@ -79,11 +84,12 @@ tests: data: x: 'Error!' lambda: !code - ruby: 'proc { |text| text == "{{x}}" ? "yes" : "no" }' - perl: 'sub { $_[0] eq "{{x}}" ? "yes" : "no" }' - js: 'function(txt) { return (txt == "{{x}}" ? "yes" : "no") }' - php: 'return ($text == "{{x}}") ? "yes" : "no";' - python: 'lambda text: text == "{{x}}" and "yes" or "no"' + ruby: 'proc { |text| text == "{{x}}" ? "yes" : "no" }' + perl: 'sub { $_[0] eq "{{x}}" ? "yes" : "no" }' + js: 'function(txt) { return (txt == "{{x}}" ? "yes" : "no") }' + php: 'return ($text == "{{x}}") ? "yes" : "no";' + python: 'lambda text: text == "{{x}}" and "yes" or "no"' + clojure: '(fn [text] (if (= text "{{x}}") "yes" "no"))' template: "<{{#lambda}}{{x}}{{/lambda}}>" expected: "<yes>" @@ -92,11 +98,12 @@ tests: data: planet: "Earth" lambda: !code - ruby: 'proc { |text| "#{text}{{planet}}#{text}" }' - perl: 'sub { $_[0] . "{{planet}}" . $_[0] }' - js: 'function(txt) { return txt + "{{planet}}" + txt }' - php: 'return $text . "{{planet}}" . $text;' - python: 'lambda text: "%s{{planet}}%s" % (text, text)' + ruby: 'proc { |text| "#{text}{{planet}}#{text}" }' + perl: 'sub { $_[0] . "{{planet}}" . $_[0] }' + js: 'function(txt) { return txt + "{{planet}}" + txt }' + php: 'return $text . "{{planet}}" . $text;' + python: 'lambda text: "%s{{planet}}%s" % (text, text)' + clojure: '(fn [text] (str text "{{planet}}" text))' template: "<{{#lambda}}-{{/lambda}}>" expected: "<-Earth->" @@ -105,11 +112,12 @@ tests: data: planet: "Earth" lambda: !code - ruby: 'proc { |text| "#{text}{{planet}} => |planet|#{text}" }' - perl: 'sub { $_[0] . "{{planet}} => |planet|" . $_[0] }' - js: 'function(txt) { return txt + "{{planet}} => |planet|" + txt }' - php: 'return $text . "{{planet}} => |planet|" . $text;' - python: 'lambda text: "%s{{planet}} => |planet|%s" % (text, text)' + ruby: 'proc { |text| "#{text}{{planet}} => |planet|#{text}" }' + perl: 'sub { $_[0] . "{{planet}} => |planet|" . $_[0] }' + js: 'function(txt) { return txt + "{{planet}} => |planet|" + txt }' + php: 'return $text . "{{planet}} => |planet|" . $text;' + python: 'lambda text: "%s{{planet}} => |planet|%s" % (text, text)' + clojure: '(fn [text] (str text "{{planet}} => |planet|" text))' template: "{{= | | =}}<|#lambda|-|/lambda|>" expected: "<-{{planet}} => Earth->" @@ -117,11 +125,12 @@ tests: desc: Lambdas used for sections should not be cached. data: lambda: !code - ruby: 'proc { |text| "__#{text}__" }' - perl: 'sub { "__" . $_[0] . "__" }' - js: 'function(txt) { return "__" + txt + "__" }' - php: 'return "__" . $text . "__";' - python: 'lambda text: "__%s__" % (text)' + ruby: 'proc { |text| "__#{text}__" }' + perl: 'sub { "__" . $_[0] . "__" }' + js: 'function(txt) { return "__" + txt + "__" }' + php: 'return "__" . $text . "__";' + python: 'lambda text: "__%s__" % (text)' + clojure: '(fn [text] (str "__" text "__"))' template: '{{#lambda}}FILE{{/lambda}} != {{#lambda}}LINE{{/lambda}}' expected: '__FILE__ != __LINE__' @@ -130,10 +139,11 @@ tests: data: static: 'static' lambda: !code - ruby: 'proc { |text| false }' - perl: 'sub { 0 }' - js: 'function(txt) { return false }' - php: 'return false;' - python: 'lambda text: 0' + ruby: 'proc { |text| false }' + perl: 'sub { 0 }' + js: 'function(txt) { return false }' + php: 'return false;' + python: 'lambda text: 0' + clojure: '(fn [text] false)' template: "<{{^lambda}}{{static}}{{/lambda}}>" expected: "<>" |