liquid 3.0.6 → 4.0.0.rc1
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 +89 -58
- data/{MIT-LICENSE → LICENSE} +0 -0
- data/lib/liquid.rb +7 -6
- data/lib/liquid/block.rb +31 -124
- data/lib/liquid/block_body.rb +54 -57
- data/lib/liquid/condition.rb +23 -22
- data/lib/liquid/context.rb +50 -42
- data/lib/liquid/document.rb +19 -9
- data/lib/liquid/drop.rb +12 -13
- data/lib/liquid/errors.rb +16 -17
- data/lib/liquid/expression.rb +15 -3
- data/lib/liquid/extensions.rb +7 -7
- data/lib/liquid/file_system.rb +3 -3
- data/lib/liquid/forloop_drop.rb +42 -0
- data/lib/liquid/i18n.rb +5 -5
- data/lib/liquid/interrupts.rb +1 -2
- data/lib/liquid/lexer.rb +6 -4
- data/lib/liquid/locales/en.yml +3 -1
- data/lib/liquid/parse_context.rb +37 -0
- data/lib/liquid/parser_switching.rb +4 -4
- data/lib/liquid/profiler.rb +18 -19
- data/lib/liquid/profiler/hooks.rb +7 -7
- data/lib/liquid/range_lookup.rb +16 -1
- data/lib/liquid/resource_limits.rb +23 -0
- data/lib/liquid/standardfilters.rb +101 -56
- data/lib/liquid/strainer.rb +4 -5
- data/lib/liquid/tablerowloop_drop.rb +62 -0
- data/lib/liquid/tag.rb +9 -8
- data/lib/liquid/tags/assign.rb +5 -4
- data/lib/liquid/tags/break.rb +0 -3
- data/lib/liquid/tags/capture.rb +1 -1
- data/lib/liquid/tags/case.rb +19 -12
- data/lib/liquid/tags/comment.rb +2 -2
- data/lib/liquid/tags/cycle.rb +6 -6
- data/lib/liquid/tags/decrement.rb +1 -4
- data/lib/liquid/tags/for.rb +93 -75
- data/lib/liquid/tags/if.rb +49 -44
- data/lib/liquid/tags/ifchanged.rb +0 -2
- data/lib/liquid/tags/include.rb +60 -52
- data/lib/liquid/tags/raw.rb +26 -4
- data/lib/liquid/tags/table_row.rb +12 -30
- data/lib/liquid/tags/unless.rb +3 -4
- data/lib/liquid/template.rb +23 -50
- data/lib/liquid/tokenizer.rb +31 -0
- data/lib/liquid/utils.rb +48 -8
- data/lib/liquid/variable.rb +46 -45
- data/lib/liquid/variable_lookup.rb +3 -3
- data/lib/liquid/version.rb +1 -1
- data/test/integration/assign_test.rb +8 -8
- data/test/integration/blank_test.rb +14 -14
- data/test/integration/context_test.rb +2 -2
- data/test/integration/document_test.rb +19 -0
- data/test/integration/drop_test.rb +42 -40
- data/test/integration/error_handling_test.rb +64 -45
- data/test/integration/filter_test.rb +60 -20
- data/test/integration/output_test.rb +26 -27
- data/test/integration/parsing_quirks_test.rb +15 -13
- data/test/integration/render_profiling_test.rb +20 -20
- data/test/integration/security_test.rb +5 -7
- data/test/integration/standard_filter_test.rb +119 -37
- data/test/integration/tags/break_tag_test.rb +1 -2
- data/test/integration/tags/continue_tag_test.rb +0 -1
- data/test/integration/tags/for_tag_test.rb +133 -98
- data/test/integration/tags/if_else_tag_test.rb +75 -77
- data/test/integration/tags/include_tag_test.rb +23 -30
- data/test/integration/tags/increment_tag_test.rb +10 -11
- data/test/integration/tags/raw_tag_test.rb +7 -1
- data/test/integration/tags/standard_tag_test.rb +121 -122
- data/test/integration/tags/statements_test.rb +3 -5
- data/test/integration/tags/table_row_test.rb +20 -19
- data/test/integration/tags/unless_else_tag_test.rb +6 -6
- data/test/integration/template_test.rb +91 -45
- data/test/integration/variable_test.rb +23 -13
- data/test/test_helper.rb +33 -5
- data/test/unit/block_unit_test.rb +6 -5
- data/test/unit/condition_unit_test.rb +82 -77
- data/test/unit/context_unit_test.rb +48 -57
- data/test/unit/file_system_unit_test.rb +3 -3
- data/test/unit/i18n_unit_test.rb +2 -2
- data/test/unit/lexer_unit_test.rb +11 -8
- data/test/unit/parser_unit_test.rb +2 -2
- data/test/unit/regexp_unit_test.rb +1 -1
- data/test/unit/strainer_unit_test.rb +13 -2
- data/test/unit/tag_unit_test.rb +7 -2
- data/test/unit/tags/case_tag_unit_test.rb +1 -1
- data/test/unit/tags/for_tag_unit_test.rb +2 -2
- data/test/unit/tags/if_tag_unit_test.rb +1 -1
- data/test/unit/template_unit_test.rb +6 -5
- data/test/unit/tokenizer_unit_test.rb +24 -7
- data/test/unit/variable_unit_test.rb +60 -43
- metadata +44 -41
- data/lib/liquid/module_ex.rb +0 -62
- data/lib/liquid/token.rb +0 -18
- data/test/unit/module_ex_unit_test.rb +0 -87
@@ -4,101 +4,100 @@ class IfElseTagTest < Minitest::Test
|
|
4
4
|
include Liquid
|
5
5
|
|
6
6
|
def test_if
|
7
|
-
assert_template_result(' ',' {% if false %} this text should not go into the output {% endif %} ')
|
7
|
+
assert_template_result(' ', ' {% if false %} this text should not go into the output {% endif %} ')
|
8
8
|
assert_template_result(' this text should go into the output ',
|
9
|
-
|
10
|
-
assert_template_result(' you rock ?','{% if false %} you suck {% endif %} {% if true %} you rock {% endif %}?')
|
9
|
+
' {% if true %} this text should go into the output {% endif %} ')
|
10
|
+
assert_template_result(' you rock ?', '{% if false %} you suck {% endif %} {% if true %} you rock {% endif %}?')
|
11
11
|
end
|
12
12
|
|
13
13
|
def test_literal_comparisons
|
14
|
-
assert_template_result(' NO ','{% assign v = false %}{% if v %} YES {% else %} NO {% endif %}')
|
15
|
-
assert_template_result(' YES ','{% assign v = nil %}{% if v == nil %} YES {% else %} NO {% endif %}')
|
14
|
+
assert_template_result(' NO ', '{% assign v = false %}{% if v %} YES {% else %} NO {% endif %}')
|
15
|
+
assert_template_result(' YES ', '{% assign v = nil %}{% if v == nil %} YES {% else %} NO {% endif %}')
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_if_else
|
19
|
-
assert_template_result(' YES ','{% if false %} NO {% else %} YES {% endif %}')
|
20
|
-
assert_template_result(' YES ','{% if true %} YES {% else %} NO {% endif %}')
|
21
|
-
assert_template_result(' YES ','{% if "foo" %} YES {% else %} NO {% endif %}')
|
19
|
+
assert_template_result(' YES ', '{% if false %} NO {% else %} YES {% endif %}')
|
20
|
+
assert_template_result(' YES ', '{% if true %} YES {% else %} NO {% endif %}')
|
21
|
+
assert_template_result(' YES ', '{% if "foo" %} YES {% else %} NO {% endif %}')
|
22
22
|
end
|
23
23
|
|
24
24
|
def test_if_boolean
|
25
|
-
assert_template_result(' YES ','{% if var %} YES {% endif %}', 'var' => true)
|
25
|
+
assert_template_result(' YES ', '{% if var %} YES {% endif %}', 'var' => true)
|
26
26
|
end
|
27
27
|
|
28
28
|
def test_if_or
|
29
|
-
assert_template_result(' YES ','{% if a or b %} YES {% endif %}', 'a' => true, 'b' => true)
|
30
|
-
assert_template_result(' YES ','{% if a or b %} YES {% endif %}', 'a' => true, 'b' => false)
|
31
|
-
assert_template_result(' YES ','{% if a or b %} YES {% endif %}', 'a' => false, 'b' => true)
|
32
|
-
assert_template_result('',
|
29
|
+
assert_template_result(' YES ', '{% if a or b %} YES {% endif %}', 'a' => true, 'b' => true)
|
30
|
+
assert_template_result(' YES ', '{% if a or b %} YES {% endif %}', 'a' => true, 'b' => false)
|
31
|
+
assert_template_result(' YES ', '{% if a or b %} YES {% endif %}', 'a' => false, 'b' => true)
|
32
|
+
assert_template_result('', '{% if a or b %} YES {% endif %}', 'a' => false, 'b' => false)
|
33
33
|
|
34
|
-
assert_template_result(' YES ','{% if a or b or c %} YES {% endif %}', 'a' => false, 'b' => false, 'c' => true)
|
35
|
-
assert_template_result('',
|
34
|
+
assert_template_result(' YES ', '{% if a or b or c %} YES {% endif %}', 'a' => false, 'b' => false, 'c' => true)
|
35
|
+
assert_template_result('', '{% if a or b or c %} YES {% endif %}', 'a' => false, 'b' => false, 'c' => false)
|
36
36
|
end
|
37
37
|
|
38
38
|
def test_if_or_with_operators
|
39
|
-
assert_template_result(' YES ','{% if a == true or b == true %} YES {% endif %}', 'a' => true, 'b' => true)
|
40
|
-
assert_template_result(' YES ','{% if a == true or b == false %} YES {% endif %}', 'a' => true, 'b' => true)
|
41
|
-
assert_template_result('','{% if a == false or b == false %} YES {% endif %}', 'a' => true, 'b' => true)
|
39
|
+
assert_template_result(' YES ', '{% if a == true or b == true %} YES {% endif %}', 'a' => true, 'b' => true)
|
40
|
+
assert_template_result(' YES ', '{% if a == true or b == false %} YES {% endif %}', 'a' => true, 'b' => true)
|
41
|
+
assert_template_result('', '{% if a == false or b == false %} YES {% endif %}', 'a' => true, 'b' => true)
|
42
42
|
end
|
43
43
|
|
44
44
|
def test_comparison_of_strings_containing_and_or_or
|
45
45
|
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 = {'a' => 'and', 'b' => 'or', 'c' => 'foo and bar', 'd' => 'bar or baz', 'e' => 'foo', 'foo' => true, 'bar' => true}
|
47
|
-
assert_template_result(' YES ',"{% if #{awful_markup} %} YES {% endif %}", assigns)
|
46
|
+
assigns = { 'a' => 'and', 'b' => 'or', 'c' => 'foo and bar', 'd' => 'bar or baz', 'e' => 'foo', 'foo' => true, 'bar' => true }
|
47
|
+
assert_template_result(' YES ', "{% if #{awful_markup} %} YES {% endif %}", assigns)
|
48
48
|
end
|
49
49
|
|
50
50
|
def test_comparison_of_expressions_starting_with_and_or_or
|
51
|
-
assigns = {'order' => {'items_count' => 0}, 'android' => {'name' => 'Roy'}}
|
52
|
-
assert_template_result(
|
53
|
-
|
54
|
-
|
55
|
-
assert_template_result(
|
56
|
-
|
57
|
-
|
51
|
+
assigns = { 'order' => { 'items_count' => 0 }, 'android' => { 'name' => 'Roy' } }
|
52
|
+
assert_template_result("YES",
|
53
|
+
"{% if android.name == 'Roy' %}YES{% endif %}",
|
54
|
+
assigns)
|
55
|
+
assert_template_result("YES",
|
56
|
+
"{% if order.items_count == 0 %}YES{% endif %}",
|
57
|
+
assigns)
|
58
58
|
end
|
59
59
|
|
60
60
|
def test_if_and
|
61
|
-
assert_template_result(' YES ','{% if true and true %} YES {% endif %}')
|
62
|
-
assert_template_result('','{% if false and true %} YES {% endif %}')
|
63
|
-
assert_template_result('','{% if false and true %} YES {% endif %}')
|
61
|
+
assert_template_result(' YES ', '{% if true and true %} YES {% endif %}')
|
62
|
+
assert_template_result('', '{% if false and true %} YES {% endif %}')
|
63
|
+
assert_template_result('', '{% if false and true %} YES {% endif %}')
|
64
64
|
end
|
65
65
|
|
66
|
-
|
67
66
|
def test_hash_miss_generates_false
|
68
|
-
assert_template_result('','{% if foo.bar %} NO {% endif %}', 'foo' => {})
|
67
|
+
assert_template_result('', '{% if foo.bar %} NO {% endif %}', 'foo' => {})
|
69
68
|
end
|
70
69
|
|
71
70
|
def test_if_from_variable
|
72
|
-
assert_template_result('','{% if var %} NO {% endif %}', 'var' => false)
|
73
|
-
assert_template_result('','{% if var %} NO {% endif %}', 'var' => nil)
|
74
|
-
assert_template_result('','{% if foo.bar %} NO {% endif %}', 'foo' => {'bar' => false})
|
75
|
-
assert_template_result('','{% if foo.bar %} NO {% endif %}', 'foo' => {})
|
76
|
-
assert_template_result('','{% if foo.bar %} NO {% endif %}', 'foo' => nil)
|
77
|
-
assert_template_result('','{% if foo.bar %} NO {% endif %}', 'foo' => true)
|
78
|
-
|
79
|
-
assert_template_result(' YES ','{% if var %} YES {% endif %}', 'var' => "text")
|
80
|
-
assert_template_result(' YES ','{% if var %} YES {% endif %}', 'var' => true)
|
81
|
-
assert_template_result(' YES ','{% if var %} YES {% endif %}', 'var' => 1)
|
82
|
-
assert_template_result(' YES ','{% if var %} YES {% endif %}', 'var' => {})
|
83
|
-
assert_template_result(' YES ','{% if var %} YES {% endif %}', 'var' => [])
|
84
|
-
assert_template_result(' YES ','{% if "foo" %} YES {% endif %}')
|
85
|
-
assert_template_result(' YES ','{% if foo.bar %} YES {% endif %}', 'foo' => {'bar' => true})
|
86
|
-
assert_template_result(' YES ','{% if foo.bar %} YES {% endif %}', 'foo' => {'bar' => "text"})
|
87
|
-
assert_template_result(' YES ','{% if foo.bar %} YES {% endif %}', 'foo' => {'bar' => 1 })
|
88
|
-
assert_template_result(' YES ','{% if foo.bar %} YES {% endif %}', 'foo' => {'bar' => {} })
|
89
|
-
assert_template_result(' YES ','{% if foo.bar %} YES {% endif %}', 'foo' => {'bar' => [] })
|
90
|
-
|
91
|
-
assert_template_result(' YES ','{% if var %} NO {% else %} YES {% endif %}', 'var' => false)
|
92
|
-
assert_template_result(' YES ','{% if var %} NO {% else %} YES {% endif %}', 'var' => nil)
|
93
|
-
assert_template_result(' YES ','{% if var %} YES {% else %} NO {% endif %}', 'var' => true)
|
94
|
-
assert_template_result(' YES ','{% if "foo" %} YES {% else %} NO {% endif %}', 'var' => "text")
|
95
|
-
|
96
|
-
assert_template_result(' YES ','{% if foo.bar %} NO {% else %} YES {% endif %}', 'foo' => {'bar' => false})
|
97
|
-
assert_template_result(' YES ','{% if foo.bar %} YES {% else %} NO {% endif %}', 'foo' => {'bar' => true})
|
98
|
-
assert_template_result(' YES ','{% if foo.bar %} YES {% else %} NO {% endif %}', 'foo' => {'bar' => "text"})
|
99
|
-
assert_template_result(' YES ','{% if foo.bar %} NO {% else %} YES {% endif %}', 'foo' => {'notbar' => true})
|
100
|
-
assert_template_result(' YES ','{% if foo.bar %} NO {% else %} YES {% endif %}', 'foo' => {})
|
101
|
-
assert_template_result(' YES ','{% if foo.bar %} NO {% else %} YES {% endif %}', 'notfoo' => {'bar' => true})
|
71
|
+
assert_template_result('', '{% if var %} NO {% endif %}', 'var' => false)
|
72
|
+
assert_template_result('', '{% if var %} NO {% endif %}', 'var' => nil)
|
73
|
+
assert_template_result('', '{% if foo.bar %} NO {% endif %}', 'foo' => { 'bar' => false })
|
74
|
+
assert_template_result('', '{% if foo.bar %} NO {% endif %}', 'foo' => {})
|
75
|
+
assert_template_result('', '{% if foo.bar %} NO {% endif %}', 'foo' => nil)
|
76
|
+
assert_template_result('', '{% if foo.bar %} NO {% endif %}', 'foo' => true)
|
77
|
+
|
78
|
+
assert_template_result(' YES ', '{% if var %} YES {% endif %}', 'var' => "text")
|
79
|
+
assert_template_result(' YES ', '{% if var %} YES {% endif %}', 'var' => true)
|
80
|
+
assert_template_result(' YES ', '{% if var %} YES {% endif %}', 'var' => 1)
|
81
|
+
assert_template_result(' YES ', '{% if var %} YES {% endif %}', 'var' => {})
|
82
|
+
assert_template_result(' YES ', '{% if var %} YES {% endif %}', 'var' => [])
|
83
|
+
assert_template_result(' YES ', '{% if "foo" %} YES {% endif %}')
|
84
|
+
assert_template_result(' YES ', '{% if foo.bar %} YES {% endif %}', 'foo' => { 'bar' => true })
|
85
|
+
assert_template_result(' YES ', '{% if foo.bar %} YES {% endif %}', 'foo' => { 'bar' => "text" })
|
86
|
+
assert_template_result(' YES ', '{% if foo.bar %} YES {% endif %}', 'foo' => { 'bar' => 1 })
|
87
|
+
assert_template_result(' YES ', '{% if foo.bar %} YES {% endif %}', 'foo' => { 'bar' => {} })
|
88
|
+
assert_template_result(' YES ', '{% if foo.bar %} YES {% endif %}', 'foo' => { 'bar' => [] })
|
89
|
+
|
90
|
+
assert_template_result(' YES ', '{% if var %} NO {% else %} YES {% endif %}', 'var' => false)
|
91
|
+
assert_template_result(' YES ', '{% if var %} NO {% else %} YES {% endif %}', 'var' => nil)
|
92
|
+
assert_template_result(' YES ', '{% if var %} YES {% else %} NO {% endif %}', 'var' => true)
|
93
|
+
assert_template_result(' YES ', '{% if "foo" %} YES {% else %} NO {% endif %}', 'var' => "text")
|
94
|
+
|
95
|
+
assert_template_result(' YES ', '{% if foo.bar %} NO {% else %} YES {% endif %}', 'foo' => { 'bar' => false })
|
96
|
+
assert_template_result(' YES ', '{% if foo.bar %} YES {% else %} NO {% endif %}', 'foo' => { 'bar' => true })
|
97
|
+
assert_template_result(' YES ', '{% if foo.bar %} YES {% else %} NO {% endif %}', 'foo' => { 'bar' => "text" })
|
98
|
+
assert_template_result(' YES ', '{% if foo.bar %} NO {% else %} YES {% endif %}', 'foo' => { 'notbar' => true })
|
99
|
+
assert_template_result(' YES ', '{% if foo.bar %} NO {% else %} YES {% endif %}', 'foo' => {})
|
100
|
+
assert_template_result(' YES ', '{% if foo.bar %} NO {% else %} YES {% endif %}', 'notfoo' => { 'bar' => true })
|
102
101
|
end
|
103
102
|
|
104
103
|
def test_nested_if
|
@@ -110,31 +109,30 @@ class IfElseTagTest < Minitest::Test
|
|
110
109
|
assert_template_result(' YES ', '{% if true %}{% if true %} YES {% else %} NO {% endif %}{% else %} NO {% endif %}')
|
111
110
|
assert_template_result(' YES ', '{% if true %}{% if false %} NO {% else %} YES {% endif %}{% else %} NO {% endif %}')
|
112
111
|
assert_template_result(' YES ', '{% if false %}{% if true %} NO {% else %} NONO {% endif %}{% else %} YES {% endif %}')
|
113
|
-
|
114
112
|
end
|
115
113
|
|
116
114
|
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 %}')
|
115
|
+
assert_template_result('', '{% if null < 10 %} NO {% endif %}')
|
116
|
+
assert_template_result('', '{% if null <= 10 %} NO {% endif %}')
|
117
|
+
assert_template_result('', '{% if null >= 10 %} NO {% endif %}')
|
118
|
+
assert_template_result('', '{% if null > 10 %} NO {% endif %}')
|
121
119
|
|
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 %}')
|
120
|
+
assert_template_result('', '{% if 10 < null %} NO {% endif %}')
|
121
|
+
assert_template_result('', '{% if 10 <= null %} NO {% endif %}')
|
122
|
+
assert_template_result('', '{% if 10 >= null %} NO {% endif %}')
|
123
|
+
assert_template_result('', '{% if 10 > null %} NO {% endif %}')
|
126
124
|
end
|
127
125
|
|
128
126
|
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 %}')
|
127
|
+
assert_template_result('0', '{% if 0 == 0 %}0{% elsif 1 == 1%}1{% else %}2{% endif %}')
|
128
|
+
assert_template_result('1', '{% if 0 != 0 %}0{% elsif 1 == 1%}1{% else %}2{% endif %}')
|
129
|
+
assert_template_result('2', '{% if 0 != 0 %}0{% elsif 1 != 1%}1{% else %}2{% endif %}')
|
132
130
|
|
133
|
-
assert_template_result('elsif','{% if false %}if{% elsif true %}elsif{% endif %}')
|
131
|
+
assert_template_result('elsif', '{% if false %}if{% elsif true %}elsif{% endif %}')
|
134
132
|
end
|
135
133
|
|
136
134
|
def test_syntax_error_no_variable
|
137
|
-
assert_raises(SyntaxError){ assert_template_result('', '{% if jerry == 1 %}')}
|
135
|
+
assert_raises(SyntaxError){ assert_template_result('', '{% if jerry == 1 %}') }
|
138
136
|
end
|
139
137
|
|
140
138
|
def test_syntax_error_no_expression
|
@@ -156,7 +154,7 @@ class IfElseTagTest < Minitest::Test
|
|
156
154
|
Condition.operators['contains'] = :[]
|
157
155
|
|
158
156
|
assert_template_result('yes',
|
159
|
-
|
157
|
+
%({% if 'gnomeslab-and-or-liquid' contains 'gnomeslab-and-or-liquid' %}yes{% endif %}))
|
160
158
|
ensure
|
161
159
|
Condition.operators['contains'] = original_op
|
162
160
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
3
|
class TestFileSystem
|
4
|
-
def read_template_file(template_path
|
4
|
+
def read_template_file(template_path)
|
5
5
|
case template_path
|
6
6
|
when "product"
|
7
7
|
"Product: {{ product.title }} "
|
@@ -37,14 +37,14 @@ class TestFileSystem
|
|
37
37
|
end
|
38
38
|
|
39
39
|
class OtherFileSystem
|
40
|
-
def read_template_file(template_path
|
40
|
+
def read_template_file(template_path)
|
41
41
|
'from OtherFileSystem'
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
class CountingFileSystem
|
46
46
|
attr_reader :count
|
47
|
-
def read_template_file(template_path
|
47
|
+
def read_template_file(template_path)
|
48
48
|
@count ||= 0
|
49
49
|
@count += 1
|
50
50
|
'from CountingFileSystem'
|
@@ -77,23 +77,22 @@ class IncludeTagTest < Minitest::Test
|
|
77
77
|
|
78
78
|
def test_include_tag_looks_for_file_system_in_registers_first
|
79
79
|
assert_equal 'from OtherFileSystem',
|
80
|
-
Template.parse("{% include 'pick_a_source' %}").render!({}, :
|
80
|
+
Template.parse("{% include 'pick_a_source' %}").render!({}, registers: { file_system: OtherFileSystem.new })
|
81
81
|
end
|
82
82
|
|
83
|
-
|
84
83
|
def test_include_tag_with
|
85
84
|
assert_template_result "Product: Draft 151cm ",
|
86
|
-
"{% include 'product' with products[0] %}", "products" => [ {'title' => 'Draft 151cm'}, {'title' => 'Element 155cm'} ]
|
85
|
+
"{% include 'product' with products[0] %}", "products" => [ { 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' } ]
|
87
86
|
end
|
88
87
|
|
89
88
|
def test_include_tag_with_default_name
|
90
89
|
assert_template_result "Product: Draft 151cm ",
|
91
|
-
"{% include 'product' %}", "product" => {'title' => 'Draft 151cm'}
|
90
|
+
"{% include 'product' %}", "product" => { 'title' => 'Draft 151cm' }
|
92
91
|
end
|
93
92
|
|
94
93
|
def test_include_tag_for
|
95
94
|
assert_template_result "Product: Draft 151cm Product: Element 155cm ",
|
96
|
-
"{% include 'product' for products %}", "products" => [ {'title' => 'Draft 151cm'}, {'title' => 'Element 155cm'} ]
|
95
|
+
"{% include 'product' for products %}", "products" => [ { 'title' => 'Draft 151cm' }, { 'title' => 'Element 155cm' } ]
|
97
96
|
end
|
98
97
|
|
99
98
|
def test_include_tag_with_local_variables
|
@@ -108,7 +107,7 @@ class IncludeTagTest < Minitest::Test
|
|
108
107
|
def test_include_tag_with_multiple_local_variables_from_context
|
109
108
|
assert_template_result "Locale: test123 test321",
|
110
109
|
"{% include 'locale_variables' echo1: echo1, echo2: more_echos.echo2 %}",
|
111
|
-
'echo1' => 'test123', 'more_echos' => { "echo2" => 'test321'}
|
110
|
+
'echo1' => 'test123', 'more_echos' => { "echo2" => 'test321' }
|
112
111
|
end
|
113
112
|
|
114
113
|
def test_included_templates_assigns_variables
|
@@ -123,16 +122,15 @@ class IncludeTagTest < Minitest::Test
|
|
123
122
|
|
124
123
|
def test_nested_include_with_variable
|
125
124
|
assert_template_result "Product: Draft 151cm details ",
|
126
|
-
"{% include 'nested_product_template' with product %}", "product" => {"title" => 'Draft 151cm'}
|
125
|
+
"{% include 'nested_product_template' with product %}", "product" => { "title" => 'Draft 151cm' }
|
127
126
|
|
128
127
|
assert_template_result "Product: Draft 151cm details Product: Element 155cm details ",
|
129
|
-
"{% include 'nested_product_template' for products %}", "products" => [{"title" => 'Draft 151cm'}, {"title" => 'Element 155cm'}]
|
128
|
+
"{% include 'nested_product_template' for products %}", "products" => [{ "title" => 'Draft 151cm' }, { "title" => 'Element 155cm' }]
|
130
129
|
end
|
131
130
|
|
132
131
|
def test_recursively_included_template_does_not_produce_endless_loop
|
133
|
-
|
134
132
|
infinite_file_system = Class.new do
|
135
|
-
def read_template_file(template_path
|
133
|
+
def read_template_file(template_path)
|
136
134
|
"-{% include 'loop' %}"
|
137
135
|
end
|
138
136
|
end
|
@@ -142,19 +140,6 @@ class IncludeTagTest < Minitest::Test
|
|
142
140
|
assert_raises(Liquid::StackLevelError, SystemStackError) do
|
143
141
|
Template.parse("{% include 'loop' %}").render!
|
144
142
|
end
|
145
|
-
|
146
|
-
end
|
147
|
-
|
148
|
-
def test_backwards_compatability_support_for_overridden_read_template_file
|
149
|
-
infinite_file_system = Class.new do
|
150
|
-
def read_template_file(template_path) # testing only one argument here.
|
151
|
-
"- hi mom"
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
Liquid::Template.file_system = infinite_file_system.new
|
156
|
-
|
157
|
-
Template.parse("{% include 'hi_mom' %}").render!
|
158
143
|
end
|
159
144
|
|
160
145
|
def test_dynamically_choosen_template
|
@@ -162,24 +147,24 @@ class IncludeTagTest < Minitest::Test
|
|
162
147
|
assert_template_result "Test321", "{% include template %}", "template" => 'Test321'
|
163
148
|
|
164
149
|
assert_template_result "Product: Draft 151cm ", "{% include template for product %}",
|
165
|
-
"template" => 'product', 'product' => { 'title' => 'Draft 151cm'}
|
150
|
+
"template" => 'product', 'product' => { 'title' => 'Draft 151cm' }
|
166
151
|
end
|
167
152
|
|
168
153
|
def test_include_tag_caches_second_read_of_same_partial
|
169
154
|
file_system = CountingFileSystem.new
|
170
155
|
assert_equal 'from CountingFileSystemfrom CountingFileSystem',
|
171
|
-
Template.parse("{% include 'pick_a_source' %}{% include 'pick_a_source' %}").render!({}, :
|
156
|
+
Template.parse("{% include 'pick_a_source' %}{% include 'pick_a_source' %}").render!({}, registers: { file_system: file_system })
|
172
157
|
assert_equal 1, file_system.count
|
173
158
|
end
|
174
159
|
|
175
160
|
def test_include_tag_doesnt_cache_partials_across_renders
|
176
161
|
file_system = CountingFileSystem.new
|
177
162
|
assert_equal 'from CountingFileSystem',
|
178
|
-
Template.parse("{% include 'pick_a_source' %}").render!({}, :
|
163
|
+
Template.parse("{% include 'pick_a_source' %}").render!({}, registers: { file_system: file_system })
|
179
164
|
assert_equal 1, file_system.count
|
180
165
|
|
181
166
|
assert_equal 'from CountingFileSystem',
|
182
|
-
Template.parse("{% include 'pick_a_source' %}").render!({}, :
|
167
|
+
Template.parse("{% include 'pick_a_source' %}").render!({}, registers: { file_system: file_system })
|
183
168
|
assert_equal 2, file_system.count
|
184
169
|
end
|
185
170
|
|
@@ -231,4 +216,12 @@ class IncludeTagTest < Minitest::Test
|
|
231
216
|
assert_equal 'x', Template.parse("{% include template %}", error_mode: :strict, include_options_blacklist: [:error_mode]).render!("template" => '{{ "X" || downcase }}')
|
232
217
|
end
|
233
218
|
end
|
219
|
+
|
220
|
+
def test_including_via_variable_value
|
221
|
+
assert_template_result "from TestFileSystem", "{% assign page = 'pick_a_source' %}{% include page %}"
|
222
|
+
|
223
|
+
assert_template_result "Product: Draft 151cm ", "{% assign page = 'product' %}{% include page %}", "product" => { 'title' => 'Draft 151cm' }
|
224
|
+
|
225
|
+
assert_template_result "Product: Draft 151cm ", "{% assign page = 'product' %}{% include page for foo %}", "foo" => { 'title' => 'Draft 151cm' }
|
226
|
+
end
|
234
227
|
end # IncludeTagTest
|
@@ -4,21 +4,20 @@ class IncrementTagTest < Minitest::Test
|
|
4
4
|
include Liquid
|
5
5
|
|
6
6
|
def test_inc
|
7
|
-
assert_template_result('0','{%increment port %}', {})
|
8
|
-
assert_template_result('0 1','{%increment port %} {%increment port%}', {})
|
7
|
+
assert_template_result('0', '{%increment port %}', {})
|
8
|
+
assert_template_result('0 1', '{%increment port %} {%increment port%}', {})
|
9
9
|
assert_template_result('0 0 1 2 1',
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
'{%increment port %} {%increment starboard%} ' \
|
11
|
+
'{%increment port %} {%increment port%} ' \
|
12
|
+
'{%increment starboard %}', {})
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_dec
|
16
|
-
assert_template_result('9','{%decrement port %}', { 'port' => 10})
|
17
|
-
assert_template_result('-1 -2','{%decrement port %} {%decrement port%}', {})
|
16
|
+
assert_template_result('9', '{%decrement port %}', { 'port' => 10 })
|
17
|
+
assert_template_result('-1 -2', '{%decrement port %} {%decrement port%}', {})
|
18
18
|
assert_template_result('1 5 2 2 5',
|
19
|
-
|
20
|
-
|
21
|
-
|
19
|
+
'{%increment port %} {%increment starboard%} ' \
|
20
|
+
'{%increment port %} {%decrement port%} ' \
|
21
|
+
'{%decrement starboard %}', { 'port' => 1, 'starboard' => 5 })
|
22
22
|
end
|
23
|
-
|
24
23
|
end
|
@@ -5,7 +5,7 @@ class RawTagTest < Minitest::Test
|
|
5
5
|
|
6
6
|
def test_tag_in_raw
|
7
7
|
assert_template_result '{% comment %} test {% endcomment %}',
|
8
|
-
|
8
|
+
'{% raw %}{% comment %} test {% endcomment %}{% endraw %}'
|
9
9
|
end
|
10
10
|
|
11
11
|
def test_output_in_raw
|
@@ -22,4 +22,10 @@ class RawTagTest < Minitest::Test
|
|
22
22
|
assert_template_result ' test {% raw %} {% endraw %}', '{% raw %} test {% raw %} {% {% endraw %}endraw %}'
|
23
23
|
assert_template_result ' Foobar {{ invalid 1', '{% raw %} Foobar {{ invalid {% endraw %}{{ 1 }}'
|
24
24
|
end
|
25
|
+
|
26
|
+
def test_invalid_raw
|
27
|
+
assert_match_syntax_error /tag was never closed/, '{% raw %} foo'
|
28
|
+
assert_match_syntax_error /Valid syntax/, '{% raw } foo {% endraw %}'
|
29
|
+
assert_match_syntax_error /Valid syntax/, '{% raw } foo %}{% endraw %}'
|
30
|
+
end
|
25
31
|
end
|
@@ -5,116 +5,116 @@ class StandardTagTest < Minitest::Test
|
|
5
5
|
|
6
6
|
def test_no_transform
|
7
7
|
assert_template_result('this text should come out of the template without change...',
|
8
|
-
|
8
|
+
'this text should come out of the template without change...')
|
9
9
|
|
10
|
-
assert_template_result('blah','blah')
|
11
|
-
assert_template_result('<blah>','<blah>')
|
12
|
-
assert_template_result('|,.:','|,.:')
|
13
|
-
assert_template_result('','')
|
10
|
+
assert_template_result('blah', 'blah')
|
11
|
+
assert_template_result('<blah>', '<blah>')
|
12
|
+
assert_template_result('|,.:', '|,.:')
|
13
|
+
assert_template_result('', '')
|
14
14
|
|
15
|
-
text =
|
16
|
-
as you can clearly see here
|
17
|
-
assert_template_result(text,text)
|
15
|
+
text = %(this shouldnt see any transformation either but has multiple lines
|
16
|
+
as you can clearly see here ...)
|
17
|
+
assert_template_result(text, text)
|
18
18
|
end
|
19
19
|
|
20
20
|
def test_has_a_block_which_does_nothing
|
21
|
-
assert_template_result(
|
22
|
-
|
23
|
-
|
24
|
-
assert_template_result('','{%comment%}{%endcomment%}')
|
25
|
-
assert_template_result('','{%comment%}{% endcomment %}')
|
26
|
-
assert_template_result('','{% comment %}{%endcomment%}')
|
27
|
-
assert_template_result('','{% comment %}{% endcomment %}')
|
28
|
-
assert_template_result('','{%comment%}comment{%endcomment%}')
|
29
|
-
assert_template_result('','{% comment %}comment{% endcomment %}')
|
30
|
-
assert_template_result('','{% comment %} 1 {% comment %} 2 {% endcomment %} 3 {% endcomment %}')
|
31
|
-
|
32
|
-
assert_template_result('','{%comment%}{%blabla%}{%endcomment%}')
|
33
|
-
assert_template_result('','{% comment %}{% blabla %}{% endcomment %}')
|
34
|
-
assert_template_result('','{%comment%}{% endif %}{%endcomment%}')
|
35
|
-
assert_template_result('','{% comment %}{% endwhatever %}{% endcomment %}')
|
36
|
-
assert_template_result('','{% comment %}{% raw %} {{%%%%}} }} { {% endcomment %} {% comment {% endraw %} {% endcomment %}')
|
37
|
-
|
38
|
-
assert_template_result('foobar','foo{%comment%}comment{%endcomment%}bar')
|
39
|
-
assert_template_result('foobar','foo{% comment %}comment{% endcomment %}bar')
|
40
|
-
assert_template_result('foobar','foo{%comment%} comment {%endcomment%}bar')
|
41
|
-
assert_template_result('foobar','foo{% comment %} comment {% endcomment %}bar')
|
42
|
-
|
43
|
-
assert_template_result('foo bar','foo {%comment%} {%endcomment%} bar')
|
44
|
-
assert_template_result('foo bar','foo {%comment%}comment{%endcomment%} bar')
|
45
|
-
assert_template_result('foo bar','foo {%comment%} comment {%endcomment%} bar')
|
46
|
-
|
47
|
-
assert_template_result('foobar','foo{%comment%}
|
21
|
+
assert_template_result(%(the comment block should be removed .. right?),
|
22
|
+
%(the comment block should be removed {%comment%} be gone.. {%endcomment%} .. right?))
|
23
|
+
|
24
|
+
assert_template_result('', '{%comment%}{%endcomment%}')
|
25
|
+
assert_template_result('', '{%comment%}{% endcomment %}')
|
26
|
+
assert_template_result('', '{% comment %}{%endcomment%}')
|
27
|
+
assert_template_result('', '{% comment %}{% endcomment %}')
|
28
|
+
assert_template_result('', '{%comment%}comment{%endcomment%}')
|
29
|
+
assert_template_result('', '{% comment %}comment{% endcomment %}')
|
30
|
+
assert_template_result('', '{% comment %} 1 {% comment %} 2 {% endcomment %} 3 {% endcomment %}')
|
31
|
+
|
32
|
+
assert_template_result('', '{%comment%}{%blabla%}{%endcomment%}')
|
33
|
+
assert_template_result('', '{% comment %}{% blabla %}{% endcomment %}')
|
34
|
+
assert_template_result('', '{%comment%}{% endif %}{%endcomment%}')
|
35
|
+
assert_template_result('', '{% comment %}{% endwhatever %}{% endcomment %}')
|
36
|
+
assert_template_result('', '{% comment %}{% raw %} {{%%%%}} }} { {% endcomment %} {% comment {% endraw %} {% endcomment %}')
|
37
|
+
|
38
|
+
assert_template_result('foobar', 'foo{%comment%}comment{%endcomment%}bar')
|
39
|
+
assert_template_result('foobar', 'foo{% comment %}comment{% endcomment %}bar')
|
40
|
+
assert_template_result('foobar', 'foo{%comment%} comment {%endcomment%}bar')
|
41
|
+
assert_template_result('foobar', 'foo{% comment %} comment {% endcomment %}bar')
|
42
|
+
|
43
|
+
assert_template_result('foo bar', 'foo {%comment%} {%endcomment%} bar')
|
44
|
+
assert_template_result('foo bar', 'foo {%comment%}comment{%endcomment%} bar')
|
45
|
+
assert_template_result('foo bar', 'foo {%comment%} comment {%endcomment%} bar')
|
46
|
+
|
47
|
+
assert_template_result('foobar', 'foo{%comment%}
|
48
48
|
{%endcomment%}bar')
|
49
49
|
end
|
50
50
|
|
51
51
|
def test_hyphenated_assign
|
52
|
-
assigns = {'a-b' => '1' }
|
52
|
+
assigns = { 'a-b' => '1' }
|
53
53
|
assert_template_result('a-b:1 a-b:2', 'a-b:{{a-b}} {%assign a-b = 2 %}a-b:{{a-b}}', assigns)
|
54
54
|
end
|
55
55
|
|
56
56
|
def test_assign_with_colon_and_spaces
|
57
|
-
assigns = {'var' => {'a:b c' => {'paged' => '1' }}}
|
57
|
+
assigns = { 'var' => { 'a:b c' => { 'paged' => '1' } } }
|
58
58
|
assert_template_result('var2: 1', '{%assign var2 = var["a:b c"].paged %}var2: {{var2}}', assigns)
|
59
59
|
end
|
60
60
|
|
61
61
|
def test_capture
|
62
|
-
assigns = {'var' => 'content' }
|
62
|
+
assigns = { 'var' => 'content' }
|
63
63
|
assert_template_result('content foo content foo ',
|
64
|
-
|
65
|
-
|
64
|
+
'{{ var2 }}{% capture var2 %}{{ var }} foo {% endcapture %}{{ var2 }}{{ var2 }}',
|
65
|
+
assigns)
|
66
66
|
end
|
67
67
|
|
68
68
|
def test_capture_detects_bad_syntax
|
69
69
|
assert_raises(SyntaxError) do
|
70
70
|
assert_template_result('content foo content foo ',
|
71
|
-
|
72
|
-
|
71
|
+
'{{ var2 }}{% capture %}{{ var }} foo {% endcapture %}{{ var2 }}{{ var2 }}',
|
72
|
+
{ 'var' => 'content' })
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
76
|
def test_case
|
77
|
-
assigns = {'condition' => 2 }
|
77
|
+
assigns = { 'condition' => 2 }
|
78
78
|
assert_template_result(' its 2 ',
|
79
|
-
|
80
|
-
|
79
|
+
'{% case condition %}{% when 1 %} its 1 {% when 2 %} its 2 {% endcase %}',
|
80
|
+
assigns)
|
81
81
|
|
82
|
-
assigns = {'condition' => 1 }
|
82
|
+
assigns = { 'condition' => 1 }
|
83
83
|
assert_template_result(' its 1 ',
|
84
|
-
|
85
|
-
|
84
|
+
'{% case condition %}{% when 1 %} its 1 {% when 2 %} its 2 {% endcase %}',
|
85
|
+
assigns)
|
86
86
|
|
87
|
-
assigns = {'condition' => 3 }
|
87
|
+
assigns = { 'condition' => 3 }
|
88
88
|
assert_template_result('',
|
89
|
-
|
90
|
-
|
89
|
+
'{% case condition %}{% when 1 %} its 1 {% when 2 %} its 2 {% endcase %}',
|
90
|
+
assigns)
|
91
91
|
|
92
|
-
assigns = {'condition' => "string here" }
|
92
|
+
assigns = { 'condition' => "string here" }
|
93
93
|
assert_template_result(' hit ',
|
94
|
-
|
95
|
-
|
94
|
+
'{% case condition %}{% when "string here" %} hit {% endcase %}',
|
95
|
+
assigns)
|
96
96
|
|
97
|
-
assigns = {'condition' => "bad string here" }
|
97
|
+
assigns = { 'condition' => "bad string here" }
|
98
98
|
assert_template_result('',
|
99
|
-
|
100
|
-
|
99
|
+
'{% case condition %}{% when "string here" %} hit {% endcase %}',\
|
100
|
+
assigns)
|
101
101
|
end
|
102
102
|
|
103
103
|
def test_case_with_else
|
104
|
-
assigns = {'condition' => 5 }
|
104
|
+
assigns = { 'condition' => 5 }
|
105
105
|
assert_template_result(' hit ',
|
106
|
-
|
107
|
-
|
106
|
+
'{% case condition %}{% when 5 %} hit {% else %} else {% endcase %}',
|
107
|
+
assigns)
|
108
108
|
|
109
|
-
assigns = {'condition' => 6 }
|
109
|
+
assigns = { 'condition' => 6 }
|
110
110
|
assert_template_result(' else ',
|
111
|
-
|
112
|
-
|
111
|
+
'{% case condition %}{% when 5 %} hit {% else %} else {% endcase %}',
|
112
|
+
assigns)
|
113
113
|
|
114
|
-
assigns = {'condition' => 6 }
|
114
|
+
assigns = { 'condition' => 6 }
|
115
115
|
assert_template_result(' else ',
|
116
|
-
|
117
|
-
|
116
|
+
'{% case condition %} {% when 5 %} hit {% else %} else {% endcase %}',
|
117
|
+
assigns)
|
118
118
|
end
|
119
119
|
|
120
120
|
def test_case_on_size
|
@@ -128,87 +128,87 @@ class StandardTagTest < Minitest::Test
|
|
128
128
|
|
129
129
|
def test_case_on_size_with_else
|
130
130
|
assert_template_result('else',
|
131
|
-
|
132
|
-
|
131
|
+
'{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}',
|
132
|
+
'a' => [])
|
133
133
|
|
134
134
|
assert_template_result('1',
|
135
|
-
|
136
|
-
|
135
|
+
'{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}',
|
136
|
+
'a' => [1])
|
137
137
|
|
138
138
|
assert_template_result('2',
|
139
|
-
|
140
|
-
|
139
|
+
'{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}',
|
140
|
+
'a' => [1, 1])
|
141
141
|
|
142
142
|
assert_template_result('else',
|
143
|
-
|
144
|
-
|
143
|
+
'{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}',
|
144
|
+
'a' => [1, 1, 1])
|
145
145
|
|
146
146
|
assert_template_result('else',
|
147
|
-
|
148
|
-
|
147
|
+
'{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}',
|
148
|
+
'a' => [1, 1, 1, 1])
|
149
149
|
|
150
150
|
assert_template_result('else',
|
151
|
-
|
152
|
-
|
151
|
+
'{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}',
|
152
|
+
'a' => [1, 1, 1, 1, 1])
|
153
153
|
end
|
154
154
|
|
155
155
|
def test_case_on_length_with_else
|
156
156
|
assert_template_result('else',
|
157
|
-
|
158
|
-
|
157
|
+
'{% case a.empty? %}{% when true %}true{% when false %}false{% else %}else{% endcase %}',
|
158
|
+
{})
|
159
159
|
|
160
160
|
assert_template_result('false',
|
161
|
-
|
162
|
-
|
161
|
+
'{% case false %}{% when true %}true{% when false %}false{% else %}else{% endcase %}',
|
162
|
+
{})
|
163
163
|
|
164
164
|
assert_template_result('true',
|
165
|
-
|
166
|
-
|
165
|
+
'{% case true %}{% when true %}true{% when false %}false{% else %}else{% endcase %}',
|
166
|
+
{})
|
167
167
|
|
168
168
|
assert_template_result('else',
|
169
|
-
|
170
|
-
|
169
|
+
'{% case NULL %}{% when true %}true{% when false %}false{% else %}else{% endcase %}',
|
170
|
+
{})
|
171
171
|
end
|
172
172
|
|
173
173
|
def test_assign_from_case
|
174
174
|
# Example from the shopify forums
|
175
|
-
code =
|
175
|
+
code = "{% case collection.handle %}{% when 'menswear-jackets' %}{% assign ptitle = 'menswear' %}{% when 'menswear-t-shirts' %}{% assign ptitle = 'menswear' %}{% else %}{% assign ptitle = 'womenswear' %}{% endcase %}{{ ptitle }}"
|
176
176
|
template = Liquid::Template.parse(code)
|
177
|
-
assert_equal "menswear", template.render!("collection" => {'handle' => 'menswear-jackets'})
|
178
|
-
assert_equal "menswear", template.render!("collection" => {'handle' => 'menswear-t-shirts'})
|
179
|
-
assert_equal "womenswear", template.render!("collection" => {'handle' => 'x'})
|
180
|
-
assert_equal "womenswear", template.render!("collection" => {'handle' => 'y'})
|
181
|
-
assert_equal "womenswear", template.render!("collection" => {'handle' => 'z'})
|
177
|
+
assert_equal "menswear", template.render!("collection" => { 'handle' => 'menswear-jackets' })
|
178
|
+
assert_equal "menswear", template.render!("collection" => { 'handle' => 'menswear-t-shirts' })
|
179
|
+
assert_equal "womenswear", template.render!("collection" => { 'handle' => 'x' })
|
180
|
+
assert_equal "womenswear", template.render!("collection" => { 'handle' => 'y' })
|
181
|
+
assert_equal "womenswear", template.render!("collection" => { 'handle' => 'z' })
|
182
182
|
end
|
183
183
|
|
184
184
|
def test_case_when_or
|
185
185
|
code = '{% case condition %}{% when 1 or 2 or 3 %} its 1 or 2 or 3 {% when 4 %} its 4 {% endcase %}'
|
186
|
-
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 1 })
|
187
|
-
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 2 })
|
188
|
-
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 3 })
|
189
|
-
assert_template_result(' its 4 ', code, {'condition' => 4 })
|
190
|
-
assert_template_result('', code, {'condition' => 5 })
|
186
|
+
assert_template_result(' its 1 or 2 or 3 ', code, { 'condition' => 1 })
|
187
|
+
assert_template_result(' its 1 or 2 or 3 ', code, { 'condition' => 2 })
|
188
|
+
assert_template_result(' its 1 or 2 or 3 ', code, { 'condition' => 3 })
|
189
|
+
assert_template_result(' its 4 ', code, { 'condition' => 4 })
|
190
|
+
assert_template_result('', code, { 'condition' => 5 })
|
191
191
|
|
192
192
|
code = '{% case condition %}{% when 1 or "string" or null %} its 1 or 2 or 3 {% when 4 %} its 4 {% endcase %}'
|
193
|
-
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 1 })
|
194
|
-
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 'string' })
|
195
|
-
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => nil })
|
196
|
-
assert_template_result('', code, {'condition' => 'something else' })
|
193
|
+
assert_template_result(' its 1 or 2 or 3 ', code, { 'condition' => 1 })
|
194
|
+
assert_template_result(' its 1 or 2 or 3 ', code, { 'condition' => 'string' })
|
195
|
+
assert_template_result(' its 1 or 2 or 3 ', code, { 'condition' => nil })
|
196
|
+
assert_template_result('', code, { 'condition' => 'something else' })
|
197
197
|
end
|
198
198
|
|
199
199
|
def test_case_when_comma
|
200
200
|
code = '{% case condition %}{% when 1, 2, 3 %} its 1 or 2 or 3 {% when 4 %} its 4 {% endcase %}'
|
201
|
-
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 1 })
|
202
|
-
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 2 })
|
203
|
-
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 3 })
|
204
|
-
assert_template_result(' its 4 ', code, {'condition' => 4 })
|
205
|
-
assert_template_result('', code, {'condition' => 5 })
|
201
|
+
assert_template_result(' its 1 or 2 or 3 ', code, { 'condition' => 1 })
|
202
|
+
assert_template_result(' its 1 or 2 or 3 ', code, { 'condition' => 2 })
|
203
|
+
assert_template_result(' its 1 or 2 or 3 ', code, { 'condition' => 3 })
|
204
|
+
assert_template_result(' its 4 ', code, { 'condition' => 4 })
|
205
|
+
assert_template_result('', code, { 'condition' => 5 })
|
206
206
|
|
207
207
|
code = '{% case condition %}{% when 1, "string", null %} its 1 or 2 or 3 {% when 4 %} its 4 {% endcase %}'
|
208
|
-
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 1 })
|
209
|
-
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 'string' })
|
210
|
-
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => nil })
|
211
|
-
assert_template_result('', code, {'condition' => 'something else' })
|
208
|
+
assert_template_result(' its 1 or 2 or 3 ', code, { 'condition' => 1 })
|
209
|
+
assert_template_result(' its 1 or 2 or 3 ', code, { 'condition' => 'string' })
|
210
|
+
assert_template_result(' its 1 or 2 or 3 ', code, { 'condition' => nil })
|
211
|
+
assert_template_result('', code, { 'condition' => 'something else' })
|
212
212
|
end
|
213
213
|
|
214
214
|
def test_assign
|
@@ -236,15 +236,14 @@ class StandardTagTest < Minitest::Test
|
|
236
236
|
assert_raises(SyntaxError) do
|
237
237
|
assert_template_result('', '{% case false %}{% huh %}true{% endcase %}', {})
|
238
238
|
end
|
239
|
-
|
240
239
|
end
|
241
240
|
|
242
241
|
def test_cycle
|
243
|
-
assert_template_result('one','{%cycle "one", "two"%}')
|
244
|
-
assert_template_result('one two','{%cycle "one", "two"%} {%cycle "one", "two"%}')
|
245
|
-
assert_template_result(' two','{%cycle "", "two"%} {%cycle "", "two"%}')
|
242
|
+
assert_template_result('one', '{%cycle "one", "two"%}')
|
243
|
+
assert_template_result('one two', '{%cycle "one", "two"%} {%cycle "one", "two"%}')
|
244
|
+
assert_template_result(' two', '{%cycle "", "two"%} {%cycle "", "two"%}')
|
246
245
|
|
247
|
-
assert_template_result('one two one','{%cycle "one", "two"%} {%cycle "one", "two"%} {%cycle "one", "two"%}')
|
246
|
+
assert_template_result('one two one', '{%cycle "one", "two"%} {%cycle "one", "two"%} {%cycle "one", "two"%}')
|
248
247
|
|
249
248
|
assert_template_result('text-align: left text-align: right',
|
250
249
|
'{%cycle "text-align: left", "text-align: right" %} {%cycle "text-align: left", "text-align: right"%}')
|
@@ -261,18 +260,18 @@ class StandardTagTest < Minitest::Test
|
|
261
260
|
end
|
262
261
|
|
263
262
|
def test_multiple_named_cycles_with_names_from_context
|
264
|
-
assigns = {"var1" => 1, "var2" => 2 }
|
263
|
+
assigns = { "var1" => 1, "var2" => 2 }
|
265
264
|
assert_template_result('one one two two one one',
|
266
265
|
'{%cycle var1: "one", "two" %} {%cycle var2: "one", "two" %} {%cycle var1: "one", "two" %} {%cycle var2: "one", "two" %} {%cycle var1: "one", "two" %} {%cycle var2: "one", "two" %}', assigns)
|
267
266
|
end
|
268
267
|
|
269
268
|
def test_size_of_array
|
270
|
-
assigns = {"array" => [1,2,3,4]}
|
269
|
+
assigns = { "array" => [1, 2, 3, 4] }
|
271
270
|
assert_template_result('array has 4 elements', "array has {{ array.size }} elements", assigns)
|
272
271
|
end
|
273
272
|
|
274
273
|
def test_size_of_hash
|
275
|
-
assigns = {"hash" => {:
|
274
|
+
assigns = { "hash" => { a: 1, b: 2, c: 3, d: 4 } }
|
276
275
|
assert_template_result('hash has 4 elements', "hash has {{ hash.size }} elements", assigns)
|
277
276
|
end
|
278
277
|
|
@@ -284,11 +283,11 @@ class StandardTagTest < Minitest::Test
|
|
284
283
|
end
|
285
284
|
|
286
285
|
def test_ifchanged
|
287
|
-
assigns = {'array' => [ 1, 1, 2, 2, 3, 3] }
|
288
|
-
assert_template_result('123','{%for item in array%}{%ifchanged%}{{item}}{% endifchanged %}{%endfor%}',assigns)
|
286
|
+
assigns = { 'array' => [ 1, 1, 2, 2, 3, 3] }
|
287
|
+
assert_template_result('123', '{%for item in array%}{%ifchanged%}{{item}}{% endifchanged %}{%endfor%}', assigns)
|
289
288
|
|
290
|
-
assigns = {'array' => [ 1, 1, 1, 1] }
|
291
|
-
assert_template_result('1','{%for item in array%}{%ifchanged%}{{item}}{% endifchanged %}{%endfor%}',assigns)
|
289
|
+
assigns = { 'array' => [ 1, 1, 1, 1] }
|
290
|
+
assert_template_result('1', '{%for item in array%}{%ifchanged%}{{item}}{% endifchanged %}{%endfor%}', assigns)
|
292
291
|
end
|
293
292
|
|
294
293
|
def test_multiline_tag
|