liquid 1.9.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/Manifest.txt +0 -31
  2. data/Rakefile +1 -1
  3. data/lib/extras/liquid_view.rb +15 -2
  4. data/lib/liquid.rb +15 -15
  5. data/lib/liquid/block.rb +1 -2
  6. data/lib/liquid/context.rb +89 -99
  7. data/lib/liquid/drop.rb +6 -4
  8. data/lib/liquid/errors.rb +1 -0
  9. data/lib/liquid/standardfilters.rb +56 -11
  10. data/lib/liquid/strainer.rb +1 -1
  11. data/lib/liquid/tags/assign.rb +1 -1
  12. data/lib/liquid/tags/case.rb +2 -2
  13. data/lib/liquid/tags/cycle.rb +3 -4
  14. data/lib/liquid/tags/for.rb +53 -35
  15. data/lib/liquid/tags/if.rb +3 -3
  16. data/lib/liquid/template.rb +8 -7
  17. data/lib/liquid/variable.rb +10 -11
  18. metadata +5 -35
  19. data/example/server/example_servlet.rb +0 -37
  20. data/example/server/liquid_servlet.rb +0 -28
  21. data/example/server/server.rb +0 -12
  22. data/example/server/templates/index.liquid +0 -6
  23. data/example/server/templates/products.liquid +0 -45
  24. data/test/block_test.rb +0 -58
  25. data/test/condition_test.rb +0 -109
  26. data/test/context_test.rb +0 -418
  27. data/test/drop_test.rb +0 -141
  28. data/test/error_handling_test.rb +0 -78
  29. data/test/extra/breakpoint.rb +0 -547
  30. data/test/extra/caller.rb +0 -80
  31. data/test/file_system_test.rb +0 -30
  32. data/test/filter_test.rb +0 -98
  33. data/test/helper.rb +0 -20
  34. data/test/html_tag_test.rb +0 -31
  35. data/test/if_else_test.rb +0 -127
  36. data/test/include_tag_test.rb +0 -114
  37. data/test/module_ex_test.rb +0 -89
  38. data/test/output_test.rb +0 -121
  39. data/test/parsing_quirks_test.rb +0 -29
  40. data/test/regexp_test.rb +0 -40
  41. data/test/security_test.rb +0 -41
  42. data/test/standard_filter_test.rb +0 -126
  43. data/test/standard_tag_test.rb +0 -383
  44. data/test/statements_test.rb +0 -137
  45. data/test/strainer_test.rb +0 -16
  46. data/test/template_test.rb +0 -26
  47. data/test/unless_else_test.rb +0 -27
  48. data/test/variable_test.rb +0 -135
@@ -1,383 +0,0 @@
1
- require File.dirname(__FILE__) + '/helper'
2
-
3
-
4
- class StandardTagTest < Test::Unit::TestCase
5
- include Liquid
6
-
7
-
8
- def test_tag
9
- tag = Tag.new('tag', [], [])
10
- assert_equal 'liquid::tag', tag.name
11
- assert_equal '', tag.render(Context.new)
12
- end
13
-
14
- def test_no_transform
15
- assert_template_result('this text should come out of the template without change...',
16
- 'this text should come out of the template without change...')
17
- assert_template_result('blah','blah')
18
- assert_template_result('<blah>','<blah>')
19
- assert_template_result('|,.:','|,.:')
20
- assert_template_result('','')
21
-
22
- text = %|this shouldnt see any transformation either but has multiple lines
23
- as you can clearly see here ...|
24
- assert_template_result(text,text)
25
- end
26
-
27
- def test_has_a_block_which_does_nothing
28
- assert_template_result(%|the comment block should be removed .. right?|,
29
- %|the comment block should be removed {%comment%} be gone.. {%endcomment%} .. right?|)
30
-
31
- assert_template_result('','{%comment%}{%endcomment%}')
32
- assert_template_result('','{%comment%}{% endcomment %}')
33
- assert_template_result('','{% comment %}{%endcomment%}')
34
- assert_template_result('','{% comment %}{% endcomment %}')
35
- assert_template_result('','{%comment%}comment{%endcomment%}')
36
- assert_template_result('','{% comment %}comment{% 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
- {%endcomment%}bar')
49
- end
50
-
51
- def test_for
52
- assert_template_result(' yo yo yo yo ','{%for item in array%} yo {%endfor%}','array' => [1,2,3,4])
53
- assert_template_result('yoyo','{%for item in array%}yo{%endfor%}','array' => [1,2])
54
- assert_template_result(' yo ','{%for item in array%} yo {%endfor%}','array' => [1])
55
- assert_template_result('','{%for item in array%}{%endfor%}','array' => [1,2])
56
- expected = <<HERE
57
-
58
- yo
59
-
60
- yo
61
-
62
- yo
63
-
64
- HERE
65
- template = <<HERE
66
- {%for item in array%}
67
- yo
68
- {%endfor%}
69
- HERE
70
- assert_template_result(expected,template,'array' => [1,2,3])
71
- end
72
-
73
- def test_for_with_range
74
- assert_template_result(' 1 2 3 ','{%for item in (1..3) %} {{item}} {%endfor%}')
75
- end
76
-
77
- def test_for_with_variable
78
- assert_template_result(' 1 2 3 ','{%for item in array%} {{item}} {%endfor%}','array' => [1,2,3])
79
- assert_template_result('123','{%for item in array%}{{item}}{%endfor%}','array' => [1,2,3])
80
- assert_template_result('123','{% for item in array %}{{item}}{% endfor %}','array' => [1,2,3])
81
- assert_template_result('abcd','{%for item in array%}{{item}}{%endfor%}','array' => ['a','b','c','d'])
82
- assert_template_result('a b c','{%for item in array%}{{item}}{%endfor%}','array' => ['a',' ','b',' ','c'])
83
- assert_template_result('abc','{%for item in array%}{{item}}{%endfor%}','array' => ['a','','b','','c'])
84
- end
85
-
86
- def test_for_helpers
87
- assigns = {'array' => [1,2,3] }
88
- assert_template_result(' 1/3 2/3 3/3 ','{%for item in array%} {{forloop.index}}/{{forloop.length}} {%endfor%}',assigns)
89
- assert_template_result(' 1 2 3 ','{%for item in array%} {{forloop.index}} {%endfor%}',assigns)
90
- assert_template_result(' 0 1 2 ','{%for item in array%} {{forloop.index0}} {%endfor%}',assigns)
91
- assert_template_result(' 2 1 0 ','{%for item in array%} {{forloop.rindex0}} {%endfor%}',assigns)
92
- assert_template_result(' 3 2 1 ','{%for item in array%} {{forloop.rindex}} {%endfor%}',assigns)
93
- assert_template_result(' true false false ','{%for item in array%} {{forloop.first}} {%endfor%}',assigns)
94
- assert_template_result(' false false true ','{%for item in array%} {{forloop.last}} {%endfor%}',assigns)
95
- end
96
-
97
- def test_for_and_if
98
- assigns = {'array' => [1,2,3] }
99
- assert_template_result('+--', '{%for item in array%}{% if forloop.first %}+{% else %}-{% endif %}{%endfor%}', assigns)
100
- end
101
-
102
- def test_limiting
103
- assigns = {'array' => [1,2,3,4,5,6,7,8,9,0]}
104
- assert_template_result('12','{%for i in array limit:2 %}{{ i }}{%endfor%}',assigns)
105
- assert_template_result('1234','{%for i in array limit:4 %}{{ i }}{%endfor%}',assigns)
106
- assert_template_result('3456','{%for i in array limit:4 offset:2 %}{{ i }}{%endfor%}',assigns)
107
- assert_template_result('3456','{%for i in array limit: 4 offset: 2 %}{{ i }}{%endfor%}',assigns)
108
-
109
- assigns['limit'] = 2
110
- assigns['offset'] = 2
111
- assert_template_result('34','{%for i in array limit: limit offset: offset %}{{ i }}{%endfor%}',assigns)
112
- end
113
-
114
- def test_nested_for
115
- assigns = {'array' => [[1,2],[3,4],[5,6]] }
116
- assert_template_result('123456','{%for item in array%}{%for i in item%}{{ i }}{%endfor%}{%endfor%}',assigns)
117
- end
118
-
119
- def test_offset_only
120
- assigns = {'array' => [1,2,3,4,5,6,7,8,9,0]}
121
- assert_template_result('890','{%for i in array offset:7 %}{{ i }}{%endfor%}',assigns)
122
- end
123
-
124
- def test_pause_resume
125
- assigns = {'array' => {'items' => [1,2,3,4,5,6,7,8,9,0]}}
126
- markup = <<-MKUP
127
- {%for i in array.items limit: 3 %}{{i}}{%endfor%}
128
- next
129
- {%for i in array.items offset:continue limit: 3 %}{{i}}{%endfor%}
130
- next
131
- {%for i in array.items offset:continue limit: 3 %}{{i}}{%endfor%}
132
- MKUP
133
- expected = <<-XPCTD
134
- 123
135
- next
136
- 456
137
- next
138
- 789
139
- XPCTD
140
- assert_template_result(expected,markup,assigns)
141
- end
142
-
143
- def test_pause_resume_limit
144
- assigns = {'array' => {'items' => [1,2,3,4,5,6,7,8,9,0]}}
145
- markup = <<-MKUP
146
- {%for i in array.items limit:3 %}{{i}}{%endfor%}
147
- next
148
- {%for i in array.items offset:continue limit:3 %}{{i}}{%endfor%}
149
- next
150
- {%for i in array.items offset:continue limit:1 %}{{i}}{%endfor%}
151
- MKUP
152
- expected = <<-XPCTD
153
- 123
154
- next
155
- 456
156
- next
157
- 7
158
- XPCTD
159
- assert_template_result(expected,markup,assigns)
160
- end
161
-
162
- def test_pause_resume_BIG_limit
163
- assigns = {'array' => {'items' => [1,2,3,4,5,6,7,8,9,0]}}
164
- markup = <<-MKUP
165
- {%for i in array.items limit:3 %}{{i}}{%endfor%}
166
- next
167
- {%for i in array.items offset:continue limit:3 %}{{i}}{%endfor%}
168
- next
169
- {%for i in array.items offset:continue limit:1000 %}{{i}}{%endfor%}
170
- MKUP
171
- expected = <<-XPCTD
172
- 123
173
- next
174
- 456
175
- next
176
- 7890
177
- XPCTD
178
- assert_template_result(expected,markup,assigns)
179
- end
180
-
181
-
182
- def test_pause_resume_BIG_offset
183
- assigns = {'array' => {'items' => [1,2,3,4,5,6,7,8,9,0]}}
184
- markup = %q({%for i in array.items limit:3 %}{{i}}{%endfor%}
185
- next
186
- {%for i in array.items offset:continue limit:3 %}{{i}}{%endfor%}
187
- next
188
- {%for i in array.items offset:continue limit:3 offset:1000 %}{{i}}{%endfor%})
189
- expected = %q(123
190
- next
191
- 456
192
- next
193
- )
194
- assert_template_result(expected,markup,assigns)
195
- end
196
-
197
- def test_assign
198
- assigns = {'var' => 'content' }
199
- assert_template_result('var2: var2:content','var2:{{var2}} {%assign var2 = var%} var2:{{var2}}',assigns)
200
-
201
- end
202
-
203
- def test_hyphenated_assign
204
- assigns = {'a-b' => '1' }
205
- assert_template_result('a-b:1 a-b:2','a-b:{{a-b}} {%assign a-b = 2 %}a-b:{{a-b}}',assigns)
206
-
207
- end
208
-
209
- def test_capture
210
- assigns = {'var' => 'content' }
211
- assert_template_result('content foo content foo ','{{ var2 }}{% capture var2 %}{{ var }} foo {% endcapture %}{{ var2 }}{{ var2 }}', assigns)
212
- end
213
-
214
- def test_capture_detects_bad_syntax
215
- assert_raise(SyntaxError) do
216
- assert_template_result('content foo content foo ','{{ var2 }}{% capture %}{{ var }} foo {% endcapture %}{{ var2 }}{{ var2 }}', {'var' => 'content' })
217
- end
218
- end
219
-
220
- def test_case
221
- assigns = {'condition' => 2 }
222
- assert_template_result(' its 2 ','{% case condition %}{% when 1 %} its 1 {% when 2 %} its 2 {% endcase %}', assigns)
223
-
224
- assigns = {'condition' => 1 }
225
- assert_template_result(' its 1 ','{% case condition %}{% when 1 %} its 1 {% when 2 %} its 2 {% endcase %}', assigns)
226
-
227
- assigns = {'condition' => 3 }
228
- assert_template_result('','{% case condition %}{% when 1 %} its 1 {% when 2 %} its 2 {% endcase %}', assigns)
229
-
230
- assigns = {'condition' => "string here" }
231
- assert_template_result(' hit ','{% case condition %}{% when "string here" %} hit {% endcase %}', assigns)
232
-
233
- assigns = {'condition' => "bad string here" }
234
- assert_template_result('','{% case condition %}{% when "string here" %} hit {% endcase %}', assigns)
235
- end
236
-
237
- def test_case_with_else
238
-
239
- assigns = {'condition' => 5 }
240
- assert_template_result(' hit ','{% case condition %}{% when 5 %} hit {% else %} else {% endcase %}', assigns)
241
-
242
- assigns = {'condition' => 6 }
243
- assert_template_result(' else ','{% case condition %}{% when 5 %} hit {% else %} else {% endcase %}', assigns)
244
-
245
- assigns = {'condition' => 6 }
246
- assert_template_result(' else ','{% case condition %} {% when 5 %} hit {% else %} else {% endcase %}', assigns)
247
-
248
-
249
- end
250
-
251
- def test_case_on_size
252
- assert_template_result('', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', 'a' => [])
253
- assert_template_result('1' , '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', 'a' => [1])
254
- assert_template_result('2' , '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', 'a' => [1, 1])
255
- assert_template_result('', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', 'a' => [1, 1, 1])
256
- assert_template_result('', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', 'a' => [1, 1, 1, 1])
257
- assert_template_result('', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', 'a' => [1, 1, 1, 1, 1])
258
- end
259
-
260
- def test_case_on_size_with_else
261
- assert_template_result('else', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}', 'a' => [])
262
- assert_template_result('1', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}', 'a' => [1])
263
- assert_template_result('2', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}', 'a' => [1, 1])
264
- assert_template_result('else', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}', 'a' => [1, 1, 1])
265
- assert_template_result('else', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}', 'a' => [1, 1, 1, 1])
266
- assert_template_result('else', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}', 'a' => [1, 1, 1, 1, 1])
267
- end
268
-
269
- def test_case_on_length_with_else
270
- assert_template_result('else', '{% case a.empty? %}{% when true %}true{% when false %}false{% else %}else{% endcase %}', {})
271
- assert_template_result('false', '{% case false %}{% when true %}true{% when false %}false{% else %}else{% endcase %}', {})
272
- assert_template_result('true', '{% case true %}{% when true %}true{% when false %}false{% else %}else{% endcase %}', {})
273
- assert_template_result('else', '{% case NULL %}{% when true %}true{% when false %}false{% else %}else{% endcase %}', {})
274
- end
275
-
276
- def test_assign_from_case
277
- # Example from the shopify forums
278
- code = %q({% case collection.handle %}{% when 'menswear-jackets' %}{% assign ptitle = 'menswear' %}{% when 'menswear-t-shirts' %}{% assign ptitle = 'menswear' %}{% else %}{% assign ptitle = 'womenswear' %}{% endcase %}{{ ptitle }})
279
- template = Liquid::Template.parse(code)
280
- assert_equal "menswear", template.render("collection" => {'handle' => 'menswear-jackets'})
281
- assert_equal "menswear", template.render("collection" => {'handle' => 'menswear-t-shirts'})
282
- assert_equal "womenswear", template.render("collection" => {'handle' => 'x'})
283
- assert_equal "womenswear", template.render("collection" => {'handle' => 'y'})
284
- assert_equal "womenswear", template.render("collection" => {'handle' => 'z'})
285
- end
286
-
287
- def test_case_when_or
288
- code = '{% case condition %}{% when 1 or 2 or 3 %} its 1 or 2 or 3 {% when 4 %} its 4 {% endcase %}'
289
- assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 1 })
290
- assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 2 })
291
- assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 3 })
292
- assert_template_result(' its 4 ', code, {'condition' => 4 })
293
- assert_template_result('', code, {'condition' => 5 })
294
-
295
- code = '{% case condition %}{% when 1 or "string" or null %} its 1 or 2 or 3 {% when 4 %} its 4 {% endcase %}'
296
- assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 1 })
297
- assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 'string' })
298
- assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => nil })
299
- assert_template_result('', code, {'condition' => 'something else' })
300
- end
301
-
302
- def test_case_when_comma
303
- code = '{% case condition %}{% when 1, 2, 3 %} its 1 or 2 or 3 {% when 4 %} its 4 {% endcase %}'
304
- assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 1 })
305
- assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 2 })
306
- assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 3 })
307
- assert_template_result(' its 4 ', code, {'condition' => 4 })
308
- assert_template_result('', code, {'condition' => 5 })
309
-
310
- code = '{% case condition %}{% when 1, "string", null %} its 1 or 2 or 3 {% when 4 %} its 4 {% endcase %}'
311
- assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 1 })
312
- assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 'string' })
313
- assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => nil })
314
- assert_template_result('', code, {'condition' => 'something else' })
315
- end
316
-
317
- def test_assign
318
- assert_equal 'variable', Liquid::Template.parse( '{% assign a = "variable"%}{{a}}' ).render
319
- end
320
-
321
- def test_assign_is_global
322
- assert_equal 'variable', Liquid::Template.parse( '{%for i in (1..2) %}{% assign a = "variable"%}{% endfor %}{{a}}' ).render
323
- end
324
-
325
- def test_case_detects_bad_syntax
326
- assert_raise(SyntaxError) do
327
- assert_template_result('', '{% case false %}{% when %}true{% endcase %}', {})
328
- end
329
-
330
- assert_raise(SyntaxError) do
331
- assert_template_result('', '{% case false %}{% huh %}true{% endcase %}', {})
332
- end
333
-
334
- end
335
-
336
-
337
-
338
- def test_cycle
339
-
340
- assert_template_result('one','{%cycle "one", "two"%}')
341
- assert_template_result('one two','{%cycle "one", "two"%} {%cycle "one", "two"%}')
342
-
343
- assert_template_result('one two one','{%cycle "one", "two"%} {%cycle "one", "two"%} {%cycle "one", "two"%}')
344
- end
345
-
346
- def test_multiple_cycles
347
- assert_template_result('1 2 1 1 2 3 1','{%cycle 1,2%} {%cycle 1,2%} {%cycle 1,2%} {%cycle 1,2,3%} {%cycle 1,2,3%} {%cycle 1,2,3%} {%cycle 1,2,3%}')
348
- end
349
-
350
- def test_multiple_named_cycles
351
- assert_template_result('one one two two one one','{%cycle 1: "one", "two" %} {%cycle 2: "one", "two" %} {%cycle 1: "one", "two" %} {%cycle 2: "one", "two" %} {%cycle 1: "one", "two" %} {%cycle 2: "one", "two" %}')
352
- end
353
-
354
- def test_multiple_named_cycles_with_names_from_context
355
- assigns = {"var1" => 1, "var2" => 2 }
356
- assert_template_result('one one two two one one','{%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)
357
- end
358
-
359
- def test_size_of_array
360
- assigns = {"array" => [1,2,3,4]}
361
- assert_template_result('array has 4 elements', "array has {{ array.size }} elements", assigns)
362
- end
363
-
364
- def test_size_of_hash
365
- assigns = {"hash" => {:a => 1, :b => 2, :c=> 3, :d => 4}}
366
- assert_template_result('hash has 4 elements', "hash has {{ hash.size }} elements", assigns)
367
- end
368
-
369
- def test_illegal_symbols
370
- assert_template_result('', '{% if true == empty %}?{% endif %}', {})
371
- assert_template_result('', '{% if true == null %}?{% endif %}', {})
372
- assert_template_result('', '{% if empty == true %}?{% endif %}', {})
373
- assert_template_result('', '{% if null == true %}?{% endif %}', {})
374
- end
375
-
376
- def test_ifchanged
377
- assigns = {'array' => [ 1, 1, 2, 2, 3, 3] }
378
- assert_template_result('123','{%for item in array%}{%ifchanged%}{{item}}{% endifchanged %}{%endfor%}',assigns)
379
-
380
- assigns = {'array' => [ 1, 1, 1, 1] }
381
- assert_template_result('1','{%for item in array%}{%ifchanged%}{{item}}{% endifchanged %}{%endfor%}',assigns)
382
- end
383
- end
@@ -1,137 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require File.dirname(__FILE__) + '/helper'
3
-
4
- class StatementsTest < Test::Unit::TestCase
5
- include Liquid
6
-
7
-
8
- def test_true_eql_true
9
- text = %| {% if true == true %} true {% else %} false {% endif %} |
10
- expected = %| true |
11
- assert_equal expected, Template.parse(text).render
12
- end
13
-
14
- def test_true_not_eql_true
15
- text = %| {% if true != true %} true {% else %} false {% endif %} |
16
- expected = %| false |
17
- assert_equal expected, Template.parse(text).render
18
- end
19
-
20
- def test_true_lq_true
21
- text = %| {% if 0 > 0 %} true {% else %} false {% endif %} |
22
- expected = %| false |
23
- assert_equal expected, Template.parse(text).render
24
- end
25
-
26
- def test_one_lq_zero
27
- text = %| {% if 1 > 0 %} true {% else %} false {% endif %} |
28
- expected = %| true |
29
- assert_equal expected, Template.parse(text).render
30
- end
31
-
32
- def test_zero_lq_one
33
- text = %| {% if 0 < 1 %} true {% else %} false {% endif %} |
34
- expected = %| true |
35
- assert_equal expected, Template.parse(text).render
36
- end
37
-
38
- def test_zero_lq_or_equal_one
39
- text = %| {% if 0 <= 0 %} true {% else %} false {% endif %} |
40
- expected = %| true |
41
- assert_equal expected, Template.parse(text).render
42
- end
43
-
44
- def test_zero_lq_or_equal_one_involving_nil
45
- text = %| {% if null <= 0 %} true {% else %} false {% endif %} |
46
- expected = %| false |
47
- assert_equal expected, Template.parse(text).render
48
-
49
-
50
- text = %| {% if 0 <= null %} true {% else %} false {% endif %} |
51
- expected = %| false |
52
- assert_equal expected, Template.parse(text).render
53
- end
54
-
55
- def test_zero_lqq_or_equal_one
56
- text = %| {% if 0 >= 0 %} true {% else %} false {% endif %} |
57
- expected = %| true |
58
- assert_equal expected, Template.parse(text).render
59
- end
60
-
61
- def test_strings
62
- text = %| {% if 'test' == 'test' %} true {% else %} false {% endif %} |
63
- expected = %| true |
64
- assert_equal expected, Template.parse(text).render
65
- end
66
-
67
- def test_strings_not_equal
68
- text = %| {% if 'test' != 'test' %} true {% else %} false {% endif %} |
69
- expected = %| false |
70
- assert_equal expected, Template.parse(text).render
71
- end
72
-
73
- def test_var_strings_equal
74
- text = %| {% if var == "hello there!" %} true {% else %} false {% endif %} |
75
- expected = %| true |
76
- assert_equal expected, Template.parse(text).render('var' => 'hello there!')
77
- end
78
-
79
- def test_var_strings_are_not_equal
80
- text = %| {% if "hello there!" == var %} true {% else %} false {% endif %} |
81
- expected = %| true |
82
- assert_equal expected, Template.parse(text).render('var' => 'hello there!')
83
- end
84
-
85
- def test_var_and_long_string_are_equal
86
- text = %| {% if var == 'hello there!' %} true {% else %} false {% endif %} |
87
- expected = %| true |
88
- assert_equal expected, Template.parse(text).render('var' => 'hello there!')
89
- end
90
-
91
-
92
- def test_var_and_long_string_are_equal_backwards
93
- text = %| {% if 'hello there!' == var %} true {% else %} false {% endif %} |
94
- expected = %| true |
95
- assert_equal expected, Template.parse(text).render('var' => 'hello there!')
96
- end
97
-
98
- #def test_is_nil
99
- # text = %| {% if var != nil %} true {% else %} false {% end %} |
100
- # @template.assigns = { 'var' => 'hello there!'}
101
- # expected = %| true |
102
- # assert_equal expected, @template.parse(text)
103
- #end
104
-
105
- def test_is_collection_empty
106
- text = %| {% if array == empty %} true {% else %} false {% endif %} |
107
- expected = %| true |
108
- assert_equal expected, Template.parse(text).render('array' => [])
109
- end
110
-
111
- def test_is_not_collection_empty
112
- text = %| {% if array == empty %} true {% else %} false {% endif %} |
113
- expected = %| false |
114
- assert_equal expected, Template.parse(text).render('array' => [1,2,3])
115
- end
116
-
117
- def test_nil
118
- text = %| {% if var == nil %} true {% else %} false {% endif %} |
119
- expected = %| true |
120
- assert_equal expected, Template.parse(text).render('var' => nil)
121
-
122
- text = %| {% if var == null %} true {% else %} false {% endif %} |
123
- expected = %| true |
124
- assert_equal expected, Template.parse(text).render('var' => nil)
125
- end
126
-
127
- def test_not_nil
128
- text = %| {% if var != nil %} true {% else %} false {% endif %} |
129
- expected = %| true |
130
- assert_equal expected, Template.parse(text).render('var' => 1 )
131
-
132
- text = %| {% if var != null %} true {% else %} false {% endif %} |
133
- expected = %| true |
134
- assert_equal expected, Template.parse(text).render('var' => 1 )
135
- end
136
-
137
- end