summaryrefslogtreecommitdiff
path: root/specs/inverted.yml
blob: 1e2c4fdd756da2aa1d52a91a88b4ea1ff05f6634 (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
tests:
  - name: Falsey
    desc: Falsey sections should have their contents rendered.
    data: { boolean: false }
    template: '"{{^boolean}}This should be rendered.{{/boolean}}"'
    expected: '"This should be rendered."'

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

  - name: Context
    desc: Objects and hashes should behave like truthy values.
    data: { context: { name: 'Joe' } }
    template: '"{{^context}}Hi {{name}}.{{/context}}"'
    expected: '""'

  - name: List
    desc: Lists should behave like truthy values.
    data: { list: [ { n: 1 }, { n: 2 }, { n: 3 } ] }
    template: '"{{^list}}{{n}}{{/list}}"'
    expected: '""'

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

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

  - name: Nested (Falsey)
    desc: Nested falsey sections should have their contents rendered.
    data: { bool: false }
    template: "| A {{^bool}}B {{^bool}}C{{/bool}} D{{/bool}} E |"
    expected: "| A B C D E |"

  - name: Nested (Truthy)
    desc: Nested truthy sections should be omitted.
    data: { bool: true }
    template: "| A {{^bool}}B {{^bool}}C{{/bool}} D{{/bool}} E |"
    expected: "| A  E |"

  # Whitespace Sensitivity

  - name: Surrounding Whitespace
    desc: Inverted sections should not alter surrounding whitespace.
    data: { boolean: false }
    template: " | {{^boolean}}\t|\t{{/boolean}} | \n"
    expected: " | \t|\t | \n"

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

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

  - name: Standalone Indented Lines
    desc: Standalone indented lines should be removed from the template.
    data: { boolean: false }
    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: false }
    template: '|{{^ boolean }}={{/ boolean }}|'
    expected: '|=|'