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

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.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57000 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mrkn 2016-12-06 12:54:19 +00:00
parent a560add68a
commit 0cb1a2b812
2 changed files with 7 additions and 1 deletions

View file

@ -243,6 +243,9 @@ rb_num_get_rounding_option(VALUE opts)
break;
}
invalid:
if (NIL_P(rounding))
rb_raise(rb_eArgError, "invalid rounding mode: nil");
else
rb_raise(rb_eArgError, "invalid rounding mode: % "PRIsVALUE, rounding);
}
noopt:

View file

@ -723,6 +723,9 @@ class TestFloat < Test::Unit::TestCase
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")
}