From d23d5c3130a0944e7e591370cbf8599009318a7c Mon Sep 17 00:00:00 2001 From: Kenta Murata Date: Thu, 22 Oct 2020 17:59:52 +0900 Subject: rational.c: try converting by to_int in Rational() (#3684) [Bug #12485] --- test/ruby/test_rational.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test') diff --git a/test/ruby/test_rational.rb b/test/ruby/test_rational.rb index 301890b620..5bdf5b717e 100644 --- a/test/ruby/test_rational.rb +++ b/test/ruby/test_rational.rb @@ -128,6 +128,13 @@ class Rational_Test < Test::Unit::TestCase assert_raise(TypeError){Rational(Object.new, Object.new)} assert_raise(TypeError){Rational(1, Object.new)} + bug12485 = '[ruby-core:75995] [Bug #12485]' + o = Object.new + def o.to_int; 1; end + assert_equal(1, Rational(o, 1), bug12485) + assert_equal(1, Rational(1, o), bug12485) + assert_equal(1, Rational(o, o), bug12485) + o = Object.new def o.to_r; 1/42r; end assert_equal(1/42r, Rational(o)) @@ -834,6 +841,18 @@ class Rational_Test < Test::Unit::TestCase assert_equal(nil, Rational(1, Object.new, exception: false)) } + bug12485 = '[ruby-core:75995] [Bug #12485]' + assert_nothing_raised(RuntimeError, bug12485) { + o = Object.new + def o.to_int; raise; end + assert_equal(nil, Rational(o, exception: false)) + } + assert_nothing_raised(RuntimeError, bug12485) { + o = Object.new + def o.to_int; raise; end + assert_equal(nil, Rational(1, o, exception: false)) + } + o = Object.new; def o.to_r; raise; end assert_nothing_raised(RuntimeError) { -- cgit v1.2.3