tests: - name: Interpolation 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";' template: "Hello, {{lambda}}!" expected: "Hello, world!" - name: Interpolation - Expansion desc: A lambda's return value should be parsed. data: planet: "world" lambda: !code ruby: 'proc { "{{planet}}" }' perl: 'sub { "{{planet}}" }' js: 'function() { return "{{planet}}" }' php: 'return "{{planet}}";' template: "Hello, {{lambda}}!" expected: "Hello, world!" - name: Interpolation - Multiple Calls desc: Interpolated lambdas should only be called once. data: lambda: !code ruby: 'proc { $calls ||= 0; $calls += 1 }' perl: 'sub { no strict; $calls += 1 }' js: 'function() { f = arguments.callee; return f.calls = (f.calls || 0) + 1 }' php: 'global $calls; return ++$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";' template: "{{#context}}{{key}} the {{lambda}}{{/context}} {{key}}" expected: "Under the Big Top" - name: Escaping desc: Lambda results should be appropriately escaped. data: lambda: !code ruby: 'proc { ">" }' perl: 'sub { ">" }' js: 'function() { return ">" }' php: 'return ">";' template: "<{{lambda}}{{{lambda}}}" expected: "<>>" - name: Section desc: Lambdas used for sections should receive the raw section string. 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";' template: "<{{#lambda}}{{x}}{{/lambda}}>" expected: "" - name: Section - Expansion desc: Lambdas used for sections should have their results parsed. 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;' template: "<{{#lambda}}-{{/lambda}}>" expected: "<-Earth->" - name: Section - Multiple Calls desc: Lambdas used for sections should not simply cache the first response. data: lambda: !code ruby: 'proc { |text| "__#{text}__" }' perl: 'sub { "__" . $_[0] . "__" }' js: 'function(txt) { return "__" + txt + "__" }' php: 'return "__" . $text . "__";' template: '{{#lambda}}FILE{{/lambda}} != {{#lambda}}LINE{{/lambda}}' expected: '__FILE__ != __LINE__' - name: Inverted Section desc: Lambdas used for inverted sections should be considered truthy. data: static: 'static' lambda: !code ruby: 'proc { |text| text }' perl: 'sub { shift }' js: 'function(txt) { return txt }' php: 'return $text;' template: "<{{^lambda}}{{static}}{{/lambda}}>" expected: "<>"