liquid 4.0.3 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +33 -0
  3. data/README.md +6 -0
  4. data/lib/liquid.rb +17 -5
  5. data/lib/liquid/block.rb +31 -14
  6. data/lib/liquid/block_body.rb +164 -54
  7. data/lib/liquid/condition.rb +39 -18
  8. data/lib/liquid/context.rb +106 -51
  9. data/lib/liquid/document.rb +47 -9
  10. data/lib/liquid/drop.rb +4 -2
  11. data/lib/liquid/errors.rb +20 -18
  12. data/lib/liquid/expression.rb +29 -34
  13. data/lib/liquid/extensions.rb +2 -0
  14. data/lib/liquid/file_system.rb +6 -4
  15. data/lib/liquid/forloop_drop.rb +11 -4
  16. data/lib/liquid/i18n.rb +5 -3
  17. data/lib/liquid/interrupts.rb +3 -1
  18. data/lib/liquid/lexer.rb +30 -23
  19. data/lib/liquid/locales/en.yml +3 -1
  20. data/lib/liquid/parse_context.rb +16 -4
  21. data/lib/liquid/parse_tree_visitor.rb +2 -2
  22. data/lib/liquid/parser.rb +30 -18
  23. data/lib/liquid/parser_switching.rb +17 -3
  24. data/lib/liquid/partial_cache.rb +24 -0
  25. data/lib/liquid/profiler.rb +67 -86
  26. data/lib/liquid/profiler/hooks.rb +26 -14
  27. data/lib/liquid/range_lookup.rb +5 -3
  28. data/lib/liquid/register.rb +6 -0
  29. data/lib/liquid/resource_limits.rb +47 -8
  30. data/lib/liquid/standardfilters.rb +63 -44
  31. data/lib/liquid/static_registers.rb +44 -0
  32. data/lib/liquid/strainer_factory.rb +36 -0
  33. data/lib/liquid/strainer_template.rb +53 -0
  34. data/lib/liquid/tablerowloop_drop.rb +6 -4
  35. data/lib/liquid/tag.rb +28 -6
  36. data/lib/liquid/tag/disableable.rb +22 -0
  37. data/lib/liquid/tag/disabler.rb +21 -0
  38. data/lib/liquid/tags/assign.rb +24 -10
  39. data/lib/liquid/tags/break.rb +8 -3
  40. data/lib/liquid/tags/capture.rb +11 -8
  41. data/lib/liquid/tags/case.rb +33 -27
  42. data/lib/liquid/tags/comment.rb +5 -3
  43. data/lib/liquid/tags/continue.rb +8 -3
  44. data/lib/liquid/tags/cycle.rb +25 -14
  45. data/lib/liquid/tags/decrement.rb +6 -3
  46. data/lib/liquid/tags/echo.rb +26 -0
  47. data/lib/liquid/tags/for.rb +68 -44
  48. data/lib/liquid/tags/if.rb +35 -23
  49. data/lib/liquid/tags/ifchanged.rb +11 -10
  50. data/lib/liquid/tags/include.rb +34 -47
  51. data/lib/liquid/tags/increment.rb +7 -3
  52. data/lib/liquid/tags/raw.rb +14 -11
  53. data/lib/liquid/tags/render.rb +84 -0
  54. data/lib/liquid/tags/table_row.rb +23 -19
  55. data/lib/liquid/tags/unless.rb +15 -15
  56. data/lib/liquid/template.rb +55 -71
  57. data/lib/liquid/template_factory.rb +9 -0
  58. data/lib/liquid/tokenizer.rb +17 -9
  59. data/lib/liquid/usage.rb +8 -0
  60. data/lib/liquid/utils.rb +5 -3
  61. data/lib/liquid/variable.rb +46 -41
  62. data/lib/liquid/variable_lookup.rb +8 -6
  63. data/lib/liquid/version.rb +2 -1
  64. data/test/integration/assign_test.rb +74 -5
  65. data/test/integration/blank_test.rb +11 -8
  66. data/test/integration/block_test.rb +47 -1
  67. data/test/integration/capture_test.rb +18 -10
  68. data/test/integration/context_test.rb +608 -5
  69. data/test/integration/document_test.rb +4 -2
  70. data/test/integration/drop_test.rb +67 -83
  71. data/test/integration/error_handling_test.rb +73 -61
  72. data/test/integration/expression_test.rb +46 -0
  73. data/test/integration/filter_test.rb +53 -42
  74. data/test/integration/hash_ordering_test.rb +5 -3
  75. data/test/integration/output_test.rb +26 -24
  76. data/test/integration/parsing_quirks_test.rb +19 -7
  77. data/test/integration/{render_profiling_test.rb → profiler_test.rb} +84 -25
  78. data/test/integration/security_test.rb +30 -21
  79. data/test/integration/standard_filter_test.rb +339 -281
  80. data/test/integration/tag/disableable_test.rb +59 -0
  81. data/test/integration/tag_test.rb +45 -0
  82. data/test/integration/tags/break_tag_test.rb +4 -2
  83. data/test/integration/tags/continue_tag_test.rb +4 -2
  84. data/test/integration/tags/echo_test.rb +13 -0
  85. data/test/integration/tags/for_tag_test.rb +107 -51
  86. data/test/integration/tags/if_else_tag_test.rb +5 -3
  87. data/test/integration/tags/include_tag_test.rb +70 -54
  88. data/test/integration/tags/increment_tag_test.rb +4 -2
  89. data/test/integration/tags/liquid_tag_test.rb +116 -0
  90. data/test/integration/tags/raw_tag_test.rb +14 -11
  91. data/test/integration/tags/render_tag_test.rb +213 -0
  92. data/test/integration/tags/standard_tag_test.rb +38 -31
  93. data/test/integration/tags/statements_test.rb +23 -21
  94. data/test/integration/tags/table_row_test.rb +2 -0
  95. data/test/integration/tags/unless_else_tag_test.rb +4 -2
  96. data/test/integration/template_test.rb +118 -124
  97. data/test/integration/trim_mode_test.rb +78 -44
  98. data/test/integration/variable_test.rb +43 -32
  99. data/test/test_helper.rb +75 -22
  100. data/test/unit/block_unit_test.rb +19 -24
  101. data/test/unit/condition_unit_test.rb +79 -77
  102. data/test/unit/file_system_unit_test.rb +6 -4
  103. data/test/unit/i18n_unit_test.rb +7 -5
  104. data/test/unit/lexer_unit_test.rb +11 -9
  105. data/test/{integration → unit}/parse_tree_visitor_test.rb +2 -2
  106. data/test/unit/parser_unit_test.rb +37 -35
  107. data/test/unit/partial_cache_unit_test.rb +128 -0
  108. data/test/unit/regexp_unit_test.rb +17 -15
  109. data/test/unit/static_registers_unit_test.rb +156 -0
  110. data/test/unit/strainer_factory_unit_test.rb +100 -0
  111. data/test/unit/strainer_template_unit_test.rb +82 -0
  112. data/test/unit/tag_unit_test.rb +5 -3
  113. data/test/unit/tags/case_tag_unit_test.rb +3 -1
  114. data/test/unit/tags/for_tag_unit_test.rb +4 -2
  115. data/test/unit/tags/if_tag_unit_test.rb +3 -1
  116. data/test/unit/template_factory_unit_test.rb +12 -0
  117. data/test/unit/template_unit_test.rb +19 -10
  118. data/test/unit/tokenizer_unit_test.rb +19 -17
  119. data/test/unit/variable_unit_test.rb +51 -49
  120. metadata +73 -47
  121. data/lib/liquid/strainer.rb +0 -66
  122. data/lib/liquid/truffle.rb +0 -5
  123. data/test/truffle/truffle_test.rb +0 -9
  124. data/test/unit/context_unit_test.rb +0 -489
  125. data/test/unit/strainer_unit_test.rb +0 -164
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class TagDisableableTest < Minitest::Test
6
+ include Liquid
7
+
8
+ module RenderTagName
9
+ def render(_context)
10
+ tag_name
11
+ end
12
+ end
13
+
14
+ class Custom < Tag
15
+ prepend Liquid::Tag::Disableable
16
+ include RenderTagName
17
+ end
18
+
19
+ class Custom2 < Tag
20
+ prepend Liquid::Tag::Disableable
21
+ include RenderTagName
22
+ end
23
+
24
+ class DisableCustom < Block
25
+ disable_tags "custom"
26
+ end
27
+
28
+ class DisableBoth < Block
29
+ disable_tags "custom", "custom2"
30
+ end
31
+
32
+ def test_block_tag_disabling_nested_tag
33
+ with_disableable_tags do
34
+ with_custom_tag('disable', DisableCustom) do
35
+ output = Template.parse('{% disable %}{% custom %};{% custom2 %}{% enddisable %}').render
36
+ assert_equal('Liquid error: custom usage is not allowed in this context;custom2', output)
37
+ end
38
+ end
39
+ end
40
+
41
+ def test_block_tag_disabling_multiple_nested_tags
42
+ with_disableable_tags do
43
+ with_custom_tag('disable', DisableBoth) do
44
+ output = Template.parse('{% disable %}{% custom %};{% custom2 %}{% enddisable %}').render
45
+ assert_equal('Liquid error: custom usage is not allowed in this context;Liquid error: custom2 usage is not allowed in this context', output)
46
+ end
47
+ end
48
+ end
49
+
50
+ private
51
+
52
+ def with_disableable_tags
53
+ with_custom_tag('custom', Custom) do
54
+ with_custom_tag('custom2', Custom2) do
55
+ yield
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class TagTest < Minitest::Test
6
+ include Liquid
7
+
8
+ def test_custom_tags_have_a_default_render_to_output_buffer_method_for_backwards_compatibility
9
+ klass1 = Class.new(Tag) do
10
+ def render(*)
11
+ 'hello'
12
+ end
13
+ end
14
+
15
+ with_custom_tag('blabla', klass1) do
16
+ template = Liquid::Template.parse("{% blabla %}")
17
+
18
+ assert_equal('hello', template.render)
19
+
20
+ buf = +''
21
+ output = template.render({}, output: buf)
22
+ assert_equal('hello', output)
23
+ assert_equal('hello', buf)
24
+ assert_equal(buf.object_id, output.object_id)
25
+ end
26
+
27
+ klass2 = Class.new(klass1) do
28
+ def render(*)
29
+ 'foo' + super + 'bar'
30
+ end
31
+ end
32
+
33
+ with_custom_tag('blabla', klass2) do
34
+ template = Liquid::Template.parse("{% blabla %}")
35
+
36
+ assert_equal('foohellobar', template.render)
37
+
38
+ buf = +''
39
+ output = template.render({}, output: buf)
40
+ assert_equal('foohellobar', output)
41
+ assert_equal('foohellobar', buf)
42
+ assert_equal(buf.object_id, output.object_id)
43
+ end
44
+ end
45
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  class BreakTagTest < Minitest::Test
@@ -6,8 +8,8 @@ class BreakTagTest < Minitest::Test
6
8
  # tests that no weird errors are raised if break is called outside of a
