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

ruby-changes:44927

From: mrkn <ko1@a...>
Date: Tue, 6 Dec 2016 21:54:24 +0900 (JST)
Subject: [ruby-changes:44927] mrkn:r57000 (trunk): numeric.c: fix exception message for nil rounding

mrkn	2016-12-06 21:54:19 +0900 (Tue, 06 Dec 2016)

  New Revision: 57000

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57000

  Log:
    numeric.c: fix exception message for nil rounding
    
    * numeric.c (rb_num_get_rounding_option): fix exception message
      for the case of nil rounding mode.
    
    * test_float.rb: add an assertion for the above change.

  Modified files:
    trunk/numeric.c
    trunk/test/ruby/test_float.rb
Index: test/ruby/test_float.rb
===================================================================
--- test/ruby/test_float.rb	(revision 56999)
+++ test/ruby/test_float.rb	(revision 57000)
@@ -723,6 +723,9 @@ class TestFloat < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_float.rb#L723
   end
 
   def test_round_half_invalid
+    assert_raise_with_message(ArgumentError, /nil/) {
+      1.0.round(half: nil)
+    }
     assert_raise_with_message(ArgumentError, /xxx/) {
       1.0.round(half: "\0xxx")
     }
Index: numeric.c
===================================================================
--- numeric.c	(revision 56999)
+++ numeric.c	(revision 57000)
@@ -243,7 +243,10 @@ rb_num_get_rounding_option(VALUE opts) https://github.com/ruby/ruby/blob/trunk/numeric.c#L243
 	    break;
 	}
       invalid:
-	rb_raise(rb_eArgError, "invalid rounding mode: % "PRIsVALUE, rounding);
+	if (NIL_P(rounding))
+	    rb_raise(rb_eArgError, "invalid rounding mode: nil");
+	else
+	    rb_raise(rb_eArgError, "invalid rounding mode: % "PRIsVALUE, rounding);
     }
   noopt:
     return RUBY_NUM_ROUND_DEFAULT;

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

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