liquid 2.6.3 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/History.md +46 -13
- data/README.md +27 -2
- data/lib/liquid/block.rb +85 -51
- data/lib/liquid/block_body.rb +123 -0
- data/lib/liquid/condition.rb +26 -15
- data/lib/liquid/context.rb +106 -140
- data/lib/liquid/document.rb +3 -3
- data/lib/liquid/drop.rb +17 -1
- data/lib/liquid/errors.rb +50 -2
- data/lib/liquid/expression.rb +33 -0
- data/lib/liquid/file_system.rb +17 -6
- data/lib/liquid/i18n.rb +39 -0
- data/lib/liquid/interrupts.rb +1 -1
- data/lib/liquid/lexer.rb +51 -0
- data/lib/liquid/locales/en.yml +22 -0
- data/lib/liquid/parser.rb +90 -0
- data/lib/liquid/parser_switching.rb +31 -0
- data/lib/liquid/profiler/hooks.rb +23 -0
- data/lib/liquid/profiler.rb +159 -0
- data/lib/liquid/range_lookup.rb +22 -0
- data/lib/liquid/standardfilters.rb +143 -55
- data/lib/liquid/strainer.rb +14 -4
- data/lib/liquid/tag.rb +25 -9
- data/lib/liquid/tags/assign.rb +12 -9
- data/lib/liquid/tags/break.rb +1 -1
- data/lib/liquid/tags/capture.rb +10 -8
- data/lib/liquid/tags/case.rb +13 -13
- data/lib/liquid/tags/comment.rb +9 -2
- data/lib/liquid/tags/continue.rb +1 -4
- data/lib/liquid/tags/cycle.rb +5 -7
- data/lib/liquid/tags/decrement.rb +3 -4
- data/lib/liquid/tags/for.rb +69 -36
- data/lib/liquid/tags/if.rb +52 -25
- data/lib/liquid/tags/ifchanged.rb +3 -3
- data/lib/liquid/tags/include.rb +19 -8
- data/lib/liquid/tags/increment.rb +4 -8
- data/lib/liquid/tags/raw.rb +4 -7
- data/lib/liquid/tags/table_row.rb +73 -0
- data/lib/liquid/tags/unless.rb +2 -4
- data/lib/liquid/template.rb +124 -14
- data/lib/liquid/token.rb +18 -0
- data/lib/liquid/utils.rb +13 -4
- data/lib/liquid/variable.rb +103 -25
- data/lib/liquid/variable_lookup.rb +78 -0
- data/lib/liquid/version.rb +1 -1
- data/lib/liquid.rb +19 -11
- data/test/fixtures/en_locale.yml +9 -0
- data/test/{liquid → integration}/assign_test.rb +18 -1
- data/test/integration/blank_test.rb +106 -0
- data/test/{liquid → integration}/capture_test.rb +3 -3
- data/test/integration/context_test.rb +32 -0
- data/test/integration/drop_test.rb +271 -0
- data/test/integration/error_handling_test.rb +207 -0
- data/test/{liquid → integration}/filter_test.rb +11 -11
- data/test/integration/hash_ordering_test.rb +23 -0
- data/test/{liquid → integration}/output_test.rb +13 -13
- data/test/integration/parsing_quirks_test.rb +116 -0
- data/test/integration/render_profiling_test.rb +154 -0
- data/test/{liquid → integration}/security_test.rb +10 -10
- data/test/{liquid → integration}/standard_filter_test.rb +148 -32
- data/test/{liquid → integration}/tags/break_tag_test.rb +1 -1
- data/test/{liquid → integration}/tags/continue_tag_test.rb +1 -1
- data/test/{liquid → integration}/tags/for_tag_test.rb +80 -2
- data/test/{liquid → integration}/tags/if_else_tag_test.rb +24 -21
- data/test/integration/tags/include_tag_test.rb +234 -0
- data/test/{liquid → integration}/tags/increment_tag_test.rb +1 -1
- data/test/{liquid → integration}/tags/raw_tag_test.rb +2 -1
- data/test/{liquid → integration}/tags/standard_tag_test.rb +28 -26
- data/test/integration/tags/statements_test.rb +113 -0
- data/test/{liquid/tags/html_tag_test.rb → integration/tags/table_row_test.rb} +5 -5
- data/test/{liquid → integration}/tags/unless_else_tag_test.rb +1 -1
- data/test/{liquid → integration}/template_test.rb +81 -45
- data/test/integration/variable_test.rb +82 -0
- data/test/test_helper.rb +73 -20
- data/test/{liquid/block_test.rb → unit/block_unit_test.rb} +2 -5
- data/test/{liquid/condition_test.rb → unit/condition_unit_test.rb} +23 -1
- data/test/{liquid/context_test.rb → unit/context_unit_test.rb} +39 -25
- data/test/{liquid/file_system_test.rb → unit/file_system_unit_test.rb} +11 -5
- data/test/unit/i18n_unit_test.rb +37 -0
- data/test/unit/lexer_unit_test.rb +48 -0
- data/test/{liquid/module_ex_test.rb → unit/module_ex_unit_test.rb} +7 -7
- data/test/unit/parser_unit_test.rb +82 -0
- data/test/{liquid/regexp_test.rb → unit/regexp_unit_test.rb} +3 -3
- data/test/{liquid/strainer_test.rb → unit/strainer_unit_test.rb} +20 -1
- data/test/unit/tag_unit_test.rb +16 -0
- data/test/unit/tags/case_tag_unit_test.rb +10 -0
- data/test/unit/tags/for_tag_unit_test.rb +13 -0
- data/test/unit/tags/if_tag_unit_test.rb +8 -0
- data/test/unit/template_unit_test.rb +69 -0
- data/test/unit/tokenizer_unit_test.rb +38 -0
- data/test/unit/variable_unit_test.rb +139 -0
- metadata +135 -67
- data/lib/extras/liquid_view.rb +0 -51
- data/lib/liquid/htmltags.rb +0 -73
- data/test/liquid/drop_test.rb +0 -180
- data/test/liquid/error_handling_test.rb +0 -81
- data/test/liquid/hash_ordering_test.rb +0 -25
- data/test/liquid/parsing_quirks_test.rb +0 -52
- data/test/liquid/tags/include_tag_test.rb +0 -166
- data/test/liquid/tags/statements_test.rb +0 -134
- data/test/liquid/variable_test.rb +0 -186
@@ -0,0 +1,234 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class TestFileSystem
|
4
|
+
def read_template_file(template_path, context)
|
5
|
+
case template_path
|
6
|
+
when "product"
|
7
|
+
"Product: {{ product.title }} "
|
8
|
+
|
9
|
+
when "locale_variables"
|
10
|
+
"Locale: {{echo1}} {{echo2}}"
|
11
|
+
|
12
|
+
when "variant"
|
13
|
+
"Variant: {{ variant.title }}"
|
14
|
+
|
15
|
+
when "nested_template"
|
16
|
+
"{% include 'header' %} {% include 'body' %} {% include 'footer' %}"
|
17
|
+
|
18
|
+
when "body"
|
19
|
+
"body {% include 'body_detail' %}"
|
20
|
+
|
21
|
+
when "nested_product_template"
|
22
|
+
"Product: {{ nested_product_template.title }} {%include 'details'%} "
|
23
|
+
|
24
|
+
when "recursively_nested_template"
|
25
|
+
"-{% include 'recursively_nested_template' %}"
|
26
|
+
|
27
|
+
when "pick_a_source"
|
28
|
+
"from TestFileSystem"
|
29
|
+
|
30
|
+
when 'assignments'
|
31
|
+
"{% assign foo = 'bar' %}"
|
32
|
+
|
33
|
+
else
|
34
|
+
template_path
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class OtherFileSystem
|
40
|
+
def read_template_file(template_path, context)
|
41
|
+
'from OtherFileSystem'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
class CountingFileSystem
|
46
|
+
attr_reader :count
|
47
|
+
def read_template_file(template_path, context)
|
48
|
+
@count ||= 0
|
49
|
+
@count += 1
|
50
|
+
'from CountingFileSystem'
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class CustomInclude < Liquid::Tag
|
55
|
+
Syntax = /(#{Liquid::QuotedFragment}+)(\s+(?:with|for)\s+(#{Liquid::QuotedFragment}+))?/o
|
56
|
+
|
57
|
+
def initialize(tag_name, markup, tokens)
|
58
|
+
markup =~ Syntax
|
59
|
+
@template_name = $1
|
60
|
+
super
|
61
|
+
end
|
62
|
+
|
63
|
+
def parse(tokens)
|
64
|
+
end
|
65
|
+
|
66
|
+
def render(context)
|
67
|
+
@template_name[1..-2]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
class IncludeTagTest < Minitest::Test
|
72
|
+
include Liquid
|
73
|
+
|
74
|
+
def setup
|
75
|
+
Liquid::Template.file_system = TestFileSystem.new
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_include_tag_looks_for_file_system_in_registers_first
|
79
|
+
assert_equal 'from OtherFileSystem',
|
80
|
+
Template.parse("{% include 'pick_a_source' %}").render!({}, :registers => {:file_system => OtherFileSystem.new})
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
def test_include_tag_with
|
85
|
+
assert_template_result "Product: Draft 151cm ",
|
86
|
+
"{% include 'product' with products[0] %}", "products" => [ {'title' => 'Draft 151cm'}, {'title' => 'Element 155cm'} ]
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_include_tag_with_default_name
|
90
|
+
assert_template_result "Product: Draft 151cm ",
|
91
|
+
"{% include 'product' %}", "product" => {'title' => 'Draft 151cm'}
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_include_tag_for
|
95
|
+
assert_template_result "Product: Draft 151cm Product: Element 155cm ",
|
96
|
+
"{% include 'product' for products %}", "products" => [ {'title' => 'Draft 151cm'}, {'title' => 'Element 155cm'} ]
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_include_tag_with_local_variables
|
100
|
+
assert_template_result "Locale: test123 ", "{% include 'locale_variables' echo1: 'test123' %}"
|
101
|
+
end
|
102
|
+
|
103
|
+
def test_include_tag_with_multiple_local_variables
|
104
|
+
assert_template_result "Locale: test123 test321",
|
105
|
+
"{% include 'locale_variables' echo1: 'test123', echo2: 'test321' %}"
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_include_tag_with_multiple_local_variables_from_context
|
109
|
+
assert_template_result "Locale: test123 test321",
|
110
|
+
"{% include 'locale_variables' echo1: echo1, echo2: more_echos.echo2 %}",
|
111
|
+
'echo1' => 'test123', 'more_echos' => { "echo2" => 'test321'}
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_included_templates_assigns_variables
|
115
|
+
assert_template_result "bar", "{% include 'assignments' %}{{ foo }}"
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_nested_include_tag
|
119
|
+
assert_template_result "body body_detail", "{% include 'body' %}"
|
120
|
+
|
121
|
+
assert_template_result "header body body_detail footer", "{% include 'nested_template' %}"
|
122
|
+
end
|
123
|
+
|
124
|
+
def test_nested_include_with_variable
|
125
|
+
assert_template_result "Product: Draft 151cm details ",
|
126
|
+
"{% include 'nested_product_template' with product %}", "product" => {"title" => 'Draft 151cm'}
|
127
|
+
|
128
|
+
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'}]
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_recursively_included_template_does_not_produce_endless_loop
|
133
|
+
|
134
|
+
infinite_file_system = Class.new do
|
135
|
+
def read_template_file(template_path, context)
|
136
|
+
"-{% include 'loop' %}"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
Liquid::Template.file_system = infinite_file_system.new
|
141
|
+
|
142
|
+
assert_raises(Liquid::StackLevelError, SystemStackError) do
|
143
|
+
Template.parse("{% include 'loop' %}").render!
|
144
|
+
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
|
+
end
|
159
|
+
|
160
|
+
def test_dynamically_choosen_template
|
161
|
+
assert_template_result "Test123", "{% include template %}", "template" => 'Test123'
|
162
|
+
assert_template_result "Test321", "{% include template %}", "template" => 'Test321'
|
163
|
+
|
164
|
+
assert_template_result "Product: Draft 151cm ", "{% include template for product %}",
|
165
|
+
"template" => 'product', 'product' => { 'title' => 'Draft 151cm'}
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_include_tag_caches_second_read_of_same_partial
|
169
|
+
file_system = CountingFileSystem.new
|
170
|
+
assert_equal 'from CountingFileSystemfrom CountingFileSystem',
|
171
|
+
Template.parse("{% include 'pick_a_source' %}{% include 'pick_a_source' %}").render!({}, :registers => {:file_system => file_system})
|
172
|
+
assert_equal 1, file_system.count
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_include_tag_doesnt_cache_partials_across_renders
|
176
|
+
file_system = CountingFileSystem.new
|
177
|
+
assert_equal 'from CountingFileSystem',
|
178
|
+
Template.parse("{% include 'pick_a_source' %}").render!({}, :registers => {:file_system => file_system})
|
179
|
+
assert_equal 1, file_system.count
|
180
|
+
|
181
|
+
assert_equal 'from CountingFileSystem',
|
182
|
+
Template.parse("{% include 'pick_a_source' %}").render!({}, :registers => {:file_system => file_system})
|
183
|
+
assert_equal 2, file_system.count
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_include_tag_within_if_statement
|
187
|
+
assert_template_result "foo_if_true", "{% if true %}{% include 'foo_if_true' %}{% endif %}"
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_custom_include_tag
|
191
|
+
original_tag = Liquid::Template.tags['include']
|
192
|
+
Liquid::Template.tags['include'] = CustomInclude
|
193
|
+
begin
|
194
|
+
assert_equal "custom_foo",
|
195
|
+
Template.parse("{% include 'custom_foo' %}").render!
|
196
|
+
ensure
|
197
|
+
Liquid::Template.tags['include'] = original_tag
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_custom_include_tag_within_if_statement
|
202
|
+
original_tag = Liquid::Template.tags['include']
|
203
|
+
Liquid::Template.tags['include'] = CustomInclude
|
204
|
+
begin
|
205
|
+
assert_equal "custom_foo_if_true",
|
206
|
+
Template.parse("{% if true %}{% include 'custom_foo_if_true' %}{% endif %}").render!
|
207
|
+
ensure
|
208
|
+
Liquid::Template.tags['include'] = original_tag
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
def test_does_not_add_error_in_strict_mode_for_missing_variable
|
213
|
+
Liquid::Template.file_system = TestFileSystem.new
|
214
|
+
|
215
|
+
a = Liquid::Template.parse(' {% include "nested_template" %}')
|
216
|
+
a.render!
|
217
|
+
assert_empty a.errors
|
218
|
+
end
|
219
|
+
|
220
|
+
def test_passing_options_to_included_templates
|
221
|
+
assert_raises(Liquid::SyntaxError) do
|
222
|
+
Template.parse("{% include template %}", error_mode: :strict).render!("template" => '{{ "X" || downcase }}')
|
223
|
+
end
|
224
|
+
with_error_mode(:lax) do
|
225
|
+
assert_equal 'x', Template.parse("{% include template %}", error_mode: :strict, include_options_blacklist: true).render!("template" => '{{ "X" || downcase }}')
|
226
|
+
end
|
227
|
+
assert_raises(Liquid::SyntaxError) do
|
228
|
+
Template.parse("{% include template %}", error_mode: :strict, include_options_blacklist: [:locale]).render!("template" => '{{ "X" || downcase }}')
|
229
|
+
end
|
230
|
+
with_error_mode(:lax) do
|
231
|
+
assert_equal 'x', Template.parse("{% include template %}", error_mode: :strict, include_options_blacklist: [:error_mode]).render!("template" => '{{ "X" || downcase }}')
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end # IncludeTagTest
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class RawTagTest < Test
|
3
|
+
class RawTagTest < Minitest::Test
|
4
4
|
include Liquid
|
5
5
|
|
6
6
|
def test_tag_in_raw
|
@@ -20,5 +20,6 @@ class RawTagTest < Test::Unit::TestCase
|
|
20
20
|
assert_template_result ' Foobar {% invalid {% {% endraw ', '{% raw %} Foobar {% invalid {% {% endraw {% endraw %}'
|
21
21
|
assert_template_result ' Foobar {% {% {% ', '{% raw %} Foobar {% {% {% {% endraw %}'
|
22
22
|
assert_template_result ' test {% raw %} {% endraw %}', '{% raw %} test {% raw %} {% {% endraw %}endraw %}'
|
23
|
+
assert_template_result ' Foobar {{ invalid 1', '{% raw %} Foobar {{ invalid {% endraw %}{{ 1 }}'
|
23
24
|
end
|
24
25
|
end
|
@@ -1,14 +1,8 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class StandardTagTest < Test
|
3
|
+
class StandardTagTest < Minitest::Test
|
4
4
|
include Liquid
|
5
5
|
|
6
|
-
def test_tag
|
7
|
-
tag = Tag.new('tag', [], [])
|
8
|
-
assert_equal 'liquid::tag', tag.name
|
9
|
-
assert_equal '', tag.render(Context.new)
|
10
|
-
end
|
11
|
-
|
12
6
|
def test_no_transform
|
13
7
|
assert_template_result('this text should come out of the template without change...',
|
14
8
|
'this text should come out of the template without change...')
|
@@ -33,6 +27,13 @@ class StandardTagTest < Test::Unit::TestCase
|
|
33
27
|
assert_template_result('','{% comment %}{% endcomment %}')
|
34
28
|
assert_template_result('','{%comment%}comment{%endcomment%}')
|
35
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 %}')
|
36
37
|
|
37
38
|
assert_template_result('foobar','foo{%comment%}comment{%endcomment%}bar')
|
38
39
|
assert_template_result('foobar','foo{% comment %}comment{% endcomment %}bar')
|
@@ -47,16 +48,9 @@ class StandardTagTest < Test::Unit::TestCase
|
|
47
48
|
{%endcomment%}bar')
|
48
49
|
end
|
49
50
|
|
50
|
-
def test_assign
|
51
|
-
assigns = {'var' => 'content' }
|
52
|
-
assert_template_result('var2: var2:content', 'var2:{{var2}} {%assign var2 = var%} var2:{{var2}}', assigns)
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
51
|
def test_hyphenated_assign
|
57
52
|
assigns = {'a-b' => '1' }
|
58
53
|
assert_template_result('a-b:1 a-b:2', 'a-b:{{a-b}} {%assign a-b = 2 %}a-b:{{a-b}}', assigns)
|
59
|
-
|
60
54
|
end
|
61
55
|
|
62
56
|
def test_assign_with_colon_and_spaces
|
@@ -72,7 +66,7 @@ class StandardTagTest < Test::Unit::TestCase
|
|
72
66
|
end
|
73
67
|
|
74
68
|
def test_capture_detects_bad_syntax
|
75
|
-
|
69
|
+
assert_raises(SyntaxError) do
|
76
70
|
assert_template_result('content foo content foo ',
|
77
71
|
'{{ var2 }}{% capture %}{{ var }} foo {% endcapture %}{{ var2 }}{{ var2 }}',
|
78
72
|
{'var' => 'content' })
|
@@ -180,11 +174,11 @@ class StandardTagTest < Test::Unit::TestCase
|
|
180
174
|
# Example from the shopify forums
|
181
175
|
code = %q({% case collection.handle %}{% when 'menswear-jackets' %}{% assign ptitle = 'menswear' %}{% when 'menswear-t-shirts' %}{% assign ptitle = 'menswear' %}{% else %}{% assign ptitle = 'womenswear' %}{% endcase %}{{ ptitle }})
|
182
176
|
template = Liquid::Template.parse(code)
|
183
|
-
assert_equal "menswear", template.render("collection" => {'handle' => 'menswear-jackets'})
|
184
|
-
assert_equal "menswear", template.render("collection" => {'handle' => 'menswear-t-shirts'})
|
185
|
-
assert_equal "womenswear", template.render("collection" => {'handle' => 'x'})
|
186
|
-
assert_equal "womenswear", template.render("collection" => {'handle' => 'y'})
|
187
|
-
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'})
|
188
182
|
end
|
189
183
|
|
190
184
|
def test_case_when_or
|
@@ -218,24 +212,28 @@ class StandardTagTest < Test::Unit::TestCase
|
|
218
212
|
end
|
219
213
|
|
220
214
|
def test_assign
|
221
|
-
|
215
|
+
assert_template_result 'variable', '{% assign a = "variable"%}{{a}}'
|
216
|
+
end
|
217
|
+
|
218
|
+
def test_assign_unassigned
|
219
|
+
assigns = { 'var' => 'content' }
|
220
|
+
assert_template_result('var2: var2:content', 'var2:{{var2}} {%assign var2 = var%} var2:{{var2}}', assigns)
|
222
221
|
end
|
223
222
|
|
224
223
|
def test_assign_an_empty_string
|
225
|
-
|
224
|
+
assert_template_result '', '{% assign a = ""%}{{a}}'
|
226
225
|
end
|
227
226
|
|
228
227
|
def test_assign_is_global
|
229
|
-
|
230
|
-
Liquid::Template.parse( '{%for i in (1..2) %}{% assign a = "variable"%}{% endfor %}{{a}}' ).render
|
228
|
+
assert_template_result 'variable', '{%for i in (1..2) %}{% assign a = "variable"%}{% endfor %}{{a}}'
|
231
229
|
end
|
232
230
|
|
233
231
|
def test_case_detects_bad_syntax
|
234
|
-
|
232
|
+
assert_raises(SyntaxError) do
|
235
233
|
assert_template_result('', '{% case false %}{% when %}true{% endcase %}', {})
|
236
234
|
end
|
237
235
|
|
238
|
-
|
236
|
+
assert_raises(SyntaxError) do
|
239
237
|
assert_template_result('', '{% case false %}{% huh %}true{% endcase %}', {})
|
240
238
|
end
|
241
239
|
|
@@ -292,4 +290,8 @@ class StandardTagTest < Test::Unit::TestCase
|
|
292
290
|
assigns = {'array' => [ 1, 1, 1, 1] }
|
293
291
|
assert_template_result('1','{%for item in array%}{%ifchanged%}{{item}}{% endifchanged %}{%endfor%}',assigns)
|
294
292
|
end
|
293
|
+
|
294
|
+
def test_multiline_tag
|
295
|
+
assert_template_result '0 1 2 3', "0{%\nfor i in (1..3)\n%} {{\ni\n}}{%\nendfor\n%}"
|
296
|
+
end
|
295
297
|
end # StandardTagTest
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class StatementsTest < Minitest::Test
|
4
|
+
include Liquid
|
5
|
+
|
6
|
+
def test_true_eql_true
|
7
|
+
text = ' {% if true == true %} true {% else %} false {% endif %} '
|
8
|
+
assert_template_result ' true ', text
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_true_not_eql_true
|
12
|
+
text = ' {% if true != true %} true {% else %} false {% endif %} '
|
13
|
+
assert_template_result ' false ', text
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_true_lq_true
|
17
|
+
text = ' {% if 0 > 0 %} true {% else %} false {% endif %} '
|
18
|
+
assert_template_result ' false ', text
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_one_lq_zero
|
22
|
+
text = ' {% if 1 > 0 %} true {% else %} false {% endif %} '
|
23
|
+
assert_template_result ' true ', text
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_zero_lq_one
|
27
|
+
text = ' {% if 0 < 1 %} true {% else %} false {% endif %} '
|
28
|
+
assert_template_result ' true ', text
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_zero_lq_or_equal_one
|
32
|
+
text = ' {% if 0 <= 0 %} true {% else %} false {% endif %} '
|
33
|
+
assert_template_result ' true ', text
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_zero_lq_or_equal_one_involving_nil
|
37
|
+
text = ' {% if null <= 0 %} true {% else %} false {% endif %} '
|
38
|
+
assert_template_result ' false ', text
|
39
|
+
|
40
|
+
|
41
|
+
text = ' {% if 0 <= null %} true {% else %} false {% endif %} '
|
42
|
+
assert_template_result ' false ', text
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_zero_lqq_or_equal_one
|
46
|
+
text = ' {% if 0 >= 0 %} true {% else %} false {% endif %} '
|
47
|
+
assert_template_result ' true ', text
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_strings
|
51
|
+
text = " {% if 'test' == 'test' %} true {% else %} false {% endif %} "
|
52
|
+
assert_template_result ' true ', text
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_strings_not_equal
|
56
|
+
text = " {% if 'test' != 'test' %} true {% else %} false {% endif %} "
|
57
|
+
assert_template_result ' false ', text
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_var_strings_equal
|
61
|
+
text = ' {% if var == "hello there!" %} true {% else %} false {% endif %} '
|
62
|
+
assert_template_result ' true ', text, 'var' => 'hello there!'
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_var_strings_are_not_equal
|
66
|
+
text = ' {% if "hello there!" == var %} true {% else %} false {% endif %} '
|
67
|
+
assert_template_result ' true ', text, 'var' => 'hello there!'
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_var_and_long_string_are_equal
|
71
|
+
text = " {% if var == 'hello there!' %} true {% else %} false {% endif %} "
|
72
|
+
assert_template_result ' true ', text, 'var' => 'hello there!'
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
def test_var_and_long_string_are_equal_backwards
|
77
|
+
text = " {% if 'hello there!' == var %} true {% else %} false {% endif %} "
|
78
|
+
assert_template_result ' true ', text, 'var' => 'hello there!'
|
79
|
+
end
|
80
|
+
|
81
|
+
#def test_is_nil
|
82
|
+
# text = %| {% if var != nil %} true {% else %} false {% end %} |
|
83
|
+
# @template.assigns = { 'var' => 'hello there!'}
|
84
|
+
# expected = %| true |
|
85
|
+
# assert_equal expected, @template.parse(text)
|
86
|
+
#end
|
87
|
+
|
88
|
+
def test_is_collection_empty
|
89
|
+
text = ' {% if array == empty %} true {% else %} false {% endif %} '
|
90
|
+
assert_template_result ' true ', text, 'array' => []
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_is_not_collection_empty
|
94
|
+
text = ' {% if array == empty %} true {% else %} false {% endif %} '
|
95
|
+
assert_template_result ' false ', text, 'array' => [1,2,3]
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_nil
|
99
|
+
text = ' {% if var == nil %} true {% else %} false {% endif %} '
|
100
|
+
assert_template_result ' true ', text, 'var' => nil
|
101
|
+
|
102
|
+
text = ' {% if var == null %} true {% else %} false {% endif %} '
|
103
|
+
assert_template_result ' true ', text, 'var' => nil
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_not_nil
|
107
|
+
text = ' {% if var != nil %} true {% else %} false {% endif %} '
|
108
|
+
assert_template_result ' true ', text, 'var' => 1
|
109
|
+
|
110
|
+
text = ' {% if var != null %} true {% else %} false {% endif %} '
|
111
|
+
assert_template_result ' true ', text, 'var' => 1
|
112
|
+
end
|
113
|
+
end # StatementsTest
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class TableRowTest < Minitest::Test
|
4
4
|
include Liquid
|
5
5
|
|
6
6
|
class ArrayDrop < Liquid::Drop
|
@@ -15,7 +15,7 @@ class HtmlTagTest < Test::Unit::TestCase
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
18
|
+
def test_table_row
|
19
19
|
|
20
20
|
assert_template_result("<tr class=\"row1\">\n<td class=\"col1\"> 1 </td><td class=\"col2\"> 2 </td><td class=\"col3\"> 3 </td></tr>\n<tr class=\"row2\"><td class=\"col1\"> 4 </td><td class=\"col2\"> 5 </td><td class=\"col3\"> 6 </td></tr>\n",
|
21
21
|
'{% tablerow n in numbers cols:3%} {{n}} {% endtablerow %}',
|
@@ -26,14 +26,14 @@ class HtmlTagTest < Test::Unit::TestCase
|
|
26
26
|
'numbers' => [])
|
27
27
|
end
|
28
28
|
|
29
|
-
def
|
29
|
+
def test_table_row_with_different_cols
|
30
30
|
assert_template_result("<tr class=\"row1\">\n<td class=\"col1\"> 1 </td><td class=\"col2\"> 2 </td><td class=\"col3\"> 3 </td><td class=\"col4\"> 4 </td><td class=\"col5\"> 5 </td></tr>\n<tr class=\"row2\"><td class=\"col1\"> 6 </td></tr>\n",
|
31
31
|
'{% tablerow n in numbers cols:5%} {{n}} {% endtablerow %}',
|
32
32
|
'numbers' => [1,2,3,4,5,6])
|
33
33
|
|
34
34
|
end
|
35
35
|
|
36
|
-
def
|
36
|
+
def test_table_col_counter
|
37
37
|
assert_template_result("<tr class=\"row1\">\n<td class=\"col1\">1</td><td class=\"col2\">2</td></tr>\n<tr class=\"row2\"><td class=\"col1\">1</td><td class=\"col2\">2</td></tr>\n<tr class=\"row3\"><td class=\"col1\">1</td><td class=\"col2\">2</td></tr>\n",
|
38
38
|
'{% tablerow n in numbers cols:2%}{{tablerowloop.col}}{% endtablerow %}',
|
39
39
|
'numbers' => [1,2,3,4,5,6])
|
@@ -60,4 +60,4 @@ class HtmlTagTest < Test::Unit::TestCase
|
|
60
60
|
'{% tablerow n in numbers cols:3 offset:1 limit:6%} {{n}} {% endtablerow %}',
|
61
61
|
'numbers' => [0,1,2,3,4,5,6,7])
|
62
62
|
end
|
63
|
-
end
|
63
|
+
end
|