[前][次][番号順一覧][スレッド一覧]

ruby-changes:17300

From: mrkn <ko1@a...>
Date: Mon, 20 Sep 2010 02:38:25 +0900 (JST)
Subject: [ruby-changes:17300] Ruby:r29304 (trunk): * ext/bigdecimal/bigdecimal.c (check_rounding_mode, BigDecimal_mode):

mrkn	2010-09-20 02:38:18 +0900 (Mon, 20 Sep 2010)

  New Revision: 29304

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29304

  Log:
    * 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.

  Modified files:
    trunk/ChangeLog
    trunk/ext/bigdecimal/bigdecimal.c
    trunk/test/bigdecimal/test_bigdecimal.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 29303)
+++ ChangeLog	(revision 29304)
@@ -1,3 +1,11 @@
+Mon Sep 20 02:34:11 2010  Kenta Murata  <mrkn@m...>
+
+	* 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@y...>
 
 	* lib/mkmf.rb (try_link): rdoc
Index: ext/bigdecimal/bigdecimal.c
===================================================================
--- ext/bigdecimal/bigdecimal.c	(revision 29303)
+++ ext/bigdecimal/bigdecimal.c	(revision 29304)
@@ -311,7 +311,7 @@
 	    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_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 @@
         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) {
Index: test/bigdecimal/test_bigdecimal.rb
===================================================================
--- test/bigdecimal/test_bigdecimal.rb	(revision 29303)
+++ test/bigdecimal/test_bigdecimal.rb	(revision 29304)
@@ -53,8 +53,9 @@
   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 @@
     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))

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]