aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-09-19 17:38:18 +0000
committermrkn <mrkn@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-09-19 17:38:18 +0000
commit971a57004e346d87c7f0f55d16f1abb66fe24451 (patch)
treeb9d054de8151f72ca7b74fa72a918d6716ffc2a3
parentac69adf5dea3b6b0b3df34db73cc2255fb481aa0 (diff)
downloadruby-971a57004e346d87c7f0f55d16f1abb66fe24451.tar.gz
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29304 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog8
-rw-r--r--ext/bigdecimal/bigdecimal.c6
-rw-r--r--test/bigdecimal/test_bigdecimal.rb7
3 files changed, 15 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index 42783c093f..8a9ea979ea 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Mon Sep 20 02:34:11 2010 Kenta Murata <mrkn@mrkn.jp>
+
+ * 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) <yugui@yugui.jp>
* 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))