1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/date] Fix comparison with Float::INFINITY

Fixes [Bug #17945]

953d907238
This commit is contained in:
Jeremy Evans 2021-06-15 10:39:42 -07:00 committed by Nobuyoshi Nakada
parent 49ba7cd259
commit 8065670cfb
2 changed files with 14 additions and 0 deletions

View file

@ -30,6 +30,8 @@ class Date
def <=>(other)
case other
when Infinity; return d <=> other.d
when Float::INFINITY; return d <=> 1
when -Float::INFINITY; return d <=> -1
when Numeric; return d
else
begin

View file

@ -163,4 +163,16 @@ class TestDate < Test::Unit::TestCase
assert_equal(1, d2 <=> d1)
end
def test_infinity_comparison
assert_equal(0, Float::INFINITY <=> Date::Infinity.new)
assert_equal(0, Date::Infinity.new <=> Float::INFINITY)
assert_equal(0, -Float::INFINITY <=> -Date::Infinity.new)
assert_equal(0, -Date::Infinity.new <=> -Float::INFINITY)
assert_equal(1, Float::INFINITY <=> -Date::Infinity.new)
assert_equal(1, Date::Infinity.new <=> -Float::INFINITY)
assert_equal(-1, -Float::INFINITY <=> Date::Infinity.new)
assert_equal(-1, -Date::Infinity.new <=> Float::INFINITY)
end
end