diff options
author | Jeremy Evans <code@jeremyevans.net> | 2021-06-15 10:39:42 -0700 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2021-07-11 20:28:21 +0900 |
commit | 8065670cfbfcf89249c2de12a513b5c7308c9aeb (patch) | |
tree | a8e9044dd8879f9ec2bf91c349fac25a9a5a0e97 | |
parent | 49ba7cd2598e047aba37c204c143ce6ee2364e8c (diff) | |
download | ruby-8065670cfbfcf89249c2de12a513b5c7308c9aeb.tar.gz |
[ruby/date] Fix comparison with Float::INFINITY
Fixes [Bug #17945]
https://github.com/ruby/date/commit/953d907238
-rw-r--r-- | ext/date/lib/date.rb | 2 | ||||
-rw-r--r-- | test/date/test_date.rb | 12 |
2 files changed, 14 insertions, 0 deletions
diff --git a/ext/date/lib/date.rb b/ext/date/lib/date.rb index 65c34ace49..4901219503 100644 --- a/ext/date/lib/date.rb +++ b/ext/date/lib/date.rb @@ -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 diff --git a/test/date/test_date.rb b/test/date/test_date.rb index ebd75ae12d..6e99bc562c 100644 --- a/test/date/test_date.rb +++ b/test/date/test_date.rb @@ -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 |