topical media & game development

talk show tell print

mobile-query-three-www-vendor-doccoviewer-vendor-bootstrap-docs-build-node-modules-hogan.js-test-spec-specs-~lambdas.json / json



  {"__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":"<&gt;>","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."}]}


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.