diff options
author | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-12-04 04:22:09 +0000 |
---|---|---|
committer | mrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2018-12-04 04:22:09 +0000 |
commit | 8891bb3bd602bdbabd24260cf1e431475dc027c8 (patch) | |
tree | 34d127bed86e82d71b9e496e518461f9a35ef9d9 /test/bigdecimal | |
parent | 242ce4b1d359d23c260ce45146d04d224127b717 (diff) |
Import bigdecimal-1.4.0.pre-20181204a
* https://github.com/ruby/bigdecimal/compare/v1.4.0.pre.20181130a..v1.4.0.pre.20181204a
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66183 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/bigdecimal')
-rw-r--r-- | test/bigdecimal/test_bigdecimal.rb | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb index 67cac71557..ff295b4270 100644 --- a/test/bigdecimal/test_bigdecimal.rb +++ b/test/bigdecimal/test_bigdecimal.rb @@ -151,6 +151,63 @@ class TestBigDecimal < Test::Unit::TestCase $SAFE = 0 end + def test_BigDecimal_with_exception_keyword + assert_raise(ArgumentError) { + BigDecimal('.', exception: true) + } + assert_nothing_raised(ArgumentError) { + assert_equal(nil, BigDecimal(".", exception: false)) + } + assert_raise(ArgumentError) { + BigDecimal("1", -1, exception: true) + } + assert_nothing_raised(ArgumentError) { + assert_equal(nil, BigDecimal("1", -1, exception: false)) + } + assert_raise(ArgumentError) { + BigDecimal(42.quo(7), exception: true) + } + assert_nothing_raised(ArgumentError) { + assert_equal(nil, BigDecimal(42.quo(7), exception: false)) + } + assert_raise(ArgumentError) { + BigDecimal(4.2, exception: true) + } + assert_nothing_raised(ArgumentError) { + assert_equal(nil, BigDecimal(4.2, exception: false)) + } + # TODO: support conversion from complex + # assert_raise(RangeError) { + # BigDecimal(1i, exception: true) + # } + # assert_nothing_raised(RangeError) { + # assert_equal(nil, BigDecimal(1i, exception: false)) + # } + assert_raise(TypeError) { + BigDecimal(nil, exception: true) + } + assert_nothing_raised(TypeError) { + assert_equal(nil, BigDecimal(nil, exception: false)) + } + assert_nothing_raised(TypeError) { + assert_equal(nil, BigDecimal(:test, exception: false)) + } + assert_nothing_raised(TypeError) { + assert_equal(nil, BigDecimal(Object.new, exception: false)) + } + # TODO: support to_d + # assert_nothing_raised(TypeError) { + # o = Object.new + # def o.to_d; 3.14; end + # assert_equal(3.14, BigDecimal(o, exception: false)) + # } + # assert_nothing_raised(RuntimeError) { + # o = Object.new + # def o.to_d; raise; end + # assert_equal(nil, BigDecimal(o, exception: false)) + # } + end + def test_s_ver assert_raise(NoMethodError, /undefined method `ver`/) { BigDecimal.ver } end |