liquid 5.1.0 → 5.4.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 +35 -0
- data/README.md +4 -4
- data/lib/liquid/block_body.rb +6 -6
- data/lib/liquid/condition.rb +7 -1
- data/lib/liquid/context.rb +6 -2
- data/lib/liquid/expression.rb +11 -10
- data/lib/liquid/forloop_drop.rb +44 -1
- data/lib/liquid/locales/en.yml +6 -5
- data/lib/liquid/partial_cache.rb +3 -3
- data/lib/liquid/registers.rb +51 -0
- data/lib/liquid/standardfilters.rb +463 -75
- data/lib/liquid/strainer_factory.rb +15 -10
- data/lib/liquid/strainer_template.rb +9 -0
- data/lib/liquid/tablerowloop_drop.rb +58 -1
- data/lib/liquid/tags/assign.rb +12 -8
- data/lib/liquid/tags/break.rb +8 -0
- data/lib/liquid/tags/capture.rb +13 -10
- data/lib/liquid/tags/case.rb +21 -0
- data/lib/liquid/tags/comment.rb +13 -0
- data/lib/liquid/tags/continue.rb +8 -9
- data/lib/liquid/tags/cycle.rb +12 -11
- data/lib/liquid/tags/decrement.rb +16 -17
- data/lib/liquid/tags/echo.rb +16 -9
- data/lib/liquid/tags/for.rb +22 -43
- data/lib/liquid/tags/if.rb +11 -9
- data/lib/liquid/tags/include.rb +15 -13
- data/lib/liquid/tags/increment.rb +16 -14
- data/lib/liquid/tags/inline_comment.rb +43 -0
- data/lib/liquid/tags/raw.rb +11 -0
- data/lib/liquid/tags/render.rb +29 -4
- data/lib/liquid/tags/table_row.rb +22 -0
- data/lib/liquid/tags/unless.rb +15 -4
- data/lib/liquid/template.rb +2 -3
- data/lib/liquid/variable.rb +4 -4
- data/lib/liquid/variable_lookup.rb +10 -7
- data/lib/liquid/version.rb +1 -1
- data/lib/liquid.rb +4 -4
- metadata +7 -121
- data/lib/liquid/register.rb +0 -6
- data/lib/liquid/static_registers.rb +0 -44
- data/test/fixtures/en_locale.yml +0 -9
- data/test/integration/assign_test.rb +0 -117
- data/test/integration/blank_test.rb +0 -109
- data/test/integration/block_test.rb +0 -58
- data/test/integration/capture_test.rb +0 -58
- data/test/integration/context_test.rb +0 -636
- data/test/integration/document_test.rb +0 -21
- data/test/integration/drop_test.rb +0 -257
- data/test/integration/error_handling_test.rb +0 -272
- data/test/integration/expression_test.rb +0 -46
- data/test/integration/filter_test.rb +0 -189
- data/test/integration/hash_ordering_test.rb +0 -25
- data/test/integration/output_test.rb +0 -125
- data/test/integration/parsing_quirks_test.rb +0 -134
- data/test/integration/profiler_test.rb +0 -213
- data/test/integration/security_test.rb +0 -89
- data/test/integration/standard_filter_test.rb +0 -880
- data/test/integration/tag/disableable_test.rb +0 -59
- data/test/integration/tag_test.rb +0 -45
- data/test/integration/tags/break_tag_test.rb +0 -17
- data/test/integration/tags/continue_tag_test.rb +0 -17
- data/test/integration/tags/echo_test.rb +0 -13
- data/test/integration/tags/for_tag_test.rb +0 -466
- data/test/integration/tags/if_else_tag_test.rb +0 -190
- data/test/integration/tags/include_tag_test.rb +0 -269
- data/test/integration/tags/increment_tag_test.rb +0 -25
- data/test/integration/tags/liquid_tag_test.rb +0 -116
- data/test/integration/tags/raw_tag_test.rb +0 -34
- data/test/integration/tags/render_tag_test.rb +0 -213
- data/test/integration/tags/standard_tag_test.rb +0 -303
- data/test/integration/tags/statements_test.rb +0 -113
- data/test/integration/tags/table_row_test.rb +0 -66
- data/test/integration/tags/unless_else_tag_test.rb +0 -28
- data/test/integration/template_test.rb +0 -340
- data/test/integration/trim_mode_test.rb +0 -563
- data/test/integration/variable_test.rb +0 -138
- data/test/test_helper.rb +0 -207
- data/test/unit/block_unit_test.rb +0 -53
- data/test/unit/condition_unit_test.rb +0 -168
- data/test/unit/file_system_unit_test.rb +0 -37
- data/test/unit/i18n_unit_test.rb +0 -39
- data/test/unit/lexer_unit_test.rb +0 -53
- data/test/unit/parse_tree_visitor_test.rb +0 -261
- data/test/unit/parser_unit_test.rb +0 -84
- data/test/unit/partial_cache_unit_test.rb +0 -128
- data/test/unit/regexp_unit_test.rb +0 -46
- data/test/unit/static_registers_unit_test.rb +0 -156
- data/test/unit/strainer_factory_unit_test.rb +0 -100
- data/test/unit/strainer_template_unit_test.rb +0 -82
- data/test/unit/tag_unit_test.rb +0 -23
- data/test/unit/tags/case_tag_unit_test.rb +0 -12
- data/test/unit/tags/for_tag_unit_test.rb +0 -15
- data/test/unit/tags/if_tag_unit_test.rb +0 -10
- data/test/unit/template_factory_unit_test.rb +0 -12
- data/test/unit/template_unit_test.rb +0 -87
- data/test/unit/tokenizer_unit_test.rb +0 -62
- data/test/unit/variable_unit_test.rb +0 -164
@@ -1,190 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class IfElseTagTest < Minitest::Test
|
6
|
-
include Liquid
|
7
|
-
|
8
|
-
def test_if
|
9
|
-
assert_template_result(' ', ' {% if false %} this text should not go into the output {% endif %} ')
|
10
|
-
assert_template_result(' this text should go into the output ',
|
11
|
-
' {% if true %} this text should go into the output {% endif %} ')
|
12
|
-
assert_template_result(' you rock ?', '{% if false %} you suck {% endif %} {% if true %} you rock {% endif %}?')
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_literal_comparisons
|
16
|
-
assert_template_result(' NO ', '{% assign v = false %}{% if v %} YES {% else %} NO {% endif %}')
|
17
|
-
assert_template_result(' YES ', '{% assign v = nil %}{% if v == nil %} YES {% else %} NO {% endif %}')
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_if_else
|
21
|
-
assert_template_result(' YES ', '{% if false %} NO {% else %} YES {% endif %}')
|
22
|
-
assert_template_result(' YES ', '{% if true %} YES {% else %} NO {% endif %}')
|
23
|
-
assert_template_result(' YES ', '{% if "foo" %} YES {% else %} NO {% endif %}')
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_if_boolean
|
27
|
-
assert_template_result(' YES ', '{% if var %} YES {% endif %}', 'var' => true)
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_if_or
|
31
|
-
assert_template_result(' YES ', '{% if a or b %} YES {% endif %}', 'a' => true, 'b' => true)
|
32
|
-
assert_template_result(' YES ', '{% if a or b %} YES {% endif %}', 'a' => true, 'b' => false)
|
33
|
-
assert_template_result(' YES ', '{% if a or b %} YES {% endif %}', 'a' => false, 'b' => true)
|
34
|
-
assert_template_result('', '{% if a or b %} YES {% endif %}', 'a' => false, 'b' => false)
|
35
|
-
|
36
|
-
assert_template_result(' YES ', '{% if a or b or c %} YES {% endif %}', 'a' => false, 'b' => false, 'c' => true)
|
37
|
-
assert_template_result('', '{% if a or b or c %} YES {% endif %}', 'a' => false, 'b' => false, 'c' => false)
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_if_or_with_operators
|
41
|
-
assert_template_result(' YES ', '{% if a == true or b == true %} YES {% endif %}', 'a' => true, 'b' => true)
|
42
|
-
assert_template_result(' YES ', '{% if a == true or b == false %} YES {% endif %}', 'a' => true, 'b' => true)
|
43
|
-
assert_template_result('', '{% if a == false or b == false %} YES {% endif %}', 'a' => true, 'b' => true)
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_comparison_of_strings_containing_and_or_or
|
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"
|
48
|
-
assigns = { 'a' => 'and', 'b' => 'or', 'c' => 'foo and bar', 'd' => 'bar or baz', 'e' => 'foo', 'foo' => true, 'bar' => true }
|
49
|
-
assert_template_result(' YES ', "{% if #{awful_markup} %} YES {% endif %}", assigns)
|
50
|
-
end
|
51
|
-
|
52
|
-
def test_comparison_of_expressions_starting_with_and_or_or
|
53
|
-
assigns = { 'order' => { 'items_count' => 0 }, 'android' => { 'name' => 'Roy' } }
|
54
|
-
assert_template_result("YES",
|
55
|
-
"{% if android.name == 'Roy' %}YES{% endif %}",
|
56
|
-
assigns)
|
57
|
-
assert_template_result("YES",
|
58
|
-
"{% if order.items_count == 0 %}YES{% endif %}",
|
59
|
-
assigns)
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_if_and
|
63
|
-
assert_template_result(' YES ', '{% if true and true %} YES {% endif %}')
|
64
|
-
assert_template_result('', '{% if false and true %} YES {% endif %}')
|
65
|
-
assert_template_result('', '{% if false and true %} YES {% endif %}')
|
66
|
-
end
|
67
|
-
|
68
|
-
def test_hash_miss_generates_false
|
69
|
-
assert_template_result('', '{% if foo.bar %} NO {% endif %}', 'foo' => {})
|
70
|
-
end
|
71
|
-
|
72
|
-
def test_if_from_variable
|
73
|
-
assert_template_result('', '{% if var %} NO {% endif %}', 'var' => false)
|
74
|
-
assert_template_result('', '{% if var %} NO {% endif %}', 'var' => nil)
|
75
|
-
assert_template_result('', '{% if foo.bar %} NO {% endif %}', 'foo' => { 'bar' => false })
|
76
|
-
assert_template_result('', '{% if foo.bar %} NO {% endif %}', 'foo' => {})
|
77
|
-
assert_template_result('', '{% if foo.bar %} NO {% endif %}', 'foo' => nil)
|
78
|
-
assert_template_result('', '{% if foo.bar %} NO {% endif %}', 'foo' => true)
|
79
|
-
|
80
|
-
assert_template_result(' YES ', '{% if var %} YES {% endif %}', 'var' => "text")
|
81
|
-
assert_template_result(' YES ', '{% if var %} YES {% endif %}', 'var' => true)
|
82
|
-
assert_template_result(' YES ', '{% if var %} YES {% endif %}', 'var' => 1)
|
83
|
-
assert_template_result(' YES ', '{% if var %} YES {% endif %}', 'var' => {})
|
84
|
-
assert_template_result(' YES ', '{% if var %} YES {% endif %}', 'var' => [])
|
85
|
-
assert_template_result(' YES ', '{% if "foo" %} YES {% endif %}')
|
86
|
-
assert_template_result(' YES ', '{% if foo.bar %} YES {% endif %}', 'foo' => { 'bar' => true })
|
87
|
-
assert_template_result(' YES ', '{% if foo.bar %} YES {% endif %}', 'foo' => { 'bar' => "text" })
|
88
|
-
assert_template_result(' YES ', '{% if foo.bar %} YES {% endif %}', 'foo' => { 'bar' => 1 })
|
89
|
-
assert_template_result(' YES ', '{% if foo.bar %} YES {% endif %}', 'foo' => { 'bar' => {} })
|
90
|
-
assert_template_result(' YES ', '{% if foo.bar %} YES {% endif %}', 'foo' => { 'bar' => [] })
|
91
|
-
|
92
|
-
assert_template_result(' YES ', '{% if var %} NO {% else %} YES {% endif %}', 'var' => false)
|
93
|
-
assert_template_result(' YES ', '{% if var %} NO {% else %} YES {% endif %}', 'var' => nil)
|
94
|
-
assert_template_result(' YES ', '{% if var %} YES {% else %} NO {% endif %}', 'var' => true)
|
95
|
-
assert_template_result(' YES ', '{% if "foo" %} YES {% else %} NO {% endif %}', 'var' => "text")
|
96
|
-
|
97
|
-
assert_template_result(' YES ', '{% if foo.bar %} NO {% else %} YES {% endif %}', 'foo' => { 'bar' => false })
|
98
|
-
assert_template_result(' YES ', '{% if foo.bar %} YES {% else %} NO {% endif %}', 'foo' => { 'bar' => true })
|
99
|
-
assert_template_result(' YES ', '{% if foo.bar %} YES {% else %} NO {% endif %}', 'foo' => { 'bar' => "text" })
|
100
|
-
assert_template_result(' YES ', '{% if foo.bar %} NO {% else %} YES {% endif %}', 'foo' => { 'notbar' => true })
|
101
|
-
assert_template_result(' YES ', '{% if foo.bar %} NO {% else %} YES {% endif %}', 'foo' => {})
|
102
|
-
assert_template_result(' YES ', '{% if foo.bar %} NO {% else %} YES {% endif %}', 'notfoo' => { 'bar' => true })
|
103
|
-
end
|
104
|
-
|
105
|
-
def test_nested_if
|
106
|
-
assert_template_result('', '{% if false %}{% if false %} NO {% endif %}{% endif %}')
|
107
|
-
assert_template_result('', '{% if false %}{% if true %} NO {% endif %}{% endif %}')
|
108
|
-
assert_template_result('', '{% if true %}{% if false %} NO {% endif %}{% endif %}')
|
109
|
-
assert_template_result(' YES ', '{% if true %}{% if true %} YES {% endif %}{% endif %}')
|
110
|
-
|
111
|
-
assert_template_result(' YES ', '{% if true %}{% if true %} YES {% else %} NO {% endif %}{% else %} NO {% endif %}')
|
112
|
-
assert_template_result(' YES ', '{% if true %}{% if false %} NO {% else %} YES {% endif %}{% else %} NO {% endif %}')
|
113
|
-
assert_template_result(' YES ', '{% if false %}{% if true %} NO {% else %} NONO {% endif %}{% else %} YES {% endif %}')
|
114
|
-
end
|
115
|
-
|
116
|
-
def test_comparisons_on_null
|
117
|
-
assert_template_result('', '{% if null < 10 %} NO {% endif %}')
|
118
|
-
assert_template_result('', '{% if null <= 10 %} NO {% endif %}')
|
119
|
-
assert_template_result('', '{% if null >= 10 %} NO {% endif %}')
|
120
|
-
assert_template_result('', '{% if null > 10 %} NO {% endif %}')
|
121
|
-
|
122
|
-
assert_template_result('', '{% if 10 < null %} NO {% endif %}')
|
123
|
-
assert_template_result('', '{% if 10 <= null %} NO {% endif %}')
|
124
|
-
assert_template_result('', '{% if 10 >= null %} NO {% endif %}')
|
125
|
-
assert_template_result('', '{% if 10 > null %} NO {% endif %}')
|
126
|
-
end
|
127
|
-
|
128
|
-
def test_else_if
|
129
|
-
assert_template_result('0', '{% if 0 == 0 %}0{% elsif 1 == 1%}1{% else %}2{% endif %}')
|
130
|
-
assert_template_result('1', '{% if 0 != 0 %}0{% elsif 1 == 1%}1{% else %}2{% endif %}')
|
131
|
-
assert_template_result('2', '{% if 0 != 0 %}0{% elsif 1 != 1%}1{% else %}2{% endif %}')
|
132
|
-
|
133
|
-
assert_template_result('elsif', '{% if false %}if{% elsif true %}elsif{% endif %}')
|
134
|
-
end
|
135
|
-
|
136
|
-
def test_syntax_error_no_variable
|
137
|
-
assert_raises(SyntaxError) { assert_template_result('', '{% if jerry == 1 %}') }
|
138
|
-
end
|
139
|
-
|
140
|
-
def test_syntax_error_no_expression
|
141
|
-
assert_raises(SyntaxError) { assert_template_result('', '{% if %}') }
|
142
|
-
end
|
143
|
-
|
144
|
-
def test_if_with_custom_condition
|
145
|
-
original_op = Condition.operators['contains']
|
146
|
-
Condition.operators['contains'] = :[]
|
147
|
-
|
148
|
-
assert_template_result('yes', %({% if 'bob' contains 'o' %}yes{% endif %}))
|
149
|
-
assert_template_result('no', %({% if 'bob' contains 'f' %}yes{% else %}no{% endif %}))
|
150
|
-
ensure
|
151
|
-
Condition.operators['contains'] = original_op
|
152
|
-
end
|
153
|
-
|
154
|
-
def test_operators_are_ignored_unless_isolated
|
155
|
-
original_op = Condition.operators['contains']
|
156
|
-
Condition.operators['contains'] = :[]
|
157
|
-
|
158
|
-
assert_template_result('yes',
|
159
|
-
%({% if 'gnomeslab-and-or-liquid' contains 'gnomeslab-and-or-liquid' %}yes{% endif %}))
|
160
|
-
ensure
|
161
|
-
Condition.operators['contains'] = original_op
|
162
|
-
end
|
163
|
-
|
164
|
-
def test_operators_are_whitelisted
|
165
|
-
assert_raises(SyntaxError) do
|
166
|
-
assert_template_result('', %({% if 1 or throw or or 1 %}yes{% endif %}))
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
def test_multiple_conditions
|
171
|
-
tpl = "{% if a or b and c %}true{% else %}false{% endif %}"
|
172
|
-
|
173
|
-
tests = {
|
174
|
-
[true, true, true] => true,
|
175
|
-
[true, true, false] => true,
|
176
|
-
[true, false, true] => true,
|
177
|
-
[true, false, false] => true,
|
178
|
-
[false, true, true] => true,
|
179
|
-
[false, true, false] => false,
|
180
|
-
[false, false, true] => false,
|
181
|
-
[false, false, false] => false,
|
182
|
-
}
|
183
|
-
|
184
|
-
tests.each do |vals, expected|
|
185
|
-
a, b, c = vals
|
186
|
-
assigns = { 'a' => a, 'b' => b, 'c' => c }
|
187
|
-
assert_template_result(expected.to_s, tpl, assigns, assigns.to_s)
|
188
|
-
end
|
189
|
-
end
|
190
|
-
end
|
@@ -1,269 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class TestFileSystem
|
6
|
-
def read_template_file(template_path)
|
7
|
-
case template_path
|
8
|
-
when "product"
|
9
|
-
"Product: {{ product.title }} "
|
10
|
-
|
11
|
-
when "product_alias"
|
12
|
-
"Product: {{ product.title }} "
|
13
|
-
|
14
|
-
when "locale_variables"
|
15
|
-
"Locale: {{echo1}} {{echo2}}"
|
16
|
-
|
17
|
-
when "variant"
|
18
|
-
"Variant: {{ variant.title }}"
|
19
|
-
|
20
|
-
when "nested_template"
|
21
|
-
"{% include 'header' %} {% include 'body' %} {% include 'footer' %}"
|
22
|
-
|
23
|
-
when "body"
|
24
|
-
"body {% include 'body_detail' %}"
|
25
|
-
|
26
|
-
when "nested_product_template"
|
27
|
-
"Product: {{ nested_product_template.title }} {%include 'details'%} "
|
28
|
-
|
29
|
-
when "recursively_nested_template"
|
30
|
-
"-{% include 'recursively_nested_template' %}"
|
31
|
-
|
32
|
-
when "pick_a_source"
|
33
|
-
"from TestFileSystem"
|
34
|
-
|
35
|
-
when 'assignments'
|
36
|
-
"{% assign foo = 'bar' %}"
|
37
|
-
|
38
|
-
when 'break'
|
39
|
-
"{% break %}"
|
40
|
-
|
41
|
-
else
|
42
|
-
template_path
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
class OtherFileSystem
|
48
|
-
def read_template_file(_template_path)
|
49
|
-
'from OtherFileSystem'
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
class CountingFileSystem
|
54
|
-
attr_reader :count
|
55
|
-
def read_template_file(_template_path)
|
56
|
-
@count ||= 0
|
57
|
-
@count += 1
|
58
|
-
'from CountingFileSystem'
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
class CustomInclude < Liquid::Tag
|
63
|
-
Syntax = /(#{Liquid::QuotedFragment}+)(\s+(?:with|for)\s+(#{Liquid::QuotedFragment}+))?/o
|
64
|
-
|
65
|
-
def initialize(tag_name, markup, tokens)
|
66
|
-
markup =~ Syntax
|
67
|
-
@template_name = Regexp.last_match(1)
|
68
|
-
super
|
69
|
-
end
|
70
|
-
|
71
|
-
def parse(tokens)
|
72
|
-
end
|
73
|
-
|
74
|
-
def render_to_output_buffer(_context, output)
|
75
|
-
output << @template_name[1..-2]
|
76
|
-
output
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
class IncludeTagTest < Minitest::Test
|
81
|
-
include Liquid
|
82
|
-
|
83
|
-
def setup
|
84
|
-
Liquid::Template.file_system = TestFileSystem.new
|
85
|
-
end
|
86
|
-
|
87
|
-
def test_include_tag_looks_for_file_system_in_registers_first
|
88
|
-
assert_equal('from OtherFileSystem',
|
89
|
-
Template.parse("{% include 'pick_a_source' %}").render!({}, registers: { file_system: OtherFileSystem.new }))
|
90
|
-
end
|
91
|
-
|
92
|
-
def test_include_tag_with
|
93
|
-
assert_template_result("Product: Draft 151cm ",
|
94
|
-
"{% include 'product' with products[0] %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }])
|
95
|
-
end
|
96
|
-
|
97
|
-
def test_include_tag_with_alias
|
98
|
-
assert_template_result("Product: Draft 151cm ",
|
99
|
-
"{% include 'product_alias' with products[0] as product %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }])
|
100
|
-
end
|
101
|
-
|
102
|
-
def test_include_tag_for_alias
|
103
|
-
assert_template_result("Product: Draft 151cm Product: Element 155cm ",
|
104
|
-
"{% include 'product_alias' for products as product %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }])
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_include_tag_with_default_name
|
108
|
-
assert_template_result("Product: Draft 151cm ",
|
109
|
-
"{% include 'product' %}", "product" => { 'title' => 'Draft 151cm' })
|
110
|
-
end
|
111
|
-
|
112
|
-
def test_include_tag_for
|
113
|
-
assert_template_result("Product: Draft 151cm Product: Element 155cm ",
|
114
|
-
"{% include 'product' for products %}", "products" => [{ 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' }])
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_include_tag_with_local_variables
|
118
|
-
assert_template_result("Locale: test123 ", "{% include 'locale_variables' echo1: 'test123' %}")
|
119
|
-
end
|
120
|
-
|
121
|
-
def test_include_tag_with_multiple_local_variables
|
122
|
-
assert_template_result("Locale: test123 test321",
|
123
|
-
"{% include 'locale_variables' echo1: 'test123', echo2: 'test321' %}")
|
124
|
-
end
|
125
|
-
|
126
|
-
def test_include_tag_with_multiple_local_variables_from_context
|
127
|
-
assert_template_result("Locale: test123 test321",
|
128
|
-
"{% include 'locale_variables' echo1: echo1, echo2: more_echos.echo2 %}",
|
129
|
-
'echo1' => 'test123', 'more_echos' => { "echo2" => 'test321' })
|
130
|
-
end
|
131
|
-
|
132
|
-
def test_included_templates_assigns_variables
|
133
|
-
assert_template_result("bar", "{% include 'assignments' %}{{ foo }}")
|
134
|
-
end
|
135
|
-
|
136
|
-
def test_nested_include_tag
|
137
|
-
assert_template_result("body body_detail", "{% include 'body' %}")
|
138
|
-
|
139
|
-
assert_template_result("header body body_detail footer", "{% include 'nested_template' %}")
|
140
|
-
end
|
141
|
-
|
142
|
-
def test_nested_include_with_variable
|
143
|
-
assert_template_result("Product: Draft 151cm details ",
|
144
|
-
"{% include 'nested_product_template' with product %}", "product" => { "title" => 'Draft 151cm' })
|
145
|
-
|
146
|
-
assert_template_result("Product: Draft 151cm details Product: Element 155cm details ",
|
147
|
-
"{% include 'nested_product_template' for products %}", "products" => [{ "title" => 'Draft 151cm' }, { "title" => 'Element 155cm' }])
|
148
|
-
end
|
149
|
-
|
150
|
-
def test_recursively_included_template_does_not_produce_endless_loop
|
151
|
-
infinite_file_system = Class.new do
|
152
|
-
def read_template_file(_template_path)
|
153
|
-
"-{% include 'loop' %}"
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
Liquid::Template.file_system = infinite_file_system.new
|
158
|
-
|
159
|
-
assert_raises(Liquid::StackLevelError) do
|
160
|
-
Template.parse("{% include 'loop' %}").render!
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
def test_dynamically_choosen_template
|
165
|
-
assert_template_result("Test123", "{% include template %}", "template" => 'Test123')
|
166
|
-
assert_template_result("Test321", "{% include template %}", "template" => 'Test321')
|
167
|
-
|
168
|
-
assert_template_result("Product: Draft 151cm ", "{% include template for product %}",
|
169
|
-
"template" => 'product', 'product' => { 'title' => 'Draft 151cm' })
|
170
|
-
end
|
171
|
-
|
172
|
-
def test_include_tag_caches_second_read_of_same_partial
|
173
|
-
file_system = CountingFileSystem.new
|
174
|
-
assert_equal('from CountingFileSystemfrom CountingFileSystem',
|
175
|
-
Template.parse("{% include 'pick_a_source' %}{% include 'pick_a_source' %}").render!({}, registers: { file_system: file_system }))
|
176
|
-
assert_equal(1, file_system.count)
|
177
|
-
end
|
178
|
-
|
179
|
-
def test_include_tag_doesnt_cache_partials_across_renders
|
180
|
-
file_system = CountingFileSystem.new
|
181
|
-
assert_equal('from CountingFileSystem',
|
182
|
-
Template.parse("{% include 'pick_a_source' %}").render!({}, registers: { file_system: file_system }))
|
183
|
-
assert_equal(1, file_system.count)
|
184
|
-
|
185
|
-
assert_equal('from CountingFileSystem',
|
186
|
-
Template.parse("{% include 'pick_a_source' %}").render!({}, registers: { file_system: file_system }))
|
187
|
-
assert_equal(2, file_system.count)
|
188
|
-
end
|
189
|
-
|
190
|
-
def test_include_tag_within_if_statement
|
191
|
-
assert_template_result("foo_if_true", "{% if true %}{% include 'foo_if_true' %}{% endif %}")
|
192
|
-
end
|
193
|
-
|
194
|
-
def test_custom_include_tag
|
195
|
-
original_tag = Liquid::Template.tags['include']
|
196
|
-
Liquid::Template.tags['include'] = CustomInclude
|
197
|
-
begin
|
198
|
-
assert_equal("custom_foo",
|
199
|
-
Template.parse("{% include 'custom_foo' %}").render!)
|
200
|
-
ensure
|
201
|
-
Liquid::Template.tags['include'] = original_tag
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
def test_custom_include_tag_within_if_statement
|
206
|
-
original_tag = Liquid::Template.tags['include']
|
207
|
-
Liquid::Template.tags['include'] = CustomInclude
|
208
|
-
begin
|
209
|
-
assert_equal("custom_foo_if_true",
|
210
|
-
Template.parse("{% if true %}{% include 'custom_foo_if_true' %}{% endif %}").render!)
|
211
|
-
ensure
|
212
|
-
Liquid::Template.tags['include'] = original_tag
|
213
|
-
end
|
214
|
-
end
|
215
|
-
|
216
|
-
def test_does_not_add_error_in_strict_mode_for_missing_variable
|
217
|
-
Liquid::Template.file_system = TestFileSystem.new
|
218
|
-
|
219
|
-
a = Liquid::Template.parse(' {% include "nested_template" %}')
|
220
|
-
a.render!
|
221
|
-
assert_empty(a.errors)
|
222
|
-
end
|
223
|
-
|
224
|
-
def test_passing_options_to_included_templates
|
225
|
-
assert_raises(Liquid::SyntaxError) do
|
226
|
-
Template.parse("{% include template %}", error_mode: :strict).render!("template" => '{{ "X" || downcase }}')
|
227
|
-
end
|
228
|
-
with_error_mode(:lax) do
|
229
|
-
assert_equal('x', Template.parse("{% include template %}", error_mode: :strict, include_options_blacklist: true).render!("template" => '{{ "X" || downcase }}'))
|
230
|
-
end
|
231
|
-
assert_raises(Liquid::SyntaxError) do
|
232
|
-
Template.parse("{% include template %}", error_mode: :strict, include_options_blacklist: [:locale]).render!("template" => '{{ "X" || downcase }}')
|
233
|
-
end
|
234
|
-
with_error_mode(:lax) do
|
235
|
-
assert_equal('x', Template.parse("{% include template %}", error_mode: :strict, include_options_blacklist: [:error_mode]).render!("template" => '{{ "X" || downcase }}'))
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
def test_render_raise_argument_error_when_template_is_undefined
|
240
|
-
assert_raises(Liquid::ArgumentError) do
|
241
|
-
template = Liquid::Template.parse('{% include undefined_variable %}')
|
242
|
-
template.render!
|
243
|
-
end
|
244
|
-
assert_raises(Liquid::ArgumentError) do
|
245
|
-
template = Liquid::Template.parse('{% include nil %}')
|
246
|
-
template.render!
|
247
|
-
end
|
248
|
-
end
|
249
|
-
|
250
|
-
def test_including_via_variable_value
|
251
|
-
assert_template_result("from TestFileSystem", "{% assign page = 'pick_a_source' %}{% include page %}")
|
252
|
-
|
253
|
-
assert_template_result("Product: Draft 151cm ", "{% assign page = 'product' %}{% include page %}", "product" => { 'title' => 'Draft 151cm' })
|
254
|
-
|
255
|
-
assert_template_result("Product: Draft 151cm ", "{% assign page = 'product' %}{% include page for foo %}", "foo" => { 'title' => 'Draft 151cm' })
|
256
|
-
end
|
257
|
-
|
258
|
-
def test_including_with_strict_variables
|
259
|
-
template = Liquid::Template.parse("{% include 'simple' %}", error_mode: :warn)
|
260
|
-
template.render(nil, strict_variables: true)
|
261
|
-
|
262
|
-
assert_equal([], template.errors)
|
263
|
-
end
|
264
|
-
|
265
|
-
def test_break_through_include
|
266
|
-
assert_template_result("1", "{% for i in (1..3) %}{{ i }}{% break %}{{ i }}{% endfor %}")
|
267
|
-
assert_template_result("1", "{% for i in (1..3) %}{{ i }}{% include 'break' %}{{ i }}{% endfor %}")
|
268
|
-
end
|
269
|
-
end # IncludeTagTest
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class IncrementTagTest < Minitest::Test
|
6
|
-
include Liquid
|
7
|
-
|
8
|
-
def test_inc
|
9
|
-
assert_template_result('0', '{%increment port %}', {})
|
10
|
-
assert_template_result('0 1', '{%increment port %} {%increment port%}', {})
|
11
|
-
assert_template_result('0 0 1 2 1',
|
12
|
-
'{%increment port %} {%increment starboard%} ' \
|
13
|
-
'{%increment port %} {%increment port%} ' \
|
14
|
-
'{%increment starboard %}', {})
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_dec
|
18
|
-
assert_template_result('9', '{%decrement port %}', 'port' => 10)
|
19
|
-
assert_template_result('-1 -2', '{%decrement port %} {%decrement port%}', {})
|
20
|
-
assert_template_result('1 5 2 2 5',
|
21
|
-
'{%increment port %} {%increment starboard%} ' \
|
22
|
-
'{%increment port %} {%decrement port%} ' \
|
23
|
-
'{%decrement starboard %}', 'port' => 1, 'starboard' => 5)
|
24
|
-
end
|
25
|
-
end
|
@@ -1,116 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class LiquidTagTest < Minitest::Test
|
6
|
-
include Liquid
|
7
|
-
|
8
|
-
def test_liquid_tag
|
9
|
-
assert_template_result('1 2 3', <<~LIQUID, 'array' => [1, 2, 3])
|
10
|
-
{%- liquid
|
11
|
-
echo array | join: " "
|
12
|
-
-%}
|
13
|
-
LIQUID
|
14
|
-
|
15
|
-
assert_template_result('1 2 3', <<~LIQUID, 'array' => [1, 2, 3])
|
16
|
-
{%- liquid
|
17
|
-
for value in array
|
18
|
-
echo value
|
19
|
-
unless forloop.last
|
20
|
-
echo " "
|
21
|
-
endunless
|
22
|
-
endfor
|
23
|
-
-%}
|
24
|
-
LIQUID
|
25
|
-
|
26
|
-
assert_template_result('4 8 12 6', <<~LIQUID, 'array' => [1, 2, 3])
|
27
|
-
{%- liquid
|
28
|
-
for value in array
|
29
|
-
assign double_value = value | times: 2
|
30
|
-
echo double_value | times: 2
|
31
|
-
unless forloop.last
|
32
|
-
echo " "
|
33
|
-
endunless
|
34
|
-
endfor
|
35
|
-
|
36
|
-
echo " "
|
37
|
-
echo double_value
|
38
|
-
-%}
|
39
|
-
LIQUID
|
40
|
-
|
41
|
-
assert_template_result('abc', <<~LIQUID)
|
42
|
-
{%- liquid echo "a" -%}
|
43
|
-
b
|
44
|
-
{%- liquid echo "c" -%}
|
45
|
-
LIQUID
|
46
|
-
end
|
47
|
-
|
48
|
-
def test_liquid_tag_errors
|
49
|
-
assert_match_syntax_error("syntax error (line 1): Unknown tag 'error'", <<~LIQUID)
|
50
|
-
{%- liquid error no such tag -%}
|
51
|
-
LIQUID
|
52
|
-
|
53
|
-
assert_match_syntax_error("syntax error (line 7): Unknown tag 'error'", <<~LIQUID)
|
54
|
-
{{ test }}
|
55
|
-
|
56
|
-
{%-
|
57
|
-
liquid
|
58
|
-
for value in array
|
59
|
-
|
60
|
-
error no such tag
|
61
|
-
endfor
|
62
|
-
-%}
|
63
|
-
LIQUID
|
64
|
-
|
65
|
-
assert_match_syntax_error("syntax error (line 2): Unknown tag '!!! the guards are vigilant'", <<~LIQUID)
|
66
|
-
{%- liquid
|
67
|
-
!!! the guards are vigilant
|
68
|
-
-%}
|
69
|
-
LIQUID
|
70
|
-
|
71
|
-
assert_match_syntax_error("syntax error (line 4): 'for' tag was never closed", <<~LIQUID)
|
72
|
-
{%- liquid
|
73
|
-
for value in array
|
74
|
-
echo 'forgot to close the for tag'
|
75
|
-
-%}
|
76
|
-
LIQUID
|
77
|
-
end
|
78
|
-
|
79
|
-
def test_line_number_is_correct_after_a_blank_token
|
80
|
-
assert_match_syntax_error("syntax error (line 3): Unknown tag 'error'", "{% liquid echo ''\n\n error %}")
|
81
|
-
assert_match_syntax_error("syntax error (line 3): Unknown tag 'error'", "{% liquid echo ''\n \n error %}")
|
82
|
-
end
|
83
|
-
|
84
|
-
def test_nested_liquid_tag
|
85
|
-
assert_template_result('good', <<~LIQUID)
|
86
|
-
{%- if true %}
|
87
|
-
{%- liquid
|
88
|
-
echo "good"
|
89
|
-
%}
|
90
|
-
{%- endif -%}
|
91
|
-
LIQUID
|
92
|
-
end
|
93
|
-
|
94
|
-
def test_cannot_open_blocks_living_past_a_liquid_tag
|
95
|
-
assert_match_syntax_error("syntax error (line 3): 'if' tag was never closed", <<~LIQUID)
|
96
|
-
{%- liquid
|
97
|
-
if true
|
98
|
-
-%}
|
99
|
-
{%- endif -%}
|
100
|
-
LIQUID
|
101
|
-
end
|
102
|
-
|
103
|
-
def test_cannot_close_blocks_created_before_a_liquid_tag
|
104
|
-
assert_match_syntax_error("syntax error (line 3): 'endif' is not a valid delimiter for liquid tags. use %}", <<~LIQUID)
|
105
|
-
{%- if true -%}
|
106
|
-
42
|
107
|
-
{%- liquid endif -%}
|
108
|
-
LIQUID
|
109
|
-
end
|
110
|
-
|
111
|
-
def test_liquid_tag_in_raw
|
112
|
-
assert_template_result("{% liquid echo 'test' %}\n", <<~LIQUID)
|
113
|
-
{% raw %}{% liquid echo 'test' %}{% endraw %}
|
114
|
-
LIQUID
|
115
|
-
end
|
116
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class RawTagTest < Minitest::Test
|
6
|
-
include Liquid
|
7
|
-
|
8
|
-
def test_tag_in_raw
|
9
|
-
assert_template_result('{% comment %} test {% endcomment %}',
|
10
|
-
'{% raw %}{% comment %} test {% endcomment %}{% endraw %}')
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_output_in_raw
|
14
|
-
assert_template_result('{{ test }}', '{% raw %}{{ test }}{% endraw %}')
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_open_tag_in_raw
|
18
|
-
assert_template_result(' Foobar {% invalid ', '{% raw %} Foobar {% invalid {% endraw %}')
|
19
|
-
assert_template_result(' Foobar invalid %} ', '{% raw %} Foobar invalid %} {% endraw %}')
|
20
|
-
assert_template_result(' Foobar {{ invalid ', '{% raw %} Foobar {{ invalid {% endraw %}')
|
21
|
-
assert_template_result(' Foobar invalid }} ', '{% raw %} Foobar invalid }} {% endraw %}')
|
22
|
-
assert_template_result(' Foobar {% invalid {% {% endraw ', '{% raw %} Foobar {% invalid {% {% endraw {% endraw %}')
|
23
|
-
assert_template_result(' Foobar {% {% {% ', '{% raw %} Foobar {% {% {% {% endraw %}')
|
24
|
-
assert_template_result(' test {% raw %} {% endraw %}', '{% raw %} test {% raw %} {% {% endraw %}endraw %}')
|
25
|
-
assert_template_result(' Foobar {{ invalid 1', '{% raw %} Foobar {{ invalid {% endraw %}{{ 1 }}')
|
26
|
-
assert_template_result(' Foobar {% foo {% bar %}', '{% raw %} Foobar {% foo {% bar %}{% endraw %}')
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_invalid_raw
|
30
|
-
assert_match_syntax_error(/tag was never closed/, '{% raw %} foo')
|
31
|
-
assert_match_syntax_error(/Valid syntax/, '{% raw } foo {% endraw %}')
|
32
|
-
assert_match_syntax_error(/Valid syntax/, '{% raw } foo %}{% endraw %}')
|
33
|
-
end
|
34
|
-
end
|