mirror of
https://github.com/ruby/ruby.git
synced 2025-09-23 04:24:04 +02:00
rational.c: try converting by to_int in Rational() (#3684)
[Bug #12485]
This commit is contained in:
parent
603fb940c0
commit
d23d5c3130
Notes:
git
2020-10-22 18:00:33 +09:00
Merged-By: mrkn <mrkn@ruby-lang.org>
2 changed files with 50 additions and 3 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue