summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-15 07:19:48 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-03-15 07:19:48 +0000
commitc6ab3498554ade8ba7fd11607967a388c7aede32 (patch)
treed557ce9c1abbb8d94509d7265221f2be9708fa27 /test/ruby
parent0dc74b94c2bea4285e4e63e7a1a03f75582a6630 (diff)
Add `exception:` keyword in Kernel#Complex()
Support `exception:` keyword argument in `Kernel#Complex()`. If `exception:` is `false`, `Kernel#Complex()` returns `nil` if the given value cannot be interpreted as a complex value. The default value of `exception:` is `true`. This is part of [Feature #12732]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62760 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_complex.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/ruby/test_complex.rb b/test/ruby/test_complex.rb
index c2ed1b0827..d8d8fb9cd6 100644
--- a/test/ruby/test_complex.rb
+++ b/test/ruby/test_complex.rb
@@ -746,6 +746,27 @@ class Complex_Test < Test::Unit::TestCase
end
+ def test_Complex_without_exception
+ assert_nothing_raised(ArgumentError){
+ assert_equal(nil, Complex('5x', exception: false))
+ }
+ assert_nothing_raised(ArgumentError){
+ assert_equal(nil, Complex(Object.new, exception: false))
+ }
+ assert_nothing_raised(ArgumentError){
+ assert_equal(nil, Complex(1, Object.new, exception: false))
+ }
+
+ o = Object.new
+ def o.to_c; raise; end
+ assert_nothing_raised(ArgumentError){
+ assert_equal(nil, Complex(o, exception: false))
+ }
+ assert_nothing_raised(ArgumentError){
+ assert_equal(nil, Complex(1, o, exception: false))
+ }
+ end
+
def test_respond
c = Complex(1,1)
assert_not_respond_to(c, :%)