ruby-changes:66750
From: Jeremy <ko1@a...>
Date: Sun, 11 Jul 2021 20:30:38 +0900 (JST)
Subject: [ruby-changes:66750] 8065670cfb (master): [ruby/date] Fix comparison with Float::INFINITY
https://git.ruby-lang.org/ruby.git/commit/?id=8065670cfb From 8065670cfbfcf89249c2de12a513b5c7308c9aeb Mon Sep 17 00:00:00 2001 From: Jeremy Evans <code@j...> Date: Tue, 15 Jun 2021 10:39:42 -0700 Subject: [ruby/date] Fix comparison with Float::INFINITY Fixes [Bug #17945] https://github.com/ruby/date/commit/953d907238 --- ext/date/lib/date.rb | 2 ++ test/date/test_date.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/ext/date/lib/date.rb b/ext/date/lib/date.rb index 65c34ac..4901219 100644 --- a/ext/date/lib/date.rb +++ b/ext/date/lib/date.rb @@ -30,6 +30,8 @@ class Date https://github.com/ruby/ruby/blob/trunk/ext/date/lib/date.rb#L30 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 ebd75ae..6e99bc5 100644 --- a/test/date/test_date.rb +++ b/test/date/test_date.rb @@ -163,4 +163,16 @@ class TestDate < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/date/test_date.rb#L163 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 -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/