7
9
  # block
8
10
  def test_break_with_no_block
9
- assigns = { 'i' => 1 }
10
- markup = '{% break %}'
11
+ assigns = { 'i' => 1 }
12
+ markup = '{% break %}'
11
13
  expected = ''
12
14
 
13
15
  assert_template_result(expected, markup, assigns)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  class ContinueTagTest < Minitest::Test
@@ -6,8 +8,8 @@ class ContinueTagTest < Minitest::Test
6
8
  # tests that no weird errors are raised if continue is called outside of a
7
9
  # block
8
10
  def test_continue_with_no_block
9
- assigns = {}
10
- markup = '{% continue %}'
11
+ assigns = {}
12
+ markup = '{% continue %}'
11
13
  expected = ''
12
14
 
13
15
  assert_template_result(expected, markup, assigns)
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ class EchoTest < Minitest::Test
6
+ include Liquid
7
+
8
+ def test_echo_outputs_its_input
9
+ assert_template_result('BAR', <<~LIQUID, 'variable-name' => 'bar')
10
+ {%- echo variable-name | upcase -%}
11
+ LIQUID
12
+ end
13
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'test_helper'
2
4
 
3
5
  class ThingWithValue < Liquid::Drop
@@ -23,16 +25,16 @@ class ForTagTest < Minitest::Test
23
25
  yo
