Fix min/max filters

This commit is contained in:
Thibaut Courouble
2017-12-06 08:58:05 -05:00
parent e6ba6ee87b
commit 282d42f98d
2 changed files with 18 additions and 18 deletions

View File

@@ -357,7 +357,7 @@ module Liquid
max_value = Utils.to_number(n)
result = Utils.to_number(input)
result = max_value if result > max_value
result = max_value if max_value > result
result.is_a?(BigDecimal) ? result.to_f : result
end
@@ -365,7 +365,7 @@ module Liquid
min_value = Utils.to_number(n)
result = Utils.to_number(input)
result = min_value if result < min_value
result = min_value if min_value < result
result.is_a?(BigDecimal) ? result.to_f : result
end

View File

@@ -496,26 +496,26 @@ class StandardFiltersTest < Minitest::Test
assert_template_result "5", "{{ price | floor }}", 'price' => NumberLikeThing.new(5.4)
end
def test_max
assert_template_result "4", "{{ 5 | max:4 }}"
assert_template_result "5", "{{ 5 | max:5 }}"
assert_template_result "5", "{{ 5 | max:6 }}"
def test_min
assert_template_result "4", "{{ 5 | min:4 }}"
assert_template_result "5", "{{ 5 | min:5 }}"
assert_template_result "5", "{{ 5 | min:6 }}"
assert_template_result "4.5", "{{ 4.5 | max:5 }}"
assert_template_result "5", "{{ width | max:5 }}", 'width' => NumberLikeThing.new(6)
assert_template_result "4", "{{ width | max:5 }}", 'width' => NumberLikeThing.new(4)
assert_template_result "4", "{{ 5 | max: width }}", 'width' => NumberLikeThing.new(4)
assert_template_result "4.5", "{{ 4.5 | min:5 }}"
assert_template_result "5", "{{ width | min:5 }}", 'width' => NumberLikeThing.new(6)
assert_template_result "4", "{{ width | min:5 }}", 'width' => NumberLikeThing.new(4)
assert_template_result "4", "{{ 5 | min: width }}", 'width' => NumberLikeThing.new(4)
end
def test_min
assert_template_result "5", "{{ 5 | min:4 }}"
assert_template_result "5", "{{ 5 | min:5 }}"
assert_template_result "6", "{{ 5 | min:6 }}"
def test_max
assert_template_result "5", "{{ 5 | max:4 }}"
assert_template_result "5", "{{ 5 | max:5 }}"
assert_template_result "6", "{{ 5 | max:6 }}"
assert_template_result "5", "{{ 4.5 | min:5 }}"
assert_template_result "6", "{{ width | min:5 }}", 'width' => NumberLikeThing.new(6)
assert_template_result "5", "{{ width | min:5 }}", 'width' => NumberLikeThing.new(4)
assert_template_result "6", "{{ 5 | min: width }}", 'width' => NumberLikeThing.new(6)
assert_template_result "5", "{{ 4.5 | max:5 }}"
assert_template_result "6", "{{ width | max:5 }}", 'width' => NumberLikeThing.new(6)
assert_template_result "5", "{{ width | max:5 }}", 'width' => NumberLikeThing.new(4)
assert_template_result "6", "{{ 5 | max: width }}", 'width' => NumberLikeThing.new(6)
end
def test_append