liquid 4.0.3 → 5.1.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.
- checksums.yaml +4 -4
- data/History.md +54 -0
- data/README.md +6 -0
- data/lib/liquid/block.rb +31 -14
- data/lib/liquid/block_body.rb +166 -54
- data/lib/liquid/condition.rb +41 -20
- data/lib/liquid/context.rb +107 -52
- data/lib/liquid/document.rb +47 -9
- data/lib/liquid/drop.rb +4 -2
- data/lib/liquid/errors.rb +20 -18
- data/lib/liquid/expression.rb +29 -34
- data/lib/liquid/extensions.rb +2 -0
- data/lib/liquid/file_system.rb +6 -4
- data/lib/liquid/forloop_drop.rb +11 -4
- data/lib/liquid/i18n.rb +5 -3
- data/lib/liquid/interrupts.rb +3 -1
- data/lib/liquid/lexer.rb +30 -23
- data/lib/liquid/locales/en.yml +3 -1
- data/lib/liquid/parse_context.rb +20 -4
- data/lib/liquid/parse_tree_visitor.rb +2 -2
- data/lib/liquid/parser.rb +30 -18
- data/lib/liquid/parser_switching.rb +17 -3
- data/lib/liquid/partial_cache.rb +24 -0
- data/lib/liquid/profiler/hooks.rb +26 -14
- data/lib/liquid/profiler.rb +67 -86
- data/lib/liquid/range_lookup.rb +13 -3
- data/lib/liquid/register.rb +6 -0
- data/lib/liquid/resource_limits.rb +47 -8
- data/lib/liquid/standardfilters.rb +95 -46
- data/lib/liquid/static_registers.rb +44 -0
- data/lib/liquid/strainer_factory.rb +36 -0
- data/lib/liquid/strainer_template.rb +53 -0
- data/lib/liquid/tablerowloop_drop.rb +6 -4
- data/lib/liquid/tag/disableable.rb +22 -0
- data/lib/liquid/tag/disabler.rb +21 -0
- data/lib/liquid/tag.rb +28 -6
- data/lib/liquid/tags/assign.rb +24 -10
- data/lib/liquid/tags/break.rb +8 -3
- data/lib/liquid/tags/capture.rb +11 -8
- data/lib/liquid/tags/case.rb +40 -27
- data/lib/liquid/tags/comment.rb +5 -3
- data/lib/liquid/tags/continue.rb +8 -3
- data/lib/liquid/tags/cycle.rb +25 -14
- data/lib/liquid/tags/decrement.rb +6 -3
- data/lib/liquid/tags/echo.rb +34 -0
- data/lib/liquid/tags/for.rb +68 -44
- data/lib/liquid/tags/if.rb +39 -23
- data/lib/liquid/tags/ifchanged.rb +11 -10
- data/lib/liquid/tags/include.rb +34 -47
- data/lib/liquid/tags/increment.rb +7 -3
- data/lib/liquid/tags/raw.rb +14 -11
- data/lib/liquid/tags/render.rb +84 -0
- data/lib/liquid/tags/table_row.rb +23 -19
- data/lib/liquid/tags/unless.rb +23 -15
- data/lib/liquid/template.rb +53 -72
- data/lib/liquid/template_factory.rb +9 -0
- data/lib/liquid/tokenizer.rb +18 -10
- data/lib/liquid/usage.rb +8 -0
- data/lib/liquid/utils.rb +13 -3
- data/lib/liquid/variable.rb +46 -41
- data/lib/liquid/variable_lookup.rb +11 -6
- data/lib/liquid/version.rb +2 -1
- data/lib/liquid.rb +17 -5
- data/test/integration/assign_test.rb +74 -5
- data/test/integration/blank_test.rb +11 -8
- data/test/integration/block_test.rb +47 -1
- data/test/integration/capture_test.rb +18 -10
- data/test/integration/context_test.rb +609 -5
- data/test/integration/document_test.rb +4 -2
- data/test/integration/drop_test.rb +67 -83
- data/test/integration/error_handling_test.rb +73 -61
- data/test/integration/expression_test.rb +46 -0
- data/test/integration/filter_test.rb +53 -42
- data/test/integration/hash_ordering_test.rb +5 -3
- data/test/integration/output_test.rb +26 -24
- data/test/integration/parsing_quirks_test.rb +19 -7
- data/test/integration/{render_profiling_test.rb → profiler_test.rb} +84 -25
- data/test/integration/security_test.rb +30 -21
- data/test/integration/standard_filter_test.rb +385 -281
- data/test/integration/tag/disableable_test.rb +59 -0
- data/test/integration/tag_test.rb +45 -0
- data/test/integration/tags/break_tag_test.rb +4 -2
- data/test/integration/tags/continue_tag_test.rb +4 -2
- data/test/integration/tags/echo_test.rb +13 -0
- data/test/integration/tags/for_tag_test.rb +107 -51
- data/test/integration/tags/if_else_tag_test.rb +5 -3
- data/test/integration/tags/include_tag_test.rb +70 -54
- data/test/integration/tags/increment_tag_test.rb +4 -2
- data/test/integration/tags/liquid_tag_test.rb +116 -0
- data/test/integration/tags/raw_tag_test.rb +14 -11
- data/test/integration/tags/render_tag_test.rb +213 -0
- data/test/integration/tags/standard_tag_test.rb +38 -31
- data/test/integration/tags/statements_test.rb +23 -21
- data/test/integration/tags/table_row_test.rb +2 -0
- data/test/integration/tags/unless_else_tag_test.rb +4 -2
- data/test/integration/template_test.rb +132 -124
- data/test/integration/trim_mode_test.rb +78 -44
- data/test/integration/variable_test.rb +74 -32
- data/test/test_helper.rb +113 -22
- data/test/unit/block_unit_test.rb +19 -24
- data/test/unit/condition_unit_test.rb +79 -77
- data/test/unit/file_system_unit_test.rb +6 -4
- data/test/unit/i18n_unit_test.rb +7 -5
- data/test/unit/lexer_unit_test.rb +11 -9
- data/test/{integration → unit}/parse_tree_visitor_test.rb +16 -2
- data/test/unit/parser_unit_test.rb +37 -35
- data/test/unit/partial_cache_unit_test.rb +128 -0
- data/test/unit/regexp_unit_test.rb +17 -15
- data/test/unit/static_registers_unit_test.rb +156 -0
- data/test/unit/strainer_factory_unit_test.rb +100 -0
- data/test/unit/strainer_template_unit_test.rb +82 -0
- data/test/unit/tag_unit_test.rb +5 -3
- data/test/unit/tags/case_tag_unit_test.rb +3 -1
- data/test/unit/tags/for_tag_unit_test.rb +4 -2
- data/test/unit/tags/if_tag_unit_test.rb +3 -1
- data/test/unit/template_factory_unit_test.rb +12 -0
- data/test/unit/template_unit_test.rb +19 -10
- data/test/unit/tokenizer_unit_test.rb +26 -19
- data/test/unit/variable_unit_test.rb +51 -49
- metadata +76 -50
- data/lib/liquid/strainer.rb +0 -66
- data/lib/liquid/truffle.rb +0 -5
- data/test/truffle/truffle_test.rb +0 -9
- data/test/unit/context_unit_test.rb +0 -489
- 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
|
10
|
-
markup
|
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
|
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 =
|
27
|
-
{%for item in array%}
|
28
|
-
|
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' => [
|
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
|
108
|
-
assigns['limit']
|
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
|
126
|
-
markup
|
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
|
145
|
-
markup
|
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
|
164
|
-
markup
|
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
|
183
|
-
markup
|
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
|
229
|
+
markup = '{% for i in array.items %}{% break %}{% endfor %}'
|
200
230
|
expected = ""
|
201
231
|
assert_template_result(expected, markup, assigns)
|
202
232
|
|
203
|
-
markup
|
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
|
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
|
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
|
218
|
-
markup
|
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
|
231
|
-
markup
|
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
|
269
|
+
markup = '{% for i in array.items %}{% continue %}{% endfor %}'
|
240
270
|
expected = ""
|
241
271
|
assert_template_result(expected, markup, assigns)
|
242
272
|
|
243
|
-
markup
|
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
|
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
|
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
|
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
|
261
|
-
markup
|
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
|
274
|
-
markup
|
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
|
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
|
363
|
-
assigns
|
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
|
368
|
-
assert
|
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
|
373
|
-
assigns
|
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
|
378
|
-
assert
|
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
|
383
|
-
assigns
|
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
|
388
|
-
assert
|
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
|
422
|
+
loader = LoaderDrop.new([1, 2, 3, 4, 5])
|
393
423
|
loader_assigns = { 'items' => loader }
|
394
|
-
array_assigns
|
395
|
-
expected
|
396
|
-
template
|
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
|
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
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'test_helper'
|
2
4
|
|
3
5
|
class IfElseTagTest < Minitest::Test
|
@@ -43,7 +45,7 @@ class IfElseTagTest < Minitest::Test
|
|
43
45
|
|
44
46
|
def test_comparison_of_strings_containing_and_or_or
|
45
47
|
awful_markup = "a == 'and' and b == 'or' and c == 'foo and bar' and d == 'bar or baz' and e == 'foo' and foo and bar"
|
46
|
-
assigns
|
48
|
+
assigns = { 'a' => 'and', 'b' => 'or', 'c' => 'foo and bar', 'd' => 'bar or baz', 'e' => 'foo', 'foo' => true, 'bar' => true }
|
47
49
|
assert_template_result(' YES ', "{% if #{awful_markup} %} YES {% endif %}", assigns)
|
48
50
|
end
|
49
51
|
|
@@ -132,7 +134,7 @@ class IfElseTagTest < Minitest::Test
|
|
132
134
|
end
|
133
135
|
|
134
136
|
def test_syntax_error_no_variable
|
135
|
-
assert_raises(SyntaxError){ assert_template_result('', '{% if jerry == 1 %}') }
|
137
|
+
assert_raises(SyntaxError) { assert_template_result('', '{% if jerry == 1 %}') }
|
136
138
|
end
|
137
139
|
|
138
140
|
def test_syntax_error_no_expression
|
@@ -182,7 +184,7 @@ class IfElseTagTest < Minitest::Test
|
|
182
184
|
tests.each do |vals, expected|
|
183
185
|
a, b, c = vals
|
184
186
|
assigns = { 'a' => a, 'b' => b, 'c' => c }
|
185
|
-
assert_template_result
|
187
|
+
assert_template_result(expected.to_s, tpl, assigns, assigns.to_s)
|
186
188
|
end
|
187
189
|
end
|
188
190
|
end
|