1
1
const { liquid } = require ( '../../lib/render-content' )
2
2
const { loadPageMap } = require ( '../../lib/pages' )
3
3
const entities = new ( require ( 'html-entities' ) . XmlEntities ) ( )
4
- const { set } = require ( 'lodash' )
5
4
const nonEnterpriseDefaultVersion = require ( '../../lib/non-enterprise-default-version' )
6
5
7
6
describe ( 'liquid helper tags' , ( ) => {
@@ -15,11 +14,16 @@ describe('liquid helper tags', () => {
15
14
context . currentVersion = nonEnterpriseDefaultVersion
16
15
context . pages = pageMap
17
16
context . redirects = [ ]
18
- context . site = { }
17
+ context . site = {
18
+ data : {
19
+ reusables : {
20
+ example : 'a rose by any other name\nwould smell as sweet'
21
+ }
22
+ }
23
+ }
19
24
context . page = {
20
25
relativePath : 'desktop/index.md'
21
26
}
22
- set ( context . site , 'data.reusables.example' , 'a rose by any other name\nwould smell as sweet' )
23
27
done ( )
24
28
} )
25
29
@@ -83,8 +87,6 @@ describe('liquid helper tags', () => {
83
87
} )
84
88
85
89
describe ( 'indented_data_reference tag' , ( ) => {
86
- set ( context . site , 'data.reusables.example' , 'a rose by any other name\nwould smell as sweet' )
87
-
88
90
test ( 'without any number of spaces specified' , async ( ) => {
89
91
const template = '{% indented_data_reference site.data.reusables.example %}'
90
92
const expected = ` a rose by any other name
@@ -117,4 +119,47 @@ would smell as sweet`
117
119
expect ( output ) . toBe ( expected )
118
120
} )
119
121
} )
122
+
123
+ describe ( 'data tag' , ( ) => {
124
+ test (
125
+ 'handles bracketed array access within for-in loop' ,
126
+ async ( ) => {
127
+ const template = `
128
+ {% for term in site.data.glossaries.external %}
129
+ ### {% data glossaries.external[forloop.index0].term %}
130
+ {% data glossaries.external[forloop.index0].description %}
131
+ ---
132
+ {% endfor %}`
133
+
134
+ const localContext = { ...context }
135
+ localContext . site = {
136
+ data : {
137
+ variables : {
138
+ fire_emoji : ':fire:'
139
+ } ,
140
+ glossaries : {
141
+ external : [
142
+ { term : 'lit' , description : 'Awesome things. {% data variables.fire_emoji %}' } ,
143
+ { term : 'Zhu Li' , description : '_"Zhu Li, do the thing!"_ :point_up:' }
144
+ ]
145
+ }
146
+ }
147
+ }
148
+
149
+ const expected = `
150
+
151
+ ### lit
152
+ Awesome things. :fire:
153
+ ---
154
+
155
+ ### Zhu Li
156
+ _"Zhu Li, do the thing!"_ :point_up:
157
+ ---
158
+ `
159
+
160
+ const output = await liquid . parseAndRender ( template , localContext )
161
+ expect ( output ) . toBe ( expected )
162
+ }
163
+ )
164
+ } )
120
165
} )
0 commit comments