diff options
author | Kenta Murata <mrkn@users.noreply.github.com> | 2020-10-22 17:59:52 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-22 17:59:52 +0900 |
commit | d23d5c3130a0944e7e591370cbf8599009318a7c (patch) | |
tree | 1133a91f7a511d669ba300a7619927806ece8849 /test | |
parent | 603fb940c0d334f399d77b56d7e62ee85edb91e0 (diff) |
rational.c: try converting by to_int in Rational() (#3684)
[Bug #12485]
Notes
Notes:
Merged-By: mrkn <mrkn@ruby-lang.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_rational.rb | 19 |
1 files changed, 19 insertions, 0 deletions
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) { |