summaryrefslogtreecommitdiff
path: root/specs/lambdas.yml
blob: 97f18cf53cd241df020d54f11079e7b3f36a0d52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
tests:
  - name: Basic Interpolation
    desc: A lambda's return value should be interpolated.
    data:
      lambda: !code
        ruby: 'proc { "world" }'
        perl: 'sub { "world" }'
    template: "Hello, {{lambda}}!"
    expected: "Hello, world!"

  - name: Basic Interpolation
    desc: A lambda's return value should be parsed.
    data:
      planet: "world"
      lambda: !code
        ruby: 'proc { "{{planet}}" }'
        perl: 'sub { "{{planet}}" }'
    template: "Hello, {{lambda}}!"
    expected: "Hello, world!"

  - name: Arity/1
    desc: Interpolated lambdas receive the context stack as the first argument.
    data:
      static: 'static'
      lambda: !code
        ruby: 'proc { |ctx| ctx["static"] }'
        perl: 'sub { my ($ctx) = @_; $ctx->get("static") }'
    template: "{{lambda}} cling"
    expected: "static cling"

  - name: Escaping
    desc: Lambda results should be appropriately escaped.
    data:
      lambda: !code
        ruby: 'proc { ">" }'
        perl: 'sub { ">" }'
    template: "<{{lambda}}{{{lambda}}}"
    expected: "<&gt;>"

  - 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" }'
    template: "<{{#lambda}}{{x}}{{/lambda}}>"
    expected: "<yes>"

  - 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] }'
    template: "<{{#lambda}}-{{/lambda}}>"
    expected: "<-Earth->"

  - 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 }'
    template: "<{{^lambda}}{{static}}{{/lambda}}>"
    expected: "<>"