summaryrefslogtreecommitdiff
path: root/specs/sections.yml
blob: c79a7821a4a32002f391275d150f018143277cca (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
tests:
  - name: Truthy
    desc: Truthy sections should have their contents rendered.
    data: { boolean: true }
    template: '"{{#boolean}}This should be rendered.{{/boolean}}"'
    expected: '"This should be rendered."'

  - name: Falsey
    desc: Falsey sections should have their contents omitted.
    data: { boolean: false }
    template: '"{{#boolean}}This should not be rendered.{{/boolean}}"'
    expected: '""'

  - name: Context
    desc: Objects and hashes should be pushed onto the context stack.
    data: { context: { name: 'Joe' } }
    template: '"{{#context}}Hi {{name}}.{{/context}}"'
    expected: '"Hi Joe."'

  - name: Deeply Nested Contexts
    desc: All elements on the context stack should be accessible.
    data:
      a: { one: 1 }
      b: { two: 2 }
      c: { three: 3 }
      d: { four: 4 }
      e: { five: 5 }
    template: |
      {{#a}}
      {{one}}
      {{#b}}
      {{one}}{{two}}{{one}}
      {{#c}}
      {{one}}{{two}}{{three}}{{two}}{{one}}
      {{#d}}
      {{one}}{{two}}{{three}}{{four}}{{three}}{{two}}{{one}}
      {{#e}}
      {{one}}{{two}}{{three}}{{four}}{{five}}{{four}}{{three}}{{two}}{{one}}
      {{/e}}
      {{one}}{{two}}{{three}}{{four}}{{three}}{{two}}{{one}}
      {{/d}}
      {{one}}{{two}}{{three}}{{two}}{{one}}
      {{/c}}
      {{one}}{{two}}{{one}}
      {{/b}}
      {{one}}
      {{/a}}
    expected: |
      1
      121
      12321
      1234321
      123454321
      1234321
      12321
      121
      1

  - name: List
    desc: Lists should be iterated; list items should visit the context stack.
    data: { list: [ { item: 1 }, { item: 2 }, { item: 3 } ] }
    template: '"{{#list}}{{item}}{{/list}}"'
    expected: '"123"'

  - name: Empty List
    desc: Empty lists should behave like falsey values.
    data: { list: [ ] }
    template: '"{{#list}}Yay lists!{{/list}}"'
    expected: '""'

  - name: Doubled
    desc: Multiple sections per template should be permitted.
    data: { bool: true, two: 'second' }
    template: |
      {{#bool}}
      * first
      {{/bool}}
      * {{two}}
      {{#bool}}
      * third
      {{/bool}}
    expected: |
      * first
      * second
      * third

  - name: Nested (Truthy)
    desc: Nested truthy sections should have their contents rendered.
    data: { bool: true }
    template: "| A {{#bool}}B {{#bool}}C{{/bool}} D{{/bool}} E |"
    expected: "| A B C D E |"

  - name: Nested (Falsey)
    desc: Nested falsey sections should be omitted.
    data: { bool: false }
    template: "| A {{#bool}}B {{#bool}}C{{/bool}} D{{/bool}} E |"
    expected: "| A  E |"

  # Implicit Iterators

  - name: Implicit Iterator - String
    desc: Implicit iterators should directly interpolate strings.
    data:
      list: [ 'a', 'b', 'c', 'd', 'e' ]
    template: '"{{#list}}({{.}}){{/list}}"'
    expected: '"(a)(b)(c)(d)(e)"'

  - name: Implicit Iterator - Integer
    desc: Implicit iterators should cast integers to strings and interpolate.
    data:
      list: [ 1, 2, 3, 4, 5 ]
    template: '"{{#list}}({{.}}){{/list}}"'
    expected: '"(1)(2)(3)(4)(5)"'

  - name: Implicit Iterator - Decimal
    desc: Implicit iterators should cast decimals to strings and interpolate.
    data:
      list: [ 1.10, 2.20, 3.30, 4.40, 5.50 ]
    template: '"{{#list}}({{.}}){{/list}}"'
    expected: '"(1.1)(2.2)(3.3)(4.4)(5.5)"'

  # Whitespace Sensitivity

  - name: Surrounding Whitespace
    desc: Sections should not alter surrounding whitespace.
    data: { boolean: true }
    template: " | {{#boolean}}\t|\t{{/boolean}} | \n"
    expected: " | \t|\t | \n"

  - name: Internal Whitespace
    desc: Sections should not alter internal whitespace.
    data: { boolean: true }
    template: " | {{#boolean}} {{! Important Whitespace }}\n {{/boolean}} | \n"
    expected: " |  \n  | \n"

  - name: Standalone Lines
    desc: Standalone lines should be removed from the template.
    data: { boolean: true }
    template: |
      | This Is
      {{#boolean}}
      |
      {{/boolean}}
      | A Line
    expected: |
      | This Is
      |
      | A Line

  - name: Indented Standalone Lines
    desc: Indented standalone lines should be removed from the template.
    data: { boolean: true }
    template: |
      | This Is
        {{#boolean}}
      |
        {{/boolean}}
      | A Line
    expected: |
      | This Is
      |
      | A Line

  # Whitespace Insensitivity

  - name: Padding
    desc: Superfluous in-tag whitespace should be ignored.
    data: { boolean: true }
    template: '|{{# boolean }}={{/ boolean }}|'
    expected: '|=|'