liquid 2.6.3 → 3.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +42 -13
  3. data/README.md +27 -2
  4. data/lib/liquid.rb +11 -11
  5. data/lib/liquid/block.rb +75 -45
  6. data/lib/liquid/condition.rb +15 -11
  7. data/lib/liquid/context.rb +68 -29
  8. data/lib/liquid/document.rb +3 -3
  9. data/lib/liquid/drop.rb +17 -1
  10. data/lib/liquid/file_system.rb +17 -6
  11. data/lib/liquid/i18n.rb +39 -0
  12. data/lib/liquid/interrupts.rb +1 -1
  13. data/lib/liquid/lexer.rb +51 -0
  14. data/lib/liquid/locales/en.yml +22 -0
  15. data/lib/liquid/parser.rb +90 -0
  16. data/lib/liquid/standardfilters.rb +115 -52
  17. data/lib/liquid/strainer.rb +14 -4
  18. data/lib/liquid/tag.rb +42 -7
  19. data/lib/liquid/tags/assign.rb +10 -8
  20. data/lib/liquid/tags/break.rb +1 -1
  21. data/lib/liquid/tags/capture.rb +10 -8
  22. data/lib/liquid/tags/case.rb +13 -13
  23. data/lib/liquid/tags/comment.rb +9 -2
  24. data/lib/liquid/tags/continue.rb +1 -4
  25. data/lib/liquid/tags/cycle.rb +5 -7
  26. data/lib/liquid/tags/decrement.rb +3 -4
  27. data/lib/liquid/tags/for.rb +69 -36
  28. data/lib/liquid/tags/if.rb +52 -25
  29. data/lib/liquid/tags/ifchanged.rb +2 -2
  30. data/lib/liquid/tags/include.rb +8 -7
  31. data/lib/liquid/tags/increment.rb +4 -8
  32. data/lib/liquid/tags/raw.rb +3 -3
  33. data/lib/liquid/tags/table_row.rb +73 -0
  34. data/lib/liquid/tags/unless.rb +2 -4
  35. data/lib/liquid/template.rb +69 -10
  36. data/lib/liquid/utils.rb +13 -4
  37. data/lib/liquid/variable.rb +59 -8
  38. data/lib/liquid/version.rb +1 -1
  39. data/test/fixtures/en_locale.yml +9 -0
  40. data/test/{liquid → integration}/assign_test.rb +6 -0
  41. data/test/integration/blank_test.rb +106 -0
  42. data/test/{liquid → integration}/capture_test.rb +2 -2
  43. data/test/integration/context_test.rb +33 -0
  44. data/test/integration/drop_test.rb +245 -0
  45. data/test/{liquid → integration}/error_handling_test.rb +31 -2
  46. data/test/{liquid → integration}/filter_test.rb +7 -7
  47. data/test/{liquid → integration}/hash_ordering_test.rb +0 -0
  48. data/test/{liquid → integration}/output_test.rb +12 -12
  49. data/test/integration/parsing_quirks_test.rb +94 -0
  50. data/test/{liquid → integration}/security_test.rb +9 -9
  51. data/test/{liquid → integration}/standard_filter_test.rb +103 -33
  52. data/test/{liquid → integration}/tags/break_tag_test.rb +0 -0
  53. data/test/{liquid → integration}/tags/continue_tag_test.rb +0 -0
  54. data/test/{liquid → integration}/tags/for_tag_test.rb +78 -0
  55. data/test/{liquid → integration}/tags/if_else_tag_test.rb +1 -1
  56. data/test/integration/tags/include_tag_test.rb +212 -0
  57. data/test/{liquid → integration}/tags/increment_tag_test.rb +0 -0
  58. data/test/{liquid → integration}/tags/raw_tag_test.rb +1 -0
  59. data/test/{liquid → integration}/tags/standard_tag_test.rb +24 -22
  60. data/test/integration/tags/statements_test.rb +113 -0
  61. data/test/{liquid/tags/html_tag_test.rb → integration/tags/table_row_test.rb} +5 -5
  62. data/test/{liquid → integration}/tags/unless_else_tag_test.rb +0 -0
  63. data/test/{liquid → integration}/template_test.rb +66 -42
  64. data/test/integration/variable_test.rb +72 -0
  65. data/test/test_helper.rb +32 -7
  66. data/test/{liquid/block_test.rb → unit/block_unit_test.rb} +1 -1
  67. data/test/{liquid/condition_test.rb → unit/condition_unit_test.rb} +19 -1
  68. data/test/{liquid/context_test.rb → unit/context_unit_test.rb} +27 -19
  69. data/test/{liquid/file_system_test.rb → unit/file_system_unit_test.rb} +7 -1
  70. data/test/unit/i18n_unit_test.rb +37 -0
  71. data/test/unit/lexer_unit_test.rb +48 -0
  72. data/test/{liquid/module_ex_test.rb → unit/module_ex_unit_test.rb} +7 -7
  73. data/test/unit/parser_unit_test.rb +82 -0
  74. data/test/{liquid/regexp_test.rb → unit/regexp_unit_test.rb} +3 -3
  75. data/test/{liquid/strainer_test.rb → unit/strainer_unit_test.rb} +19 -1
  76. data/test/unit/tag_unit_test.rb +11 -0
  77. data/test/unit/tags/case_tag_unit_test.rb +10 -0
  78. data/test/unit/tags/for_tag_unit_test.rb +13 -0
  79. data/test/unit/tags/if_tag_unit_test.rb +8 -0
  80. data/test/unit/template_unit_test.rb +69 -0
  81. data/test/unit/tokenizer_unit_test.rb +29 -0
  82. data/test/{liquid/variable_test.rb → unit/variable_unit_test.rb} +17 -67
  83. metadata +117 -73
  84. data/lib/extras/liquid_view.rb +0 -51
  85. data/lib/liquid/htmltags.rb +0 -73
  86. data/test/liquid/drop_test.rb +0 -180
  87. data/test/liquid/parsing_quirks_test.rb +0 -52
  88. data/test/liquid/tags/include_tag_test.rb +0 -166
  89. data/test/liquid/tags/statements_test.rb +0 -134