24
26
 
25
27
  HERE
26
- template = <<HERE
27
- {%for item in array%}
28
- yo
29
- {%endfor%}
30
- HERE
28
+ template = <<~HERE
29
+ {%for item in array%}
30
+ yo
31
+ {%endfor%}
32
+ HERE
31
33
  assert_template_result(expected, template, 'array' => [1, 2, 3])
32
34
  end
33
35
 
34
36
  def test_for_reversed
35
- assigns = { 'array' => [ 1, 2, 3] }
37
+ assigns = { 'array' => [1, 2, 3] }
36
38
  assert_template_result('321', '{%for item in array reversed %}{{item}}{%endfor%}', assigns)
37
39
  end
38
40
 
@@ -103,9 +105,37 @@ HERE
103
105
  assert_template_result('3456', '{%for i in array limit: 4 offset: 2 %}{{ i }}{%endfor%}', assigns)
104
106
  end
105
107
 
108
+ def test_limiting_with_invalid_limit
109
+ assigns = { 'array' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] }
110
+ template = <<-MKUP
111
+ {% for i in array limit: true offset: 1 %}
112
+ {{ i }}
113
+ {% endfor %}
114
+ MKUP
115
+
116
+ exception = assert_raises(Liquid::ArgumentError) do
117
+ Template.parse(template).render!(assigns)
118
+ end
119
+ assert_equal("Liquid error: invalid integer", exception.message)
120
+ end
121
+
122
+ def test_limiting_with_invalid_offset
123
+ assigns = { 'array' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] }
124
+ template = <<-MKUP
125
+ {% for i in array limit: 1 offset: true %}
126
+ {{ i }}
127
+ {% endfor %}
128
+ MKUP
129
+
130
+ exception = assert_raises(Liquid::ArgumentError) do
131
+ Template.parse(template).render!(assigns)
132
+ end
133
+ assert_equal("Liquid error: invalid integer", exception.message)
134
+ end
135
+
106
136
  def test_dynamic_variable_limiting
