11const { liquid } = require ( '../../lib/render-content' )
22const { loadPageMap } = require ( '../../lib/pages' )
33const entities = new ( require ( 'html-entities' ) . XmlEntities ) ( )
4- const { set } = require ( 'lodash' )
54const nonEnterpriseDefaultVersion = require ( '../../lib/non-enterprise-default-version' )
65
76describe ( 'liquid helper tags' , ( ) => {
@@ -15,11 +14,16 @@ describe('liquid helper tags', () => {
1514 context . currentVersion = nonEnterpriseDefaultVersion
1615 context . pages = pageMap
1716 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+ }
1924 context . page = {
2025 relativePath : 'desktop/index.md'
2126 }
22- set ( context . site , 'data.reusables.example' , 'a rose by any other name\nwould smell as sweet' )
2327 done ( )
2428 } )
2529
@@ -83,8 +87,6 @@ describe('liquid helper tags', () => {
8387 } )
8488
8589 describe ( 'indented_data_reference tag' , ( ) => {
86- set ( context . site , 'data.reusables.example' , 'a rose by any other name\nwould smell as sweet' )
87-
8890 test ( 'without any number of spaces specified' , async ( ) => {
8991 const template = '{% indented_data_reference site.data.reusables.example %}'
9092 const expected = ` a rose by any other name
@@ -117,4 +119,47 @@ would smell as sweet`
117119 expect ( output ) . toBe ( expected )
118120 } )
119121 } )
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+ } )
120165} )
0 commit comments