mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-29 15:15:19 -07:00
@@ -289,6 +289,12 @@ module Liquid
|
|||||||
array.last if array.respond_to?(:last)
|
array.last if array.respond_to?(:last)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# absolute value
|
||||||
|
def abs(input)
|
||||||
|
result = Utils.to_number(input).abs
|
||||||
|
result.is_a?(BigDecimal) ? result.to_f : result
|
||||||
|
end
|
||||||
|
|
||||||
# addition
|
# addition
|
||||||
def plus(input, operand)
|
def plus(input, operand)
|
||||||
apply_operation(input, operand, :+)
|
apply_operation(input, operand, :+)
|
||||||
|
|||||||
@@ -385,6 +385,19 @@ class StandardFiltersTest < Minitest::Test
|
|||||||
assert_template_result "5", "{{ price | minus:'2' }}", 'price' => NumberLikeThing.new(7)
|
assert_template_result "5", "{{ price | minus:'2' }}", 'price' => NumberLikeThing.new(7)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_abs
|
||||||
|
assert_template_result "17", "{{ 17 | abs }}"
|
||||||
|
assert_template_result "17", "{{ -17 | abs }}"
|
||||||
|
assert_template_result "17", "{{ '17' | abs }}"
|
||||||
|
assert_template_result "17", "{{ '-17' | abs }}"
|
||||||
|
assert_template_result "0", "{{ 0 | abs }}"
|
||||||
|
assert_template_result "0", "{{ '0' | abs }}"
|
||||||
|
assert_template_result "17.42", "{{ 17.42 | abs }}"
|
||||||
|
assert_template_result "17.42", "{{ -17.42 | abs }}"
|
||||||
|
assert_template_result "17.42", "{{ '17.42' | abs }}"
|
||||||
|
assert_template_result "17.42", "{{ '-17.42' | abs }}"
|
||||||
|
end
|
||||||
|
|
||||||
def test_times
|
def test_times
|
||||||
assert_template_result "12", "{{ 3 | times:4 }}"
|
assert_template_result "12", "{{ 3 | times:4 }}"
|
||||||
assert_template_result "0", "{{ 'foo' | times:4 }}"
|
assert_template_result "0", "{{ 'foo' | times:4 }}"
|
||||||
|
|||||||
Reference in New Issue
Block a user