107
- assigns = { 'array' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] }
108
- assigns['limit'] = 2
137
+ assigns = { 'array' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] }
138
+ assigns['limit'] = 2
109
139
  assigns['offset'] = 2
110
140
 
111
141
  assert_template_result('34', '{%for i in array limit: limit offset: offset %}{{ i }}{%endfor%}', assigns)
@@ -122,8 +152,8 @@ HERE
122
152
  end
123
153
 
124
154
  def test_pause_resume
125
- assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } }
126
- markup = <<-MKUP
155
+ assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } }
156
+ markup = <<-MKUP
127
157
  {%for i in array.items limit: 3 %}{{i}}{%endfor%}
128
158
  next
129
159
  {%for i in array.items offset:continue limit: 3 %}{{i}}{%endfor%}
@@ -141,8 +171,8 @@ HERE
141
171
  end
142
172
 
143
173
  def test_pause_resume_limit
144
- assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } }
145
- markup = <<-MKUP
174
+ assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } }
175
+ markup = <<-MKUP
146
176
  {%for i in array.items limit:3 %}{{i}}{%endfor%}
147
177
  next
148
178
  {%for i in array.items offset:continue limit:3 %}{{i}}{%endfor%}
@@ -160,8 +190,8 @@ HERE
160
190
  end
