liquid 3.0.6 → 5.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/History.md +243 -58
- data/README.md +43 -4
- data/lib/liquid/block.rb +57 -123
- data/lib/liquid/block_body.rb +217 -85
- data/lib/liquid/condition.rb +92 -45
- data/lib/liquid/context.rb +154 -89
- data/lib/liquid/document.rb +57 -9
- data/lib/liquid/drop.rb +20 -17
- data/lib/liquid/errors.rb +27 -29
- data/lib/liquid/expression.rb +32 -20
- data/lib/liquid/extensions.rb +21 -7
- data/lib/liquid/file_system.rb +17 -15
- data/lib/liquid/forloop_drop.rb +92 -0
- data/lib/liquid/i18n.rb +10 -8
- data/lib/liquid/interrupts.rb +4 -3
- data/lib/liquid/lexer.rb +37 -26
- data/lib/liquid/locales/en.yml +13 -6
- data/lib/liquid/parse_context.rb +54 -0
- data/lib/liquid/parse_tree_visitor.rb +42 -0
- data/lib/liquid/parser.rb +30 -18
- data/lib/liquid/parser_switching.rb +20 -6
- data/lib/liquid/partial_cache.rb +24 -0
- data/lib/liquid/profiler/hooks.rb +26 -14
- data/lib/liquid/profiler.rb +72 -92
- data/lib/liquid/range_lookup.rb +28 -3
- data/lib/liquid/registers.rb +51 -0
- data/lib/liquid/resource_limits.rb +62 -0
- data/lib/liquid/standardfilters.rb +715 -132
- data/lib/liquid/strainer_factory.rb +41 -0
- data/lib/liquid/strainer_template.rb +62 -0
- data/lib/liquid/tablerowloop_drop.rb +121 -0
- data/lib/liquid/tag/disableable.rb +22 -0
- data/lib/liquid/tag/disabler.rb +21 -0
- data/lib/liquid/tag.rb +35 -12
- data/lib/liquid/tags/assign.rb +57 -18
- data/lib/liquid/tags/break.rb +15 -5
- data/lib/liquid/tags/capture.rb +24 -18
- data/lib/liquid/tags/case.rb +79 -30
- data/lib/liquid/tags/comment.rb +19 -4
- data/lib/liquid/tags/continue.rb +16 -12
- data/lib/liquid/tags/cycle.rb +47 -27
- data/lib/liquid/tags/decrement.rb +23 -24
- data/lib/liquid/tags/echo.rb +41 -0
- data/lib/liquid/tags/for.rb +155 -124
- data/lib/liquid/tags/if.rb +97 -63
- data/lib/liquid/tags/ifchanged.rb +11 -12
- data/lib/liquid/tags/include.rb +82 -73
- data/lib/liquid/tags/increment.rb +23 -17
- data/lib/liquid/tags/inline_comment.rb +43 -0
- data/lib/liquid/tags/raw.rb +50 -8
- data/lib/liquid/tags/render.rb +109 -0
- data/lib/liquid/tags/table_row.rb +57 -41
- data/lib/liquid/tags/unless.rb +38 -20
- data/lib/liquid/template.rb +71 -103
- data/lib/liquid/template_factory.rb +9 -0
- data/lib/liquid/tokenizer.rb +39 -0
- data/lib/liquid/usage.rb +8 -0
- data/lib/liquid/utils.rb +63 -9
- data/lib/liquid/variable.rb +74 -56
- data/lib/liquid/variable_lookup.rb +31 -15
- data/lib/liquid/version.rb +3 -1
- data/lib/liquid.rb +27 -12
- metadata +30 -106
- data/lib/liquid/module_ex.rb +0 -62
- data/lib/liquid/strainer.rb +0 -59
- data/lib/liquid/token.rb +0 -18
- data/test/fixtures/en_locale.yml +0 -9
- data/test/integration/assign_test.rb +0 -48
- data/test/integration/blank_test.rb +0 -106
- data/test/integration/capture_test.rb +0 -50
- data/test/integration/context_test.rb +0 -32
- data/test/integration/drop_test.rb +0 -271
- data/test/integration/error_handling_test.rb +0 -207
- data/test/integration/filter_test.rb +0 -138
- data/test/integration/hash_ordering_test.rb +0 -23
- data/test/integration/output_test.rb +0 -124
- data/test/integration/parsing_quirks_test.rb +0 -116
- data/test/integration/render_profiling_test.rb +0 -154
- data/test/integration/security_test.rb +0 -64
- data/test/integration/standard_filter_test.rb +0 -396
- data/test/integration/tags/break_tag_test.rb +0 -16
- data/test/integration/tags/continue_tag_test.rb +0 -16
- data/test/integration/tags/for_tag_test.rb +0 -375
- data/test/integration/tags/if_else_tag_test.rb +0 -190
- data/test/integration/tags/include_tag_test.rb +0 -234
- data/test/integration/tags/increment_tag_test.rb +0 -24
- data/test/integration/tags/raw_tag_test.rb +0 -25
- data/test/integration/tags/standard_tag_test.rb +0 -297
- data/test/integration/tags/statements_test.rb +0 -113
- data/test/integration/tags/table_row_test.rb +0 -63
- data/test/integration/tags/unless_else_tag_test.rb +0 -26
- data/test/integration/template_test.rb +0 -182
- data/test/integration/variable_test.rb +0 -82
- data/test/test_helper.rb +0 -89
- data/test/unit/block_unit_test.rb +0 -55
- data/test/unit/condition_unit_test.rb +0 -149
- data/test/unit/context_unit_test.rb +0 -492
- data/test/unit/file_system_unit_test.rb +0 -35
- data/test/unit/i18n_unit_test.rb +0 -37
- data/test/unit/lexer_unit_test.rb +0 -48
- data/test/unit/module_ex_unit_test.rb +0 -87
- data/test/unit/parser_unit_test.rb +0 -82
- data/test/unit/regexp_unit_test.rb +0 -44
- data/test/unit/strainer_unit_test.rb +0 -69
- data/test/unit/tag_unit_test.rb +0 -16
- data/test/unit/tags/case_tag_unit_test.rb +0 -10
- data/test/unit/tags/for_tag_unit_test.rb +0 -13
- data/test/unit/tags/if_tag_unit_test.rb +0 -8
- data/test/unit/template_unit_test.rb +0 -69
- data/test/unit/tokenizer_unit_test.rb +0 -38
- data/test/unit/variable_unit_test.rb +0 -145
- /data/{MIT-LICENSE → LICENSE} +0 -0
@@ -1,396 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
|
5
|
-
class Filters
|
6
|
-
include Liquid::StandardFilters
|
7
|
-
end
|
8
|
-
|
9
|
-
class TestThing
|
10
|
-
attr_reader :foo
|
11
|
-
|
12
|
-
def initialize
|
13
|
-
@foo = 0
|
14
|
-
end
|
15
|
-
|
16
|
-
def to_s
|
17
|
-
"woot: #{@foo}"
|
18
|
-
end
|
19
|
-
|
20
|
-
def [](whatever)
|
21
|
-
to_s
|
22
|
-
end
|
23
|
-
|
24
|
-
def to_liquid
|
25
|
-
@foo += 1
|
26
|
-
self
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
class TestDrop < Liquid::Drop
|
31
|
-
def test
|
32
|
-
"testfoo"
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
class TestEnumerable < Liquid::Drop
|
37
|
-
include Enumerable
|
38
|
-
|
39
|
-
def each(&block)
|
40
|
-
[ { "foo" => 1, "bar" => 2 }, { "foo" => 2, "bar" => 1 }, { "foo" => 3, "bar" => 3 } ].each(&block)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
class StandardFiltersTest < Minitest::Test
|
45
|
-
include Liquid
|
46
|
-
|
47
|
-
def setup
|
48
|
-
@filters = Filters.new
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_size
|
52
|
-
assert_equal 3, @filters.size([1,2,3])
|
53
|
-
assert_equal 0, @filters.size([])
|
54
|
-
assert_equal 0, @filters.size(nil)
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_downcase
|
58
|
-
assert_equal 'testing', @filters.downcase("Testing")
|
59
|
-
assert_equal '', @filters.downcase(nil)
|
60
|
-
end
|
61
|
-
|
62
|
-
def test_upcase
|
63
|
-
assert_equal 'TESTING', @filters.upcase("Testing")
|
64
|
-
assert_equal '', @filters.upcase(nil)
|
65
|
-
end
|
66
|
-
|
67
|
-
def test_slice
|
68
|
-
assert_equal 'oob', @filters.slice('foobar', 1, 3)
|
69
|
-
assert_equal 'oobar', @filters.slice('foobar', 1, 1000)
|
70
|
-
assert_equal '', @filters.slice('foobar', 1, 0)
|
71
|
-
assert_equal 'o', @filters.slice('foobar', 1, 1)
|
72
|
-
assert_equal 'bar', @filters.slice('foobar', 3, 3)
|
73
|
-
assert_equal 'ar', @filters.slice('foobar', -2, 2)
|
74
|
-
assert_equal 'ar', @filters.slice('foobar', -2, 1000)
|
75
|
-
assert_equal 'r', @filters.slice('foobar', -1)
|
76
|
-
assert_equal '', @filters.slice(nil, 0)
|
77
|
-
assert_equal '', @filters.slice('foobar', 100, 10)
|
78
|
-
assert_equal '', @filters.slice('foobar', -100, 10)
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_slice_on_arrays
|
82
|
-
input = 'foobar'.split(//)
|
83
|
-
assert_equal %w{o o b}, @filters.slice(input, 1, 3)
|
84
|
-
assert_equal %w{o o b a r}, @filters.slice(input, 1, 1000)
|
85
|
-
assert_equal %w{}, @filters.slice(input, 1, 0)
|
86
|
-
assert_equal %w{o}, @filters.slice(input, 1, 1)
|
87
|
-
assert_equal %w{b a r}, @filters.slice(input, 3, 3)
|
88
|
-
assert_equal %w{a r}, @filters.slice(input, -2, 2)
|
89
|
-
assert_equal %w{a r}, @filters.slice(input, -2, 1000)
|
90
|
-
assert_equal %w{r}, @filters.slice(input, -1)
|
91
|
-
assert_equal %w{}, @filters.slice(input, 100, 10)
|
92
|
-
assert_equal %w{}, @filters.slice(input, -100, 10)
|
93
|
-
end
|
94
|
-
|
95
|
-
def test_truncate
|
96
|
-
assert_equal '1234...', @filters.truncate('1234567890', 7)
|
97
|
-
assert_equal '1234567890', @filters.truncate('1234567890', 20)
|
98
|
-
assert_equal '...', @filters.truncate('1234567890', 0)
|
99
|
-
assert_equal '1234567890', @filters.truncate('1234567890')
|
100
|
-
assert_equal "测试...", @filters.truncate("测试测试测试测试", 5)
|
101
|
-
end
|
102
|
-
|
103
|
-
def test_split
|
104
|
-
assert_equal ['12','34'], @filters.split('12~34', '~')
|
105
|
-
assert_equal ['A? ',' ,Z'], @filters.split('A? ~ ~ ~ ,Z', '~ ~ ~')
|
106
|
-
assert_equal ['A?Z'], @filters.split('A?Z', '~')
|
107
|
-
# Regexp works although Liquid does not support.
|
108
|
-
assert_equal ['A','Z'], @filters.split('AxZ', /x/)
|
109
|
-
assert_equal [], @filters.split(nil, ' ')
|
110
|
-
end
|
111
|
-
|
112
|
-
def test_escape
|
113
|
-
assert_equal '<strong>', @filters.escape('<strong>')
|
114
|
-
assert_equal '<strong>', @filters.h('<strong>')
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_escape_once
|
118
|
-
assert_equal '<strong>Hulk</strong>', @filters.escape_once('<strong>Hulk</strong>')
|
119
|
-
end
|
120
|
-
|
121
|
-
def test_url_encode
|
122
|
-
assert_equal 'foo%2B1%40example.com', @filters.url_encode('foo+1@example.com')
|
123
|
-
assert_equal nil, @filters.url_encode(nil)
|
124
|
-
end
|
125
|
-
|
126
|
-
def test_truncatewords
|
127
|
-
assert_equal 'one two three', @filters.truncatewords('one two three', 4)
|
128
|
-
assert_equal 'one two...', @filters.truncatewords('one two three', 2)
|
129
|
-
assert_equal 'one two three', @filters.truncatewords('one two three')
|
130
|
-
assert_equal 'Two small (13” x 5.5” x 10” high) baskets fit inside one large basket (13”...', @filters.truncatewords('Two small (13” x 5.5” x 10” high) baskets fit inside one large basket (13” x 16” x 10.5” high) with cover.', 15)
|
131
|
-
assert_equal "测试测试测试测试", @filters.truncatewords('测试测试测试测试', 5)
|
132
|
-
end
|
133
|
-
|
134
|
-
def test_strip_html
|
135
|
-
assert_equal 'test', @filters.strip_html("<div>test</div>")
|
136
|
-
assert_equal 'test', @filters.strip_html("<div id='test'>test</div>")
|
137
|
-
assert_equal '', @filters.strip_html("<script type='text/javascript'>document.write('some stuff');</script>")
|
138
|
-
assert_equal '', @filters.strip_html("<style type='text/css'>foo bar</style>")
|
139
|
-
assert_equal 'test', @filters.strip_html("<div\nclass='multiline'>test</div>")
|
140
|
-
assert_equal 'test', @filters.strip_html("<!-- foo bar \n test -->test")
|
141
|
-
assert_equal '', @filters.strip_html(nil)
|
142
|
-
end
|
143
|
-
|
144
|
-
def test_join
|
145
|
-
assert_equal '1 2 3 4', @filters.join([1,2,3,4])
|
146
|
-
assert_equal '1 - 2 - 3 - 4', @filters.join([1,2,3,4], ' - ')
|
147
|
-
end
|
148
|
-
|
149
|
-
def test_sort
|
150
|
-
assert_equal [1,2,3,4], @filters.sort([4,3,2,1])
|
151
|
-
assert_equal [{"a" => 1}, {"a" => 2}, {"a" => 3}, {"a" => 4}], @filters.sort([{"a" => 4}, {"a" => 3}, {"a" => 1}, {"a" => 2}], "a")
|
152
|
-
end
|
153
|
-
|
154
|
-
def test_legacy_sort_hash
|
155
|
-
assert_equal [{a:1, b:2}], @filters.sort({a:1, b:2})
|
156
|
-
end
|
157
|
-
|
158
|
-
def test_numerical_vs_lexicographical_sort
|
159
|
-
assert_equal [2, 10], @filters.sort([10, 2])
|
160
|
-
assert_equal [{"a" => 2}, {"a" => 10}], @filters.sort([{"a" => 10}, {"a" => 2}], "a")
|
161
|
-
assert_equal ["10", "2"], @filters.sort(["10", "2"])
|
162
|
-
assert_equal [{"a" => "10"}, {"a" => "2"}], @filters.sort([{"a" => "10"}, {"a" => "2"}], "a")
|
163
|
-
end
|
164
|
-
|
165
|
-
def test_uniq
|
166
|
-
assert_equal [1,3,2,4], @filters.uniq([1,1,3,2,3,1,4,3,2,1])
|
167
|
-
assert_equal [{"a" => 1}, {"a" => 3}, {"a" => 2}], @filters.uniq([{"a" => 1}, {"a" => 3}, {"a" => 1}, {"a" => 2}], "a")
|
168
|
-
testdrop = TestDrop.new
|
169
|
-
assert_equal [testdrop], @filters.uniq([testdrop, TestDrop.new], 'test')
|
170
|
-
end
|
171
|
-
|
172
|
-
def test_reverse
|
173
|
-
assert_equal [4,3,2,1], @filters.reverse([1,2,3,4])
|
174
|
-
end
|
175
|
-
|
176
|
-
def test_legacy_reverse_hash
|
177
|
-
assert_equal [{a:1, b:2}], @filters.reverse(a:1, b:2)
|
178
|
-
end
|
179
|
-
|
180
|
-
def test_map
|
181
|
-
assert_equal [1,2,3,4], @filters.map([{"a" => 1}, {"a" => 2}, {"a" => 3}, {"a" => 4}], 'a')
|
182
|
-
assert_template_result 'abc', "{{ ary | map:'foo' | map:'bar' }}",
|
183
|
-
'ary' => [{'foo' => {'bar' => 'a'}}, {'foo' => {'bar' => 'b'}}, {'foo' => {'bar' => 'c'}}]
|
184
|
-
end
|
185
|
-
|
186
|
-
def test_map_doesnt_call_arbitrary_stuff
|
187
|
-
assert_template_result "", '{{ "foo" | map: "__id__" }}'
|
188
|
-
assert_template_result "", '{{ "foo" | map: "inspect" }}'
|
189
|
-
end
|
190
|
-
|
191
|
-
def test_map_calls_to_liquid
|
192
|
-
t = TestThing.new
|
193
|
-
assert_template_result "woot: 1", '{{ foo | map: "whatever" }}', "foo" => [t]
|
194
|
-
end
|
195
|
-
|
196
|
-
def test_map_on_hashes
|
197
|
-
assert_template_result "4217", '{{ thing | map: "foo" | map: "bar" }}',
|
198
|
-
"thing" => { "foo" => [ { "bar" => 42 }, { "bar" => 17 } ] }
|
199
|
-
end
|
200
|
-
|
201
|
-
def test_legacy_map_on_hashes_with_dynamic_key
|
202
|
-
template = "{% assign key = 'foo' %}{{ thing | map: key | map: 'bar' }}"
|
203
|
-
hash = { "foo" => { "bar" => 42 } }
|
204
|
-
assert_template_result "42", template, "thing" => hash
|
205
|
-
end
|
206
|
-
|
207
|
-
def test_sort_calls_to_liquid
|
208
|
-
t = TestThing.new
|
209
|
-
Liquid::Template.parse('{{ foo | sort: "whatever" }}').render("foo" => [t])
|
210
|
-
assert t.foo > 0
|
211
|
-
end
|
212
|
-
|
213
|
-
def test_map_over_proc
|
214
|
-
drop = TestDrop.new
|
215
|
-
p = Proc.new{ drop }
|
216
|
-
templ = '{{ procs | map: "test" }}'
|
217
|
-
assert_template_result "testfoo", templ, "procs" => [p]
|
218
|
-
end
|
219
|
-
|
220
|
-
def test_map_works_on_enumerables
|
221
|
-
assert_template_result "123", '{{ foo | map: "foo" }}', "foo" => TestEnumerable.new
|
222
|
-
end
|
223
|
-
|
224
|
-
def test_sort_works_on_enumerables
|
225
|
-
assert_template_result "213", '{{ foo | sort: "bar" | map: "foo" }}', "foo" => TestEnumerable.new
|
226
|
-
end
|
227
|
-
|
228
|
-
def test_first_and_last_call_to_liquid
|
229
|
-
assert_template_result 'foobar', '{{ foo | first }}', 'foo' => [ThingWithToLiquid.new]
|
230
|
-
assert_template_result 'foobar', '{{ foo | last }}', 'foo' => [ThingWithToLiquid.new]
|
231
|
-
end
|
232
|
-
|
233
|
-
def test_date
|
234
|
-
assert_equal 'May', @filters.date(Time.parse("2006-05-05 10:00:00"), "%B")
|
235
|
-
assert_equal 'June', @filters.date(Time.parse("2006-06-05 10:00:00"), "%B")
|
236
|
-
assert_equal 'July', @filters.date(Time.parse("2006-07-05 10:00:00"), "%B")
|
237
|
-
|
238
|
-
assert_equal 'May', @filters.date("2006-05-05 10:00:00", "%B")
|
239
|
-
assert_equal 'June', @filters.date("2006-06-05 10:00:00", "%B")
|
240
|
-
assert_equal 'July', @filters.date("2006-07-05 10:00:00", "%B")
|
241
|
-
|
242
|
-
assert_equal '2006-07-05 10:00:00', @filters.date("2006-07-05 10:00:00", "")
|
243
|
-
assert_equal '2006-07-05 10:00:00', @filters.date("2006-07-05 10:00:00", "")
|
244
|
-
assert_equal '2006-07-05 10:00:00', @filters.date("2006-07-05 10:00:00", "")
|
245
|
-
assert_equal '2006-07-05 10:00:00', @filters.date("2006-07-05 10:00:00", nil)
|
246
|
-
|
247
|
-
assert_equal '07/05/2006', @filters.date("2006-07-05 10:00:00", "%m/%d/%Y")
|
248
|
-
|
249
|
-
assert_equal "07/16/2004", @filters.date("Fri Jul 16 01:00:00 2004", "%m/%d/%Y")
|
250
|
-
assert_equal "#{Date.today.year}", @filters.date('now', '%Y')
|
251
|
-
assert_equal "#{Date.today.year}", @filters.date('today', '%Y')
|
252
|
-
|
253
|
-
assert_equal nil, @filters.date(nil, "%B")
|
254
|
-
|
255
|
-
with_timezone("UTC") do
|
256
|
-
assert_equal "07/05/2006", @filters.date(1152098955, "%m/%d/%Y")
|
257
|
-
assert_equal "07/05/2006", @filters.date("1152098955", "%m/%d/%Y")
|
258
|
-
end
|
259
|
-
end
|
260
|
-
|
261
|
-
def test_first_last
|
262
|
-
assert_equal 1, @filters.first([1,2,3])
|
263
|
-
assert_equal 3, @filters.last([1,2,3])
|
264
|
-
assert_equal nil, @filters.first([])
|
265
|
-
assert_equal nil, @filters.last([])
|
266
|
-
end
|
267
|
-
|
268
|
-
def test_replace
|
269
|
-
assert_equal '2 2 2 2', @filters.replace('1 1 1 1', '1', 2)
|
270
|
-
assert_equal '2 1 1 1', @filters.replace_first('1 1 1 1', '1', 2)
|
271
|
-
assert_template_result '2 1 1 1', "{{ '1 1 1 1' | replace_first: '1', 2 }}"
|
272
|
-
end
|
273
|
-
|
274
|
-
def test_remove
|
275
|
-
assert_equal ' ', @filters.remove("a a a a", 'a')
|
276
|
-
assert_equal 'a a a', @filters.remove_first("a a a a", 'a ')
|
277
|
-
assert_template_result 'a a a', "{{ 'a a a a' | remove_first: 'a ' }}"
|
278
|
-
end
|
279
|
-
|
280
|
-
def test_pipes_in_string_arguments
|
281
|
-
assert_template_result 'foobar', "{{ 'foo|bar' | remove: '|' }}"
|
282
|
-
end
|
283
|
-
|
284
|
-
def test_strip
|
285
|
-
assert_template_result 'ab c', "{{ source | strip }}", 'source' => " ab c "
|
286
|
-
assert_template_result 'ab c', "{{ source | strip }}", 'source' => " \tab c \n \t"
|
287
|
-
end
|
288
|
-
|
289
|
-
def test_lstrip
|
290
|
-
assert_template_result 'ab c ', "{{ source | lstrip }}", 'source' => " ab c "
|
291
|
-
assert_template_result "ab c \n \t", "{{ source | lstrip }}", 'source' => " \tab c \n \t"
|
292
|
-
end
|
293
|
-
|
294
|
-
def test_rstrip
|
295
|
-
assert_template_result " ab c", "{{ source | rstrip }}", 'source' => " ab c "
|
296
|
-
assert_template_result " \tab c", "{{ source | rstrip }}", 'source' => " \tab c \n \t"
|
297
|
-
end
|
298
|
-
|
299
|
-
def test_strip_newlines
|
300
|
-
assert_template_result 'abc', "{{ source | strip_newlines }}", 'source' => "a\nb\nc"
|
301
|
-
assert_template_result 'abc', "{{ source | strip_newlines }}", 'source' => "a\r\nb\nc"
|
302
|
-
end
|
303
|
-
|
304
|
-
def test_newlines_to_br
|
305
|
-
assert_template_result "a<br />\nb<br />\nc", "{{ source | newline_to_br }}", 'source' => "a\nb\nc"
|
306
|
-
end
|
307
|
-
|
308
|
-
def test_plus
|
309
|
-
assert_template_result "2", "{{ 1 | plus:1 }}"
|
310
|
-
assert_template_result "2.0", "{{ '1' | plus:'1.0' }}"
|
311
|
-
end
|
312
|
-
|
313
|
-
def test_minus
|
314
|
-
assert_template_result "4", "{{ input | minus:operand }}", 'input' => 5, 'operand' => 1
|
315
|
-
assert_template_result "2.3", "{{ '4.3' | minus:'2' }}"
|
316
|
-
end
|
317
|
-
|
318
|
-
def test_times
|
319
|
-
assert_template_result "12", "{{ 3 | times:4 }}"
|
320
|
-
assert_template_result "0", "{{ 'foo' | times:4 }}"
|
321
|
-
|
322
|
-
assert_template_result "6", "{{ '2.1' | times:3 | replace: '.','-' | plus:0}}"
|
323
|
-
|
324
|
-
assert_template_result "7.25", "{{ 0.0725 | times:100 }}"
|
325
|
-
end
|
326
|
-
|
327
|
-
def test_divided_by
|
328
|
-
assert_template_result "4", "{{ 12 | divided_by:3 }}"
|
329
|
-
assert_template_result "4", "{{ 14 | divided_by:3 }}"
|
330
|
-
|
331
|
-
assert_template_result "5", "{{ 15 | divided_by:3 }}"
|
332
|
-
assert_equal "Liquid error: divided by 0", Template.parse("{{ 5 | divided_by:0 }}").render
|
333
|
-
|
334
|
-
assert_template_result "0.5", "{{ 2.0 | divided_by:4 }}"
|
335
|
-
end
|
336
|
-
|
337
|
-
def test_modulo
|
338
|
-
assert_template_result "1", "{{ 3 | modulo:2 }}"
|
339
|
-
end
|
340
|
-
|
341
|
-
def test_round
|
342
|
-
assert_template_result "5", "{{ input | round }}", 'input' => 4.6
|
343
|
-
assert_template_result "4", "{{ '4.3' | round }}"
|
344
|
-
assert_template_result "4.56", "{{ input | round: 2 }}", 'input' => 4.5612
|
345
|
-
end
|
346
|
-
|
347
|
-
def test_ceil
|
348
|
-
assert_template_result "5", "{{ input | ceil }}", 'input' => 4.6
|
349
|
-
assert_template_result "5", "{{ '4.3' | ceil }}"
|
350
|
-
end
|
351
|
-
|
352
|
-
def test_floor
|
353
|
-
assert_template_result "4", "{{ input | floor }}", 'input' => 4.6
|
354
|
-
assert_template_result "4", "{{ '4.3' | floor }}"
|
355
|
-
end
|
356
|
-
|
357
|
-
def test_append
|
358
|
-
assigns = {'a' => 'bc', 'b' => 'd' }
|
359
|
-
assert_template_result('bcd',"{{ a | append: 'd'}}",assigns)
|
360
|
-
assert_template_result('bcd',"{{ a | append: b}}",assigns)
|
361
|
-
end
|
362
|
-
|
363
|
-
def test_prepend
|
364
|
-
assigns = {'a' => 'bc', 'b' => 'a' }
|
365
|
-
assert_template_result('abc',"{{ a | prepend: 'a'}}",assigns)
|
366
|
-
assert_template_result('abc',"{{ a | prepend: b}}",assigns)
|
367
|
-
end
|
368
|
-
|
369
|
-
def test_default
|
370
|
-
assert_equal "foo", @filters.default("foo", "bar")
|
371
|
-
assert_equal "bar", @filters.default(nil, "bar")
|
372
|
-
assert_equal "bar", @filters.default("", "bar")
|
373
|
-
assert_equal "bar", @filters.default(false, "bar")
|
374
|
-
assert_equal "bar", @filters.default([], "bar")
|
375
|
-
assert_equal "bar", @filters.default({}, "bar")
|
376
|
-
end
|
377
|
-
|
378
|
-
def test_cannot_access_private_methods
|
379
|
-
assert_template_result('a',"{{ 'a' | to_number }}")
|
380
|
-
end
|
381
|
-
|
382
|
-
def test_date_raises_nothing
|
383
|
-
assert_template_result('', "{{ '' | date: '%D' }}")
|
384
|
-
assert_template_result('abc', "{{ 'abc' | date: '%D' }}")
|
385
|
-
end
|
386
|
-
|
387
|
-
private
|
388
|
-
|
389
|
-
def with_timezone(tz)
|
390
|
-
old_tz = ENV['TZ']
|
391
|
-
ENV['TZ'] = tz
|
392
|
-
yield
|
393
|
-
ensure
|
394
|
-
ENV['TZ'] = old_tz
|
395
|
-
end
|
396
|
-
end # StandardFiltersTest
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class BreakTagTest < Minitest::Test
|
4
|
-
include Liquid
|
5
|
-
|
6
|
-
# tests that no weird errors are raised if break is called outside of a
|
7
|
-
# block
|
8
|
-
def test_break_with_no_block
|
9
|
-
assigns = {'i' => 1}
|
10
|
-
markup = '{% break %}'
|
11
|
-
expected = ''
|
12
|
-
|
13
|
-
assert_template_result(expected, markup, assigns)
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class ContinueTagTest < Minitest::Test
|
4
|
-
include Liquid
|
5
|
-
|
6
|
-
# tests that no weird errors are raised if continue is called outside of a
|
7
|
-
# block
|
8
|
-
def test_continue_with_no_block
|
9
|
-
assigns = {}
|
10
|
-
markup = '{% continue %}'
|
11
|
-
expected = ''
|
12
|
-
|
13
|
-
assert_template_result(expected, markup, assigns)
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|