spinto-liquid 2.3.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.md +56 -0
- data/MIT-LICENSE +20 -0
- data/README.md +44 -0
- data/lib/extras/liquid_view.rb +51 -0
- data/lib/liquid/block.rb +101 -0
- data/lib/liquid/condition.rb +120 -0
- data/lib/liquid/context.rb +245 -0
- data/lib/liquid/document.rb +17 -0
- data/lib/liquid/drop.rb +49 -0
- data/lib/liquid/errors.rb +11 -0
- data/lib/liquid/extensions.rb +62 -0
- data/lib/liquid/file_system.rb +62 -0
- data/lib/liquid/htmltags.rb +75 -0
- data/lib/liquid/module_ex.rb +62 -0
- data/lib/liquid/standardfilters.rb +241 -0
- data/lib/liquid/strainer.rb +54 -0
- data/lib/liquid/tag.rb +26 -0
- data/lib/liquid/tags/assign.rb +33 -0
- data/lib/liquid/tags/capture.rb +35 -0
- data/lib/liquid/tags/case.rb +79 -0
- data/lib/liquid/tags/comment.rb +9 -0
- data/lib/liquid/tags/cycle.rb +59 -0
- data/lib/liquid/tags/decrement.rb +39 -0
- data/lib/liquid/tags/for.rb +190 -0
- data/lib/liquid/tags/if.rb +79 -0
- data/lib/liquid/tags/ifchanged.rb +20 -0
- data/lib/liquid/tags/include.rb +65 -0
- data/lib/liquid/tags/increment.rb +35 -0
- data/lib/liquid/tags/raw.rb +21 -0
- data/lib/liquid/tags/unless.rb +33 -0
- data/lib/liquid/template.rb +150 -0
- data/lib/liquid/variable.rb +50 -0
- data/lib/liquid.rb +66 -0
- data/test/liquid/assign_test.rb +21 -0
- data/test/liquid/block_test.rb +58 -0
- data/test/liquid/capture_test.rb +40 -0
- data/test/liquid/condition_test.rb +127 -0
- data/test/liquid/context_test.rb +478 -0
- data/test/liquid/drop_test.rb +162 -0
- data/test/liquid/error_handling_test.rb +81 -0
- data/test/liquid/file_system_test.rb +29 -0
- data/test/liquid/filter_test.rb +106 -0
- data/test/liquid/module_ex_test.rb +87 -0
- data/test/liquid/output_test.rb +116 -0
- data/test/liquid/parsing_quirks_test.rb +52 -0
- data/test/liquid/regexp_test.rb +44 -0
- data/test/liquid/security_test.rb +41 -0
- data/test/liquid/standard_filter_test.rb +195 -0
- data/test/liquid/strainer_test.rb +25 -0
- data/test/liquid/tags/for_tag_test.rb +215 -0
- data/test/liquid/tags/html_tag_test.rb +39 -0
- data/test/liquid/tags/if_else_tag_test.rb +160 -0
- data/test/liquid/tags/include_tag_test.rb +139 -0
- data/test/liquid/tags/increment_tag_test.rb +24 -0
- data/test/liquid/tags/raw_tag_test.rb +15 -0
- data/test/liquid/tags/standard_tag_test.rb +295 -0
- data/test/liquid/tags/statements_test.rb +134 -0
- data/test/liquid/tags/unless_else_tag_test.rb +26 -0
- data/test/liquid/template_test.rb +74 -0
- data/test/liquid/variable_test.rb +170 -0
- data/test/test_helper.rb +29 -0
- metadata +136 -0
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class IncrementTagTest < Test::Unit::TestCase
|
4
|
+
include Liquid
|
5
|
+
|
6
|
+
def test_inc
|
7
|
+
assert_template_result('0','{%increment port %}', {})
|
8
|
+
assert_template_result('0 1','{%increment port %} {%increment port%}', {})
|
9
|
+
assert_template_result('0 0 1 2 1',
|
10
|
+
'{%increment port %} {%increment starboard%} ' +
|
11
|
+
'{%increment port %} {%increment port%} ' +
|
12
|
+
'{%increment starboard %}', {})
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_dec
|
16
|
+
assert_template_result('9','{%decrement port %}', { 'port' => 10})
|
17
|
+
assert_template_result('-1 -2','{%decrement port %} {%decrement port%}', {})
|
18
|
+
assert_template_result('1 5 2 2 5',
|
19
|
+
'{%increment port %} {%increment starboard%} ' +
|
20
|
+
'{%increment port %} {%decrement port%} ' +
|
21
|
+
'{%decrement starboard %}', { 'port' => 1, 'starboard' => 5 })
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class RawTagTest < Test::Unit::TestCase
|
4
|
+
include Liquid
|
5
|
+
|
6
|
+
def test_tag_in_raw
|
7
|
+
assert_template_result '{% comment %} test {% endcomment %}',
|
8
|
+
'{% raw %}{% comment %} test {% endcomment %}{% endraw %}'
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_output_in_raw
|
12
|
+
assert_template_result '{{ test }}',
|
13
|
+
'{% raw %}{{ test }}{% endraw %}'
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,295 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class StandardTagTest < Test::Unit::TestCase
|
4
|
+
include Liquid
|
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
|
+
def test_no_transform
|
13
|
+
assert_template_result('this text should come out of the template without change...',
|
14
|
+
'this text should come out of the template without change...')
|
15
|
+
|
16
|
+
assert_template_result('blah','blah')
|
17
|
+
assert_template_result('<blah>','<blah>')
|
18
|
+
assert_template_result('|,.:','|,.:')
|
19
|
+
assert_template_result('','')
|
20
|
+
|
21
|
+
text = %|this shouldnt see any transformation either but has multiple lines
|
22
|
+
as you can clearly see here ...|
|
23
|
+
assert_template_result(text,text)
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_has_a_block_which_does_nothing
|
27
|
+
assert_template_result(%|the comment block should be removed .. right?|,
|
28
|
+
%|the comment block should be removed {%comment%} be gone.. {%endcomment%} .. right?|)
|
29
|
+
|
30
|
+
assert_template_result('','{%comment%}{%endcomment%}')
|
31
|
+
assert_template_result('','{%comment%}{% endcomment %}')
|
32
|
+
assert_template_result('','{% comment %}{%endcomment%}')
|
33
|
+
assert_template_result('','{% comment %}{% endcomment %}')
|
34
|
+
assert_template_result('','{%comment%}comment{%endcomment%}')
|
35
|
+
assert_template_result('','{% comment %}comment{% endcomment %}')
|
36
|
+
|
37
|
+
assert_template_result('foobar','foo{%comment%}comment{%endcomment%}bar')
|
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
|
+
|
42
|
+
assert_template_result('foo bar','foo {%comment%} {%endcomment%} bar')
|
43
|
+
assert_template_result('foo bar','foo {%comment%}comment{%endcomment%} bar')
|
44
|
+
assert_template_result('foo bar','foo {%comment%} comment {%endcomment%} bar')
|
45
|
+
|
46
|
+
assert_template_result('foobar','foo{%comment%}
|
47
|
+
{%endcomment%}bar')
|
48
|
+
end
|
49
|
+
|
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
|
+
def test_hyphenated_assign
|
57
|
+
assigns = {'a-b' => '1' }
|
58
|
+
assert_template_result('a-b:1 a-b:2', 'a-b:{{a-b}} {%assign a-b = 2 %}a-b:{{a-b}}', assigns)
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_assign_with_colon_and_spaces
|
63
|
+
assigns = {'var' => {'a:b c' => {'paged' => '1' }}}
|
64
|
+
assert_template_result('var2: 1', '{%assign var2 = var["a:b c"].paged %}var2: {{var2}}', assigns)
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_capture
|
68
|
+
assigns = {'var' => 'content' }
|
69
|
+
assert_template_result('content foo content foo ',
|
70
|
+
'{{ var2 }}{% capture var2 %}{{ var }} foo {% endcapture %}{{ var2 }}{{ var2 }}',
|
71
|
+
assigns)
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_capture_detects_bad_syntax
|
75
|
+
assert_raise(SyntaxError) do
|
76
|
+
assert_template_result('content foo content foo ',
|
77
|
+
'{{ var2 }}{% capture %}{{ var }} foo {% endcapture %}{{ var2 }}{{ var2 }}',
|
78
|
+
{'var' => 'content' })
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_case
|
83
|
+
assigns = {'condition' => 2 }
|
84
|
+
assert_template_result(' its 2 ',
|
85
|
+
'{% case condition %}{% when 1 %} its 1 {% when 2 %} its 2 {% endcase %}',
|
86
|
+
assigns)
|
87
|
+
|
88
|
+
assigns = {'condition' => 1 }
|
89
|
+
assert_template_result(' its 1 ',
|
90
|
+
'{% case condition %}{% when 1 %} its 1 {% when 2 %} its 2 {% endcase %}',
|
91
|
+
assigns)
|
92
|
+
|
93
|
+
assigns = {'condition' => 3 }
|
94
|
+
assert_template_result('',
|
95
|
+
'{% case condition %}{% when 1 %} its 1 {% when 2 %} its 2 {% endcase %}',
|
96
|
+
assigns)
|
97
|
+
|
98
|
+
assigns = {'condition' => "string here" }
|
99
|
+
assert_template_result(' hit ',
|
100
|
+
'{% case condition %}{% when "string here" %} hit {% endcase %}',
|
101
|
+
assigns)
|
102
|
+
|
103
|
+
assigns = {'condition' => "bad string here" }
|
104
|
+
assert_template_result('',
|
105
|
+
'{% case condition %}{% when "string here" %} hit {% endcase %}',\
|
106
|
+
assigns)
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_case_with_else
|
110
|
+
assigns = {'condition' => 5 }
|
111
|
+
assert_template_result(' hit ',
|
112
|
+
'{% case condition %}{% when 5 %} hit {% else %} else {% endcase %}',
|
113
|
+
assigns)
|
114
|
+
|
115
|
+
assigns = {'condition' => 6 }
|
116
|
+
assert_template_result(' else ',
|
117
|
+
'{% case condition %}{% when 5 %} hit {% else %} else {% endcase %}',
|
118
|
+
assigns)
|
119
|
+
|
120
|
+
assigns = {'condition' => 6 }
|
121
|
+
assert_template_result(' else ',
|
122
|
+
'{% case condition %} {% when 5 %} hit {% else %} else {% endcase %}',
|
123
|
+
assigns)
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_case_on_size
|
127
|
+
assert_template_result('', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', 'a' => [])
|
128
|
+
assert_template_result('1', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', 'a' => [1])
|
129
|
+
assert_template_result('2', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', 'a' => [1, 1])
|
130
|
+
assert_template_result('', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', 'a' => [1, 1, 1])
|
131
|
+
assert_template_result('', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', 'a' => [1, 1, 1, 1])
|
132
|
+
assert_template_result('', '{% case a.size %}{% when 1 %}1{% when 2 %}2{% endcase %}', 'a' => [1, 1, 1, 1, 1])
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_case_on_size_with_else
|
136
|
+
assert_template_result('else',
|
137
|
+
'{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}',
|
138
|
+
'a' => [])
|
139
|
+
|
140
|
+
assert_template_result('1',
|
141
|
+
'{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}',
|
142
|
+
'a' => [1])
|
143
|
+
|
144
|
+
assert_template_result('2',
|
145
|
+
'{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}',
|
146
|
+
'a' => [1, 1])
|
147
|
+
|
148
|
+
assert_template_result('else',
|
149
|
+
'{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}',
|
150
|
+
'a' => [1, 1, 1])
|
151
|
+
|
152
|
+
assert_template_result('else',
|
153
|
+
'{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}',
|
154
|
+
'a' => [1, 1, 1, 1])
|
155
|
+
|
156
|
+
assert_template_result('else',
|
157
|
+
'{% case a.size %}{% when 1 %}1{% when 2 %}2{% else %}else{% endcase %}',
|
158
|
+
'a' => [1, 1, 1, 1, 1])
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_case_on_length_with_else
|
162
|
+
assert_template_result('else',
|
163
|
+
'{% case a.empty? %}{% when true %}true{% when false %}false{% else %}else{% endcase %}',
|
164
|
+
{})
|
165
|
+
|
166
|
+
assert_template_result('false',
|
167
|
+
'{% case false %}{% when true %}true{% when false %}false{% else %}else{% endcase %}',
|
168
|
+
{})
|
169
|
+
|
170
|
+
assert_template_result('true',
|
171
|
+
'{% case true %}{% when true %}true{% when false %}false{% else %}else{% endcase %}',
|
172
|
+
{})
|
173
|
+
|
174
|
+
assert_template_result('else',
|
175
|
+
'{% case NULL %}{% when true %}true{% when false %}false{% else %}else{% endcase %}',
|
176
|
+
{})
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_assign_from_case
|
180
|
+
# Example from the shopify forums
|
181
|
+
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
|
+
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'})
|
188
|
+
end
|
189
|
+
|
190
|
+
def test_case_when_or
|
191
|
+
code = '{% case condition %}{% when 1 or 2 or 3 %} its 1 or 2 or 3 {% when 4 %} its 4 {% endcase %}'
|
192
|
+
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 1 })
|
193
|
+
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 2 })
|
194
|
+
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 3 })
|
195
|
+
assert_template_result(' its 4 ', code, {'condition' => 4 })
|
196
|
+
assert_template_result('', code, {'condition' => 5 })
|
197
|
+
|
198
|
+
code = '{% case condition %}{% when 1 or "string" or null %} its 1 or 2 or 3 {% when 4 %} its 4 {% endcase %}'
|
199
|
+
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 1 })
|
200
|
+
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 'string' })
|
201
|
+
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => nil })
|
202
|
+
assert_template_result('', code, {'condition' => 'something else' })
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_case_when_comma
|
206
|
+
code = '{% case condition %}{% when 1, 2, 3 %} its 1 or 2 or 3 {% when 4 %} its 4 {% endcase %}'
|
207
|
+
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 1 })
|
208
|
+
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 2 })
|
209
|
+
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 3 })
|
210
|
+
assert_template_result(' its 4 ', code, {'condition' => 4 })
|
211
|
+
assert_template_result('', code, {'condition' => 5 })
|
212
|
+
|
213
|
+
code = '{% case condition %}{% when 1, "string", null %} its 1 or 2 or 3 {% when 4 %} its 4 {% endcase %}'
|
214
|
+
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 1 })
|
215
|
+
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => 'string' })
|
216
|
+
assert_template_result(' its 1 or 2 or 3 ', code, {'condition' => nil })
|
217
|
+
assert_template_result('', code, {'condition' => 'something else' })
|
218
|
+
end
|
219
|
+
|
220
|
+
def test_assign
|
221
|
+
assert_equal 'variable', Liquid::Template.parse( '{% assign a = "variable"%}{{a}}' ).render
|
222
|
+
end
|
223
|
+
|
224
|
+
def test_assign_an_empty_string
|
225
|
+
assert_equal '', Liquid::Template.parse( '{% assign a = ""%}{{a}}' ).render
|
226
|
+
end
|
227
|
+
|
228
|
+
def test_assign_is_global
|
229
|
+
assert_equal 'variable',
|
230
|
+
Liquid::Template.parse( '{%for i in (1..2) %}{% assign a = "variable"%}{% endfor %}{{a}}' ).render
|
231
|
+
end
|
232
|
+
|
233
|
+
def test_case_detects_bad_syntax
|
234
|
+
assert_raise(SyntaxError) do
|
235
|
+
assert_template_result('', '{% case false %}{% when %}true{% endcase %}', {})
|
236
|
+
end
|
237
|
+
|
238
|
+
assert_raise(SyntaxError) do
|
239
|
+
assert_template_result('', '{% case false %}{% huh %}true{% endcase %}', {})
|
240
|
+
end
|
241
|
+
|
242
|
+
end
|
243
|
+
|
244
|
+
def test_cycle
|
245
|
+
assert_template_result('one','{%cycle "one", "two"%}')
|
246
|
+
assert_template_result('one two','{%cycle "one", "two"%} {%cycle "one", "two"%}')
|
247
|
+
assert_template_result(' two','{%cycle "", "two"%} {%cycle "", "two"%}')
|
248
|
+
|
249
|
+
assert_template_result('one two one','{%cycle "one", "two"%} {%cycle "one", "two"%} {%cycle "one", "two"%}')
|
250
|
+
|
251
|
+
assert_template_result('text-align: left text-align: right',
|
252
|
+
'{%cycle "text-align: left", "text-align: right" %} {%cycle "text-align: left", "text-align: right"%}')
|
253
|
+
end
|
254
|
+
|
255
|
+
def test_multiple_cycles
|
256
|
+
assert_template_result('1 2 1 1 2 3 1',
|
257
|
+
'{%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%}')
|
258
|
+
end
|
259
|
+
|
260
|
+
def test_multiple_named_cycles
|
261
|
+
assert_template_result('one one two two one one',
|
262
|
+
'{%cycle 1: "one", "two" %} {%cycle 2: "one", "two" %} {%cycle 1: "one", "two" %} {%cycle 2: "one", "two" %} {%cycle 1: "one", "two" %} {%cycle 2: "one", "two" %}')
|
263
|
+
end
|
264
|
+
|
265
|
+
def test_multiple_named_cycles_with_names_from_context
|
266
|
+
assigns = {"var1" => 1, "var2" => 2 }
|
267
|
+
assert_template_result('one one two two one one',
|
268
|
+
'{%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)
|
269
|
+
end
|
270
|
+
|
271
|
+
def test_size_of_array
|
272
|
+
assigns = {"array" => [1,2,3,4]}
|
273
|
+
assert_template_result('array has 4 elements', "array has {{ array.size }} elements", assigns)
|
274
|
+
end
|
275
|
+
|
276
|
+
def test_size_of_hash
|
277
|
+
assigns = {"hash" => {:a => 1, :b => 2, :c=> 3, :d => 4}}
|
278
|
+
assert_template_result('hash has 4 elements', "hash has {{ hash.size }} elements", assigns)
|
279
|
+
end
|
280
|
+
|
281
|
+
def test_illegal_symbols
|
282
|
+
assert_template_result('', '{% if true == empty %}?{% endif %}', {})
|
283
|
+
assert_template_result('', '{% if true == null %}?{% endif %}', {})
|
284
|
+
assert_template_result('', '{% if empty == true %}?{% endif %}', {})
|
285
|
+
assert_template_result('', '{% if null == true %}?{% endif %}', {})
|
286
|
+
end
|
287
|
+
|
288
|
+
def test_ifchanged
|
289
|
+
assigns = {'array' => [ 1, 1, 2, 2, 3, 3] }
|
290
|
+
assert_template_result('123','{%for item in array%}{%ifchanged%}{{item}}{% endifchanged %}{%endfor%}',assigns)
|
291
|
+
|
292
|
+
assigns = {'array' => [ 1, 1, 1, 1] }
|
293
|
+
assert_template_result('1','{%for item in array%}{%ifchanged%}{{item}}{% endifchanged %}{%endfor%}',assigns)
|
294
|
+
end
|
295
|
+
end # StandardTagTest
|
@@ -0,0 +1,134 @@
|
|
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
|
+
expected = %| true |
|
9
|
+
assert_equal expected, Template.parse(text).render
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_true_not_eql_true
|
13
|
+
text = %| {% if true != true %} true {% else %} false {% endif %} |
|
14
|
+
expected = %| false |
|
15
|
+
assert_equal expected, Template.parse(text).render
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_true_lq_true
|
19
|
+
text = %| {% if 0 > 0 %} true {% else %} false {% endif %} |
|
20
|
+
expected = %| false |
|
21
|
+
assert_equal expected, Template.parse(text).render
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_one_lq_zero
|
25
|
+
text = %| {% if 1 > 0 %} true {% else %} false {% endif %} |
|
26
|
+
expected = %| true |
|
27
|
+
assert_equal expected, Template.parse(text).render
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_zero_lq_one
|
31
|
+
text = %| {% if 0 < 1 %} true {% else %} false {% endif %} |
|
32
|
+
expected = %| true |
|
33
|
+
assert_equal expected, Template.parse(text).render
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_zero_lq_or_equal_one
|
37
|
+
text = %| {% if 0 <= 0 %} true {% else %} false {% endif %} |
|
38
|
+
expected = %| true |
|
39
|
+
assert_equal expected, Template.parse(text).render
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_zero_lq_or_equal_one_involving_nil
|
43
|
+
text = %| {% if null <= 0 %} true {% else %} false {% endif %} |
|
44
|
+
expected = %| false |
|
45
|
+
assert_equal expected, Template.parse(text).render
|
46
|
+
|
47
|
+
|
48
|
+
text = %| {% if 0 <= null %} true {% else %} false {% endif %} |
|
49
|
+
expected = %| false |
|
50
|
+
assert_equal expected, Template.parse(text).render
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_zero_lqq_or_equal_one
|
54
|
+
text = %| {% if 0 >= 0 %} true {% else %} false {% endif %} |
|
55
|
+
expected = %| true |
|
56
|
+
assert_equal expected, Template.parse(text).render
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_strings
|
60
|
+
text = %| {% if 'test' == 'test' %} true {% else %} false {% endif %} |
|
61
|
+
expected = %| true |
|
62
|
+
assert_equal expected, Template.parse(text).render
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_strings_not_equal
|
66
|
+
text = %| {% if 'test' != 'test' %} true {% else %} false {% endif %} |
|
67
|
+
expected = %| false |
|
68
|
+
assert_equal expected, Template.parse(text).render
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_var_strings_equal
|
72
|
+
text = %| {% if var == "hello there!" %} true {% else %} false {% endif %} |
|
73
|
+
expected = %| true |
|
74
|
+
assert_equal expected, Template.parse(text).render('var' => 'hello there!')
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_var_strings_are_not_equal
|
78
|
+
text = %| {% if "hello there!" == var %} true {% else %} false {% endif %} |
|
79
|
+
expected = %| true |
|
80
|
+
assert_equal expected, Template.parse(text).render('var' => 'hello there!')
|
81
|
+
end
|
82
|
+
|
83
|
+
def test_var_and_long_string_are_equal
|
84
|
+
text = %| {% if var == 'hello there!' %} true {% else %} false {% endif %} |
|
85
|
+
expected = %| true |
|
86
|
+
assert_equal expected, Template.parse(text).render('var' => 'hello there!')
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
def test_var_and_long_string_are_equal_backwards
|
91
|
+
text = %| {% if 'hello there!' == var %} true {% else %} false {% endif %} |
|
92
|
+
expected = %| true |
|
93
|
+
assert_equal expected, Template.parse(text).render('var' => 'hello there!')
|
94
|
+
end
|
95
|
+
|
96
|
+
#def test_is_nil
|
97
|
+
# text = %| {% if var != nil %} true {% else %} false {% end %} |
|
98
|
+
# @template.assigns = { 'var' => 'hello there!'}
|
99
|
+
# expected = %| true |
|
100
|
+
# assert_equal expected, @template.parse(text)
|
101
|
+
#end
|
102
|
+
|
103
|
+
def test_is_collection_empty
|
104
|
+
text = %| {% if array == empty %} true {% else %} false {% endif %} |
|
105
|
+
expected = %| true |
|
106
|
+
assert_equal expected, Template.parse(text).render('array' => [])
|
107
|
+
end
|
108
|
+
|
109
|
+
def test_is_not_collection_empty
|
110
|
+
text = %| {% if array == empty %} true {% else %} false {% endif %} |
|
111
|
+
expected = %| false |
|
112
|
+
assert_equal expected, Template.parse(text).render('array' => [1,2,3])
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_nil
|
116
|
+
text = %| {% if var == nil %} true {% else %} false {% endif %} |
|
117
|
+
expected = %| true |
|
118
|
+
assert_equal expected, Template.parse(text).render('var' => nil)
|
119
|
+
|
120
|
+
text = %| {% if var == null %} true {% else %} false {% endif %} |
|
121
|
+
expected = %| true |
|
122
|
+
assert_equal expected, Template.parse(text).render('var' => nil)
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_not_nil
|
126
|
+
text = %| {% if var != nil %} true {% else %} false {% endif %} |
|
127
|
+
expected = %| true |
|
128
|
+
assert_equal expected, Template.parse(text).render('var' => 1 )
|
129
|
+
|
130
|
+
text = %| {% if var != null %} true {% else %} false {% endif %} |
|
131
|
+
expected = %| true |
|
132
|
+
assert_equal expected, Template.parse(text).render('var' => 1 )
|
133
|
+
end
|
134
|
+
end # StatementsTest
|