diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | ext/bigdecimal/bigdecimal.c | 6 | ||||
-rw-r--r-- | test/bigdecimal/test_bigdecimal.rb | 7 |
3 files changed, 15 insertions, 6 deletions
@@ -1,3 +1,11 @@ +Mon Sep 20 02:34:11 2010 Kenta Murata <[email protected]> + + * ext/bigdecimal/bigdecimal.c (check_rounding_mode, BigDecimal_mode): + raise ArgumentError instead of TypeError passing invalid modes. + + * test/bigdecimal/test_bigdecimal.rb (test_mode, test_round): + change against the above modifications. + Sun Sep 19 22:08:39 2010 Yuki Sonoda (Yugui) <[email protected]> * lib/mkmf.rb (try_link): rdoc diff --git a/ext/bigdecimal/bigdecimal.c b/ext/bigdecimal/bigdecimal.c index 64eebecad1..a251a8e9de 100644 --- a/ext/bigdecimal/bigdecimal.c +++ b/ext/bigdecimal/bigdecimal.c @@ -311,7 +311,7 @@ check_rounding_mode(VALUE const v) return VP_ROUND_CEIL; if (id == id_floor) return VP_ROUND_FLOOR; - break; + rb_raise(rb_eArgError, "invalid rounding mode"); default: break; @@ -320,7 +320,7 @@ check_rounding_mode(VALUE const v) Check_Type(v, T_FIXNUM); sw = (unsigned short)FIX2UINT(v); if (!VpIsRoundMode(sw)) { - rb_raise(rb_eTypeError, "invalid rounding mode"); + rb_raise(rb_eArgError, "invalid rounding mode"); } return sw; } @@ -380,7 +380,7 @@ BigDecimal_mode(int argc, VALUE *argv, VALUE self) fo = VpGetException(); if(val==Qnil) return INT2FIX(fo); if(val!=Qfalse && val!=Qtrue) { - rb_raise(rb_eTypeError, "second argument must be true or false"); + rb_raise(rb_eArgError, "second argument must be true or false"); return Qnil; /* Not reached */ } if(f&VP_EXCEPTION_INFINITY) { diff --git a/test/bigdecimal/test_bigdecimal.rb b/test/bigdecimal/test_bigdecimal.rb index 351fd2dbab..9f66a7940f 100644 --- a/test/bigdecimal/test_bigdecimal.rb +++ b/test/bigdecimal/test_bigdecimal.rb @@ -53,8 +53,9 @@ class TestBigDecimal < Test::Unit::TestCase end def test_mode - assert_raise(TypeError) { BigDecimal.mode(BigDecimal::EXCEPTION_ALL, 1) } - assert_raise(TypeError) { BigDecimal.mode(BigDecimal::ROUND_MODE, 256) } + assert_raise(ArgumentError) { BigDecimal.mode(BigDecimal::EXCEPTION_ALL, 1) } + assert_raise(ArgumentError) { BigDecimal.mode(BigDecimal::ROUND_MODE, 256) } + assert_raise(ArgumentError) { BigDecimal.mode(BigDecimal::ROUND_MODE, :xyzzy) } assert_raise(TypeError) { BigDecimal.mode(0xf000, true) } begin @@ -632,7 +633,7 @@ class TestBigDecimal < Test::Unit::TestCase assert_equal(2, x.round(0, BigDecimal::ROUND_HALF_EVEN)) assert_equal(3, x.round(0, BigDecimal::ROUND_CEILING)) assert_equal(2, x.round(0, BigDecimal::ROUND_FLOOR)) - assert_raise(TypeError) { x.round(0, 256) } + assert_raise(ArgumentError) { x.round(0, 256) } ROUNDING_MODE_MAP.each do |const, sym| assert_equal(x.round(0, const), x.round(0, sym)) |