1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/bigdecimal/bigdecimal.c (BigDecimal_new),

test/bigdecimal/test_bigdecimal.rb:
  Fix exception message of BigDecimal constructor with a Float.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37407 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mrkn 2012-11-01 13:04:04 +00:00
parent 2e6b5ece95
commit a3e5a86596
3 changed files with 21 additions and 1 deletions

View file

@ -1,3 +1,9 @@
Thu Nov 1 21:57:00 2012 Kenta Murata <mrkn@mrkn.jp>
* ext/bigdecimal/bigdecimal.c (BigDecimal_new),
test/bigdecimal/test_bigdecimal.rb:
Fix exception message of BigDecimal constructor with a Float.
Thu Nov 1 21:52:20 2012 Kenta Murata <mrkn@mrkn.jp>
* ext/bigdecimal/bigdecimal.c (BigDecimal_add),

View file

@ -2354,7 +2354,9 @@ BigDecimal_new(int argc, VALUE *argv)
/* fall through */
case T_RATIONAL:
if (NIL_P(nFig)) {
rb_raise(rb_eArgError, "can't omit precision for a Rational.");
rb_raise(rb_eArgError,
"can't omit precision for a %s.",
rb_class2name(CLASS_OF(iniValue)));
}
return GetVpValueWithPrec(iniValue, mf, 1);

View file

@ -52,6 +52,18 @@ class TestBigDecimal < Test::Unit::TestCase
assert_equal(1, BigDecimal("1"))
assert_equal(1, BigDecimal("1", 1))
assert_raise(ArgumentError) { BigDecimal("1", -1) }
assert_raise(ArgumentError) { BigDecimal(4.2) }
begin
BigDecimal(4.2)
rescue ArgumentError => error
assert_match(/Float/, error.message)
end
assert_raise(ArgumentError) { BigDecimal(42.quo(7)) }
begin
BigDecimal(42.quo(7))
rescue ArgumentError => error
assert_match(/Rational/, error.message)
end
end
def test_global_new_with_integer