summaryrefslogtreecommitdiff
path: root/specs/delimiters.yml
blob: ce80b17cd183d0b8e6c4934944adcb331ee7980f (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
overview: |
  Set Delimiter tags are used to change the tag delimiters for all content
  following the tag in the current compilation unit.

  The tag's content MUST be any two non-whitespace sequences (separated by
  whitespace) EXCEPT an equals sign ('=') followed by the current closing
  delimiter.

  Set Delimiter tags SHOULD be treated as standalone when appropriate.
tests:
  - name: Pair Behavior
    desc: The equals sign (used on both sides) should permit delimiter changes.
    data: { text: 'Hey!' }
    template: '{{=<% %>=}}(<%text%>)'
    expected: '(Hey!)'

  - name: Special Characters
    desc: Characters with special meaning regexen should be valid delimiters.
    data: { text: 'It worked!' }
    template: '({{=[ ]=}}[text])'
    expected: '(It worked!)'

  - name: Sections
    desc: Delimiters set outside sections should persist.
    data: { section: true, data: 'I got interpolated.' }
    template: |
      [
      {{#section}}
        {{data}}
        |data|
      {{/section}}

      {{= | | =}}
      |#section|
        {{data}}
        |data|
      |/section|
      ]
    expected: |
      [
        I got interpolated.
        |data|

        {{data}}
        I got interpolated.
      ]

  - name: Inverted Sections
    desc: Delimiters set outside inverted sections should persist.
    data: { section: false, data: 'I got interpolated.' }
    template: |
      [
      {{^section}}
        {{data}}
        |data|
      {{/section}}

      {{= | | =}}
      |^section|
        {{data}}
        |data|
      |/section|
      ]
    expected: |
      [
        I got interpolated.
        |data|

        {{data}}
        I got interpolated.
      ]

  - name: Partial Inheritence
    desc: Delimiters set in a parent template should not affect a partial.
    data: { value: 'yes' }
    partials:
      include: '.{{value}}.'
    template: |
      [ {{>include}} ]
      {{= | | =}}
      [ |>include| ]
    expected: |
      [ .yes. ]
      [ .yes. ]

  - name: Post-Partial Behavior
    desc: Delimiters set in a partial should not affect the parent template.
    data: { value: 'yes' }
    partials:
      include: '.{{value}}. {{= | | =}} .|value|.'
    template: |
      [ {{>include}} ]
      [ .{{value}}.  .|value|. ]
    expected: |
      [ .yes.  .yes. ]
      [ .yes.  .|value|. ]

  # Whitespace Sensitivity

  - name: Surrounding Whitespace
    desc: Surrounding whitespace should be left untouched.
    data: { }
    template: '| {{=@ @=}} |'
    expected: '|  |'

  - name: Outlying Whitespace (Inline)
    desc: Whitespace should be left untouched.
    data: { }
    template: " | {{=@ @=}}\n"
    expected: " | \n"

  - name: Standalone Tag
    desc: Standalone lines should be removed from the template.
    data: { }
    template: |
      Begin.
      {{=@ @=}}
      End.
    expected: |
      Begin.
      End.

  - name: Indented Standalone Tag
    desc: Indented standalone lines should be removed from the template.
    data: { }
    template: |
      Begin.
        {{=@ @=}}
      End.
    expected: |
      Begin.
      End.

  - name: Standalone Line Endings
    desc: '"\r\n" should be considered a newline for standalone tags.'
    data: { }
    template: "|\r\n{{= @ @ =}}\r\n|"
    expected: "|\r\n|"

  - name: Standalone Without Previous Line
    desc: Standalone tags should not require a newline to precede them.
    data: { }
    template: "  {{=@ @=}}\n="
    expected: "="

  - name: Standalone Without Newline
    desc: Standalone tags should not require a newline to follow them.
    data: { }
    template: "=\n  {{=@ @=}}"
    expected: "=\n"

  # Whitespace Insensitivity

  - name: Pair with Padding
    desc: Superfluous in-tag whitespace should be ignored.
    data: { }
    template: '|{{= @   @ =}}|'
    expected: '||'