From c6ab3498554ade8ba7fd11607967a388c7aede32 Mon Sep 17 00:00:00 2001 From: mrkn Date: Thu, 15 Mar 2018 07:19:48 +0000 Subject: 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 --- test/ruby/test_complex.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/ruby') 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, :%) -- cgit v1.2.3