161
191
 
162
192
  def test_pause_resume_big_limit
163
- assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } }
164
- markup = <<-MKUP
193
+ assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } }
194
+ markup = <<-MKUP
165
195
  {%for i in array.items limit:3 %}{{i}}{%endfor%}
166
196
  next
167
197
  {%for i in array.items offset:continue limit:3 %}{{i}}{%endfor%}
@@ -179,8 +209,8 @@ HERE
179
209
  end
180
210
 
181
211
  def test_pause_resume_big_offset
182
- assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } }
183
- markup = '{%for i in array.items limit:3 %}{{i}}{%endfor%}
212
+ assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 0] } }
213
+ markup = '{%for i in array.items limit:3 %}{{i}}{%endfor%}
184
214
  next
185
215
  {%for i in array.items offset:continue limit:3 %}{{i}}{%endfor%}
186
216
  next
@@ -196,26 +226,26 @@ HERE
196
226
  def test_for_with_break
197
227
  assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] } }
198
228
 
199
- markup = '{% for i in array.items %}{% break %}{% endfor %}'
229
+ markup = '{% for i in array.items %}{% break %}{% endfor %}'
200
230
  expected = ""
201
231
  assert_template_result(expected, markup, assigns)
202
232
 
203
- markup = '{% for i in array.items %}{{ i }}{% break %}{% endfor %}'
233
+ markup = '{% for i in array.items %}{{ i }}{% break %}{% endfor %}'
204
234
  expected = "1"
205
235
  assert_template_result(expected, markup, assigns)
206
236
 
207
- markup = '{% for i in array.items %}{% break %}{{ i }}{% endfor %}'
237
+ markup = '{% for i in array.items %}{% break %}{{ i }}{% endfor %}'
208
238
  expected = ""
209
239
  assert_template_result(expected, markup, assigns)
210
240
 
211
- markup = '{% for i in array.items %}{{ i }}{% if i > 3 %}{% break %}{% endif %}{% endfor %}'
241
+ markup = '{% for i in array.items %}{{ i }}{% if i > 3 %}{% break %}{% endif %}{% endfor %}'
212
242
  expected = "1234"
213
243
  assert_template_result(expected, markup, assigns)
214
244
 
215
245
  # tests to ensure it only breaks out of the local for loop
216
246
  # and not all of them.
217
- assigns = { 'array' => [[1, 2], [3, 4], [5, 6]] }
218
- markup = '{% for item in array %}' \
247
+ assigns = { 'array' => [[1, 2], [3, 4], [5, 6]] }
248
+ markup = '{% for item in array %}' \
219
249
  '{% for i in item %}' \
220
250
  '{% if i == 1 %}' \
221
251
  '{% break %}' \
@@ -227,8 +257,8 @@ HERE
227
257
  assert_template_result(expected, markup, assigns)
228
258
 
229
259
  # test break does nothing when unreached
230
- assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5] } }
231
- markup = '{% for i in array.items %}{% if i == 9999 %}{% break %}{% endif %}{{ i }}{% endfor %}'
260
+ assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5] } }
261
+ markup = '{% for i in array.items %}{% if i == 9999 %}{% break %}{% endif %}{{ i }}{% endfor %}'
232
262
  expected = '12345'
233
263
  assert_template_result(expected, markup, assigns)
234
264
  end
@@ -236,29 +266,29 @@ HERE
236
266
  def test_for_with_continue
237
267
  assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5] } }
238
268
 
239
- markup = '{% for i in array.items %}{% continue %}{% endfor %}'
269
+ markup = '{% for i in array.items %}{% continue %}{% endfor %}'
240
270
  expected = ""
241
271
  assert_template_result(expected, markup, assigns)
242
272
 
243
- markup = '{% for i in array.items %}{{ i }}{% continue %}{% endfor %}'
273
+ markup = '{% for i in array.items %}{{ i }}{% continue %}{% endfor %}'
244
274
  expected = "12345"
245
275
  assert_template_result(expected, markup, assigns)
246
276
 
247
- markup = '{% for i in array.items %}{% continue %}{{ i }}{% endfor %}'
277
+ markup = '{% for i in array.items %}{% continue %}{{ i }}{% endfor %}'
248
278
  expected = ""
249
279
  assert_template_result(expected, markup, assigns)
250
280
 
251
- markup = '{% for i in array.items %}{% if i > 3 %}{% continue %}{% endif %}{{ i }}{% endfor %}'
281
+ markup = '{% for i in array.items %}{% if i > 3 %}{% continue %}{% endif %}{{ i }}{% endfor %}'
252
282
  expected = "123"
253
283
  assert_template_result(expected, markup, assigns)
254
284
 
255
- markup = '{% for i in array.items %}{% if i == 3 %}{% continue %}{% else %}{{ i }}{% endif %}{% endfor %}'
285
+ markup = '{% for i in array.items %}{% if i == 3 %}{% continue %}{% else %}{{ i }}{% endif %}{% endfor %}'
256
286
  expected = "1245"
257
287
  assert_template_result(expected, markup, assigns)
258
288
 
259
289
  # tests to ensure it only continues the local for loop and not all of them.
260
- assigns = { 'array' => [[1, 2], [3, 4], [5, 6]] }
261
- markup = '{% for item in array %}' \
290
+ assigns = { 'array' => [[1, 2], [3, 4], [5, 6]] }
291
+ markup = '{% for item in array %}' \
262
292
  '{% for i in item %}' \
263
293
  '{% if i == 1 %}' \
264
294
  '{% continue %}' \
@@ -270,8 +300,8 @@ HERE
270
300
  assert_template_result(expected, markup, assigns)
271
301
 
272
302
  # test continue does nothing when unreached
273
- assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5] } }
274
- markup = '{% for i in array.items %}{% if i == 9999 %}{% continue %}{% endif %}{{ i }}{% endfor %}'
303
+ assigns = { 'array' => { 'items' => [1, 2, 3, 4, 5] } }
304
+ markup = '{% for i in array.items %}{% if i == 9999 %}{% continue %}{% endif %}{{ i }}{% endfor %}'
275
305
  expected = '12345'
276
306
  assert_template_result(expected, markup, assigns)
277
307
  end
@@ -320,7 +350,7 @@ HERE
320
350
  end
321
351
 
322
352
  def test_inner_for_over_empty_input
323
- assert_template_result 'oo', '{% for a in (1..2) %}o{% for b in empty %}{% endfor %}{% endfor %}'
353
+ assert_template_result('oo', '{% for a in (1..2) %}o{% for b in empty %}{% endfor %}{% endfor %}')
324
354
  end
325
355
 
326
356
  def test_blank_string_not_iterable
@@ -359,41 +389,41 @@ HERE
359
389
  end
360
390
 
361
391
  def test_iterate_with_each_when_no_limit_applied
362
- loader = LoaderDrop.new([1, 2, 3, 4, 5])
363
- assigns = { 'items' => loader }
392
+ loader = LoaderDrop.new([1, 2, 3, 4, 5])
393
+ assigns = { 'items' => loader }
364
394
  expected = '12345'
365
395
  template = '{% for item in items %}{{item}}{% endfor %}'
366
396
  assert_template_result(expected, template, assigns)
367
- assert loader.each_called
368
- assert !loader.load_slice_called
397
+ assert(loader.each_called)
398
+ assert(!loader.load_slice_called)
369
399
  end
370
400
 
371
401
  def test_iterate_with_load_slice_when_limit_applied
372
- loader = LoaderDrop.new([1, 2, 3, 4, 5])
373
- assigns = { 'items' => loader }
402
+ loader = LoaderDrop.new([1, 2, 3, 4, 5])
403
+ assigns = { 'items' => loader }
374
404
  expected = '1'
375
405
  template = '{% for item in items limit:1 %}{{item}}{% endfor %}'
376
406
  assert_template_result(expected, template, assigns)
377
- assert !loader.each_called
378
- assert loader.load_slice_called
407
+ assert(!loader.each_called)
408
+ assert(loader.load_slice_called)
379
409
  end
380
410
 
381
411
  def test_iterate_with_load_slice_when_limit_and_offset_applied
382
- loader = LoaderDrop.new([1, 2, 3, 4, 5])
383
- assigns = { 'items' => loader }
412
+ loader = LoaderDrop.new([1, 2, 3, 4, 5])
413
+ assigns = { 'items' => loader }
384
414
  expected = '34'
385
415
  template = '{% for item in items offset:2 limit:2 %}{{item}}{% endfor %}'
386
416
  assert_template_result(expected, template, assigns)
387
- assert !loader.each_called
388
- assert loader.load_slice_called
417
+ assert(!loader.each_called)
418
+ assert(loader.load_slice_called)
389
419
  end
390
420
 
391
421
  def test_iterate_with_load_slice_returns_same_results_as_without
392
- loader = LoaderDrop.new([1, 2, 3, 4, 5])
422
+ loader = LoaderDrop.new([1, 2, 3, 4, 5])
393
423
  loader_assigns = { 'items' => loader }
394
- array_assigns = { 'items' => [1, 2, 3, 4, 5] }
395
- expected = '34'
396
- template = '{% for item in items offset:2 limit:2 %}{{item}}{% endfor %}'
424
+ array_assigns = { 'items' => [1, 2, 3, 4, 5] }
425
+ expected = '34'
426
+ template = '{% for item in items offset:2 limit:2 %}{{item}}{% endfor %}'
397
427
  assert_template_result(expected, template, loader_assigns)
398
428
  assert_template_result(expected, template, array_assigns)
399
429
  end
@@ -405,6 +435,32 @@ HERE
405
435
  Liquid::Template.parse('{% for i in (1..2) %}{{ standard_error }}{% endfor %}').render!(context)
406
436
  end
407
437
 
408
- assert context.registers[:for_stack].empty?
438
+ assert(context.registers[:for_stack].empty?)
439
+ end
440
+
441
+ def test_instrument_for_offset_continue
442
+ assert_usage_increment('for_offset_continue') do
443
+ Template.parse('{% for item in items offset:continue %}{{item}}{% endfor %}')
444
+ end
445
+
446
+ assert_usage_increment('for_offset_continue', times: 0) do
447
+ Template.parse('{% for item in items offset:2 %}{{item}}{% endfor %}')
448
+ end
449
+ end
450
+
451
+ def test_instrument_forloop_drop_name
452
+ assigns = { 'items' => [1, 2, 3, 4, 5] }
453
+
454
+ assert_usage_increment('forloop_drop_name', times: 5) do
455
+ Template.parse('{% for item in items %}{{forloop.name}}{% endfor %}').render!(assigns)
456
+ end
457
+
458
+ assert_usage_increment('forloop_drop_name', times: 0) do
459
+ Template.parse('{% for item in items %}{{forloop.index}}{% endfor %}').render!(assigns)
460
+ end
461
+
462
+ assert_usage_increment('forloop_drop_name', times: 0) do
463
+ Template.parse('{% for item in items %}{{item}}{% endfor %}').render!(assigns)
464
+ end
409
465
  end
410
466
  end