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:
parent
49ba7cd259
commit
8065670cfb
2 changed files with 14 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue