mirror of
https://github.com/Shopify/liquid.git
synced 2025-07-21 00:00:18 -04:00
Compare commits
No commits in common. "b1b9b9f6913ad0a9322cb33acd58879124b66f3a" and "0b9318222bcc09681e52fd5b8e70262274e673bf" have entirely different histories.
b1b9b9f691
...
0b9318222b
@ -892,11 +892,9 @@ module Liquid
|
|||||||
raise_property_error(property)
|
raise_property_error(property)
|
||||||
end
|
end
|
||||||
|
|
||||||
result = InputIterator.new(values_for_sum, context).sum do |item|
|
InputIterator.new(values_for_sum, context).sum do |item|
|
||||||
Utils.to_number(item)
|
Utils.to_number(item)
|
||||||
end
|
end
|
||||||
|
|
||||||
result.is_a?(BigDecimal) ? result.to_f : result
|
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -994,42 +994,6 @@ class StandardFiltersTest < Minitest::Test
|
|||||||
assert(t.foo > 0)
|
assert(t.foo > 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_sum_of_floats
|
|
||||||
input = [0.1, 0.2, 0.3]
|
|
||||||
assert_equal(0.6, @filters.sum(input))
|
|
||||||
assert_template_result("0.6", "{{ input | sum }}", { "input" => input })
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_sum_of_negative_floats
|
|
||||||
input = [0.1, 0.2, -0.3]
|
|
||||||
assert_equal(0.0, @filters.sum(input))
|
|
||||||
assert_template_result("0.0", "{{ input | sum }}", { "input" => input })
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_sum_with_float_strings
|
|
||||||
input = [0.1, "0.2", "0.3"]
|
|
||||||
assert_equal(0.6, @filters.sum(input))
|
|
||||||
assert_template_result("0.6", "{{ input | sum }}", { "input" => input })
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_sum_resulting_in_negative_float
|
|
||||||
input = [0.1, -0.2, -0.3]
|
|
||||||
assert_equal(-0.4, @filters.sum(input))
|
|
||||||
assert_template_result("-0.4", "{{ input | sum }}", { "input" => input })
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_sum_with_floats_and_indexable_map_values
|
|
||||||
input = [{ "quantity" => 1 }, { "quantity" => 0.2, "weight" => -0.3 }, { "weight" => 0.4 }]
|
|
||||||
assert_equal(0.0, @filters.sum(input))
|
|
||||||
assert_equal(1.2, @filters.sum(input, "quantity"))
|
|
||||||
assert_equal(0.1, @filters.sum(input, "weight"))
|
|
||||||
assert_equal(0.0, @filters.sum(input, "subtotal"))
|
|
||||||
assert_template_result("0", "{{ input | sum }}", { "input" => input })
|
|
||||||
assert_template_result("1.2", "{{ input | sum: 'quantity' }}", { "input" => input })
|
|
||||||
assert_template_result("0.1", "{{ input | sum: 'weight' }}", { "input" => input })
|
|
||||||
assert_template_result("0", "{{ input | sum: 'subtotal' }}", { "input" => input })
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def with_timezone(tz)
|
def with_timezone(tz)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user