mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
ac69adf5de
commit
971a57004e
3 changed files with 15 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in a new issue