File without changes
@@ -1,5 +1,11 @@
1
1
  require 'test_helper'
2
2
 
3
+ class ThingWithValue < Liquid::Drop
4
+ def value
5
+ 3
6
+ end
7
+ end
8
+
3
9
  class ForTagTest < Test::Unit::TestCase
4
10
  include Liquid
5
11
 
@@ -34,6 +40,20 @@ HERE
34
40
  assert_template_result(' 1 2 3 ','{%for item in (1..3) %} {{item}} {%endfor%}')
35
41
  end
36
42
 
43
+ def test_for_with_variable_range
44
+ assert_template_result(' 1 2 3 ','{%for item in (1..foobar) %} {{item}} {%endfor%}', "foobar" => 3)
45
+ end
46
+
47
+ def test_for_with_hash_value_range
48
+ foobar = { "value" => 3 }
49
+ assert_template_result(' 1 2 3 ','{%for item in (1..foobar.value) %} {{item}} {%endfor%}', "foobar" => foobar)
50
+ end
51
+
52
+ def test_for_with_drop_value_range
53
+ foobar = ThingWithValue.new
54
+ assert_template_result(' 1 2 3 ','{%for item in (1..foobar.value) %} {{item}} {%endfor%}', "foobar" => foobar)
55
+ end
56
+
37
57
  def test_for_with_variable
38
58
  assert_template_result(' 1 2 3 ','{%for item in array%} {{item}} {%endfor%}','array' => [1,2,3])
39
59
  assert_template_result('123','{%for item in array%}{{item}}{%endfor%}','array' => [1,2,3])
@@ -294,4 +314,62 @@ HERE
294
314
  assigns = {'items' => [1,2,3,4,5]}
295
315
  assert_template_result(expected, template, assigns)
296
316
  end
317
+
318
+ class LoaderDrop < Liquid::Drop
319
+ attr_accessor :each_called, :load_slice_called
320
+
321
+ def initialize(data)
322
+ @data = data
323
+ end
324
+
325
+ def each
326
+ @each_called = true
327
+ @data.each { |el| yield el }
328
+ end
329
+
330
+ def load_slice(from, to)
331
+ @load_slice_called = true
332
+ @data[(from..to-1)]
333
+ end
334
+ end
335
+
336
+ def test_iterate_with_each_when_no_limit_applied
337
+ loader = LoaderDrop.new([1,2,3,4,5])
338
+ assigns = {'items' => loader}
339
+ expected = '12345'
340
+ template = '{% for item in items %}{{item}}{% endfor %}'
341
+ assert_template_result(expected, template, assigns)
342
+ assert loader.each_called
343
+ assert !loader.load_slice_called
344
+ end
345
+
346
+ def test_iterate_with_load_slice_when_limit_applied
347
+ loader = LoaderDrop.new([1,2,3,4,5])
348
+ assigns = {'items' => loader}
349
+ expected = '1'
350
+ template = '{% for item in items limit:1 %}{{item}}{% endfor %}'
351
+ assert_template_result(expected, template, assigns)
352
+ assert !loader.each_called
353
+ assert loader.load_slice_called
354
+ end
355
+
356
+ def test_iterate_with_load_slice_when_limit_and_offset_applied
357
+ loader = LoaderDrop.new([1,2,3,4,5])
358
+ assigns = {'items' => loader}
359
+ expected = '34'
360
+ template = '{% for item in items offset:2 limit:2 %}{{item}}{% endfor %}'
361
+ assert_template_result(expected, template, assigns)
362
+ assert !loader.each_called
363
+ assert loader.load_slice_called
364
+ end
365
+
366
+ def test_iterate_with_load_slice_returns_same_results_as_without
367
+ loader = LoaderDrop.new([1,2,3,4,5])
368
+ loader_assigns = {'items' => loader}
369
+ array_assigns = {'items' => [1,2,3,4,5]}
370
+ expected = '34'
371
+ template = '{% for item in items offset:2 limit:2 %}{{item}}{% endfor %}'
372
+ assert_template_result(expected, template, loader_assigns)
373
+ assert_template_result(expected, template, array_assigns)
374
+ end
297
375
  end
@@ -163,4 +163,4 @@ class IfElseTagTest < Test::Unit::TestCase
163
163
  assert_template_result('', %({% if 1 or throw or or 1 %}yes{% endif %}))
164
164
  end
165
165
  end
166
- end # IfElseTest
166
+ end
@@ -0,0 +1,212 @@
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
+ else
31
+ template_path
32
+ end
33
+ end
34
+ end
35
+
36
+ class OtherFileSystem
37
+ def read_template_file(template_path, context)
38
+ 'from OtherFileSystem'
39
+ end
40
+ end
41
+
42
+ class CountingFileSystem
43
+ attr_reader :count
44
+ def read_template_file(template_path, context)
45
+ @count ||= 0
46
+ @count += 1
47
+ 'from CountingFileSystem'
48
+ end
49
+ end
50
+
51
+ class CustomInclude < Liquid::Tag
52
+ Syntax = /(#{Liquid::QuotedFragment}+)(\s+(?:with|for)\s+(#{Liquid::QuotedFragment}+))?/o
53
+
54
+ def initialize(tag_name, markup, tokens)
55
+ markup =~ Syntax
56
+ @template_name = $1
57
+ super
58
+ end
59
+
60
+ def parse(tokens)
61
+ end
62
+
63
+ def render(context)
64
+ @template_name[1..-2]
65
+ end
66
+ end
67
+
68
+ class IncludeTagTest < Test::Unit::TestCase
69
+ include Liquid
70
+
71
+ def setup
72
+ Liquid::Template.file_system = TestFileSystem.new
73
+ end
74
+
75
+ def test_include_tag_looks_for_file_system_in_registers_first
76
+ assert_equal 'from OtherFileSystem',
77
+ Template.parse("{% include 'pick_a_source' %}").render!({}, :registers => {:file_system => OtherFileSystem.new})
78
+ end
79
+
80
+
81
+ def test_include_tag_with
82
+ assert_template_result "Product: Draft 151cm ",
83
+ "{% include 'product' with products[0] %}", "products" => [ {'title' => 'Draft 151cm'}, {'title' => 'Element 155cm'} ]
84
+ end
85
+
86
+ def test_include_tag_with_default_name
87
+ assert_template_result "Product: Draft 151cm ",
88
+ "{% include 'product' %}", "product" => {'title' => 'Draft 151cm'}
89
+ end
90
+
91
+ def test_include_tag_for
92
+ assert_template_result "Product: Draft 151cm Product: Element 155cm ",
93
+ "{% include 'product' for products %}", "products" => [ {'title' => 'Draft 151cm'}, {'title' => 'Element 155cm'} ]
94
+ end
95
+
96
+ def test_include_tag_with_local_variables
97
+ assert_template_result "Locale: test123 ", "{% include 'locale_variables' echo1: 'test123' %}"
98
+ end
99
+
100
+ def test_include_tag_with_multiple_local_variables
101
+ assert_template_result "Locale: test123 test321",
102
+ "{% include 'locale_variables' echo1: 'test123', echo2: 'test321' %}"
103
+ end
104
+
105
+ def test_include_tag_with_multiple_local_variables_from_context
106
+ assert_template_result "Locale: test123 test321",
107
+ "{% include 'locale_variables' echo1: echo1, echo2: more_echos.echo2 %}",
108
+ 'echo1' => 'test123', 'more_echos' => { "echo2" => 'test321'}
109
+ end
110
+
111
+ def test_nested_include_tag
112
+ assert_template_result "body body_detail", "{% include 'body' %}"
113
+
114
+ assert_template_result "header body body_detail footer", "{% include 'nested_template' %}"
115
+ end
116
+
117
+ def test_nested_include_with_variable
118
+ assert_template_result "Product: Draft 151cm details ",
119
+ "{% include 'nested_product_template' with product %}", "product" => {"title" => 'Draft 151cm'}
120
+
121
+ assert_template_result "Product: Draft 151cm details Product: Element 155cm details ",
122
+ "{% include 'nested_product_template' for products %}", "products" => [{"title" => 'Draft 151cm'}, {"title" => 'Element 155cm'}]
123
+ end
124
+
125
+ def test_recursively_included_template_does_not_produce_endless_loop
126
+
127
+ infinite_file_system = Class.new do
128
+ def read_template_file(template_path, context)
129
+ "-{% include 'loop' %}"
130
+ end
131
+ end
132
+
133
+ Liquid::Template.file_system = infinite_file_system.new
134
+
135
+ assert_raise(Liquid::StackLevelError) do
136
+ Template.parse("{% include 'loop' %}").render!
137
+ end
138
+
139
+ end
140
+
141
+ def test_backwards_compatability_support_for_overridden_read_template_file
142
+ infinite_file_system = Class.new do
143
+ def read_template_file(template_path) # testing only one argument here.
144
+ "- hi mom"
145
+ end
146
+ end
147
+
148
+ Liquid::Template.file_system = infinite_file_system.new
149
+
150
+ Template.parse("{% include 'hi_mom' %}").render!
151
+ end
152
+
153
+ def test_dynamically_choosen_template
154
+ assert_template_result "Test123", "{% include template %}", "template" => 'Test123'
155
+ assert_template_result "Test321", "{% include template %}", "template" => 'Test321'
156
+
157
+ assert_template_result "Product: Draft 151cm ", "{% include template for product %}",
158
+ "template" => 'product', 'product' => { 'title' => 'Draft 151cm'}
159
+ end
160
+
161
+ def test_include_tag_caches_second_read_of_same_partial
162
+ file_system = CountingFileSystem.new
163
+ assert_equal 'from CountingFileSystemfrom CountingFileSystem',
164
+ Template.parse("{% include 'pick_a_source' %}{% include 'pick_a_source' %}").render!({}, :registers => {:file_system => file_system})
165
+ assert_equal 1, file_system.count
166
+ end
167
+
168
+ def test_include_tag_doesnt_cache_partials_across_renders
169
+ file_system = CountingFileSystem.new
170
+ assert_equal 'from CountingFileSystem',
171
+ Template.parse("{% include 'pick_a_source' %}").render!({}, :registers => {:file_system => file_system})
172
+ assert_equal 1, file_system.count
173
+
174
+ assert_equal 'from CountingFileSystem',
175
+ Template.parse("{% include 'pick_a_source' %}").render!({}, :registers => {:file_system => file_system})
176
+ assert_equal 2, file_system.count
177
+ end
178
+
179
+ def test_include_tag_within_if_statement
180
+ assert_template_result "foo_if_true", "{% if true %}{% include 'foo_if_true' %}{% endif %}"
181
+ end
182
+
183
+ def test_custom_include_tag
184
+ original_tag = Liquid::Template.tags['include']
185
+ Liquid::Template.tags['include'] = CustomInclude
186
+ begin
187
+ assert_equal "custom_foo",
188
+ Template.parse("{% include 'custom_foo' %}").render!
189
+ ensure
190
+ Liquid::Template.tags['include'] = original_tag
191
+ end
192
+ end
193
+
194
+ def test_custom_include_tag_within_if_statement
195
+ original_tag = Liquid::Template.tags['include']
196
+ Liquid::Template.tags['include'] = CustomInclude
197
+ begin
198
+ assert_equal "custom_foo_if_true",
199
+ Template.parse("{% if true %}{% include 'custom_foo_if_true' %}{% endif %}").render!
200
+ ensure
201
+ Liquid::Template.tags['include'] = original_tag
202
+ end
203
+ end
204
+
205
+ def test_does_not_add_error_in_strict_mode_for_missing_variable
206
+ Liquid::Template.file_system = TestFileSystem.new
207
+
208
+ a = Liquid::Template.parse(' {% include "nested_template" %}')
209
+ a.render!
210
+ assert_empty a.errors
211
+ end
212
+ end # IncludeTagTest
@@ -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
@@ -3,12 +3,6 @@ require 'test_helper'
3
3
  class StandardTagTest < Test::Unit::TestCase
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
@@ -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,16 +212,20 @@ class StandardTagTest < Test::Unit::TestCase
218
212
  end
219
213
 
220
214
  def test_assign
221
- assert_equal 'variable', Liquid::Template.parse( '{% assign a = "variable"%}{{a}}' ).render
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
- assert_equal '', Liquid::Template.parse( '{% assign a = ""%}{{a}}' ).render
224
+ assert_template_result '', '{% assign a = ""%}{{a}}'
226
225
  end
227
226
 
228
227
  def test_assign_is_global
229
- assert_equal 'variable',
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
@@ -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 < Test::Unit::TestCase
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