Skip to content

Commit 377f207

Browse files
author
Jeff Escalante
committed
add tests for custom tag and delimiter options
1 parent aa1a160 commit 377f207

File tree

8 files changed

+61
-1
lines changed

8 files changed

+61
-1
lines changed

lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function walk (opts, nodes) {
6060
}
6161

6262
// if the node has content, recurse (unless it's a loop, handled later)
63-
if (node.content && node.tag !== 'each') {
63+
if (node.content && node.tag !== loops[0]) {
6464
node.content = walk(opts, node.content)
6565
}
6666

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<p>x</p>
2+
3+
<p>it works!</p>
4+
<p>x</p>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<p>x</p>
2+
<zif condition="foo === 'bar'">
3+
<p>it works!</p>
4+
</zif>
5+
<zelseif condition="foo === 'wow'">
6+
<p>it doesn't work</p>
7+
</zelseif>
8+
<zelseif condition="foo === 'snargle'">
9+
<p>it really doesn't work</p>
10+
</zelseif>
11+
<zelse>
12+
<p>it definitely doesn't work</p>
13+
</zelse>
14+
<p>x</p>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
x wow x 2 x
2+
<p class="x wow x">x wow x</p>
3+
x&x
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
x {% test %} x {% 1 + 1 %} x
2+
<p class="x {% test %} x">x {% test %} x</p>
3+
{{% 'x&x' %}}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<p>x</p>
2+
3+
<p>0: 1</p>
4+
5+
<p>1: 2</p>
6+
7+
<p>2: 3</p>
8+
9+
<p>x</p>

test/fixtures/loop_customtag.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<p>x</p>
2+
<zeach loop='item, index in items'>
3+
<p>{{index}}: {{item}}</p>
4+
</zeach>
5+
<p>x</p>

test/index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ test('unescaped', (t) => {
1919
})
2020
})
2121

22+
test('custom delimiters', (t) => {
23+
return matchExpected(t, 'custom_delimiters', {
24+
delimiters: ['{%', '%}'],
25+
unescapeDelimiters: ['{{%', '%}}'],
26+
locals: { test: 'wow' }
27+
})
28+
})
29+
2230
test('expression spacing', (t) => {
2331
return matchExpected(t, 'expression_spacing', { locals: { foo: 'X' } })
2432
})
@@ -67,6 +75,13 @@ test('conditional - expression error', (t) => {
6775
})
6876
})
6977

78+
test('conditional - custom tags', (t) => {
79+
return matchExpected(t, 'conditional_customtags', {
80+
conditionalTags: ['zif', 'zelseif', 'zelse'],
81+
locals: { foo: 'bar' }
82+
})
83+
})
84+
7085
test('loop', (t) => {
7186
return matchExpected(t, 'loop', { locals: { items: [1, 2, 3] } })
7287
})
@@ -95,6 +110,13 @@ test('nested loops', (t) => {
95110
})
96111
})
97112

113+
test('loop - custom tag', (t) => {
114+
return matchExpected(t, 'loop_customtag', {
115+
loopTags: ['zeach'],
116+
locals: { items: [1, 2, 3] }
117+
})
118+
})
119+
98120
test('loop - no loop attribute', (t) => {
99121
return expectError('loop_no_attr', (err) => {
100122
t.truthy(err.toString() === 'Error: the "elseif" tag must have a "loop" attribute')

0 commit comments

Comments
 (0)