Commit 2f717544 authored by KOBAYASHI Shuji's avatar KOBAYASHI Shuji

Fix `Fixnum#(to_s|inspect)` argument specs

Before this patch:

  $ bin/mruby -e 'p 3.to_s(2)'
  trace (most recent call last):
    [0] -e:1
  -e:1: 'to_s': wrong number of arguments (1 for 0) (ArgumentError)

After this patch:

  $ bin/mruby -e 'p 3.to_s(2)'
  "11"
parent 2f9b1fdb
......@@ -1663,8 +1663,8 @@ mrb_init_numeric(mrb_state *mrb)
#ifndef MRB_WITHOUT_FLOAT
mrb_define_method(mrb, fixnum, "to_f", fix_to_f, MRB_ARGS_NONE()); /* 15.2.8.3.23 */
#endif
mrb_define_method(mrb, fixnum, "to_s", fix_to_s, MRB_ARGS_NONE()); /* 15.2.8.3.25 */
mrb_define_method(mrb, fixnum, "inspect", fix_to_s, MRB_ARGS_NONE());
mrb_define_method(mrb, fixnum, "to_s", fix_to_s, MRB_ARGS_OPT(1)); /* 15.2.8.3.25 */
mrb_define_method(mrb, fixnum, "inspect", fix_to_s, MRB_ARGS_OPT(1));
mrb_define_method(mrb, fixnum, "divmod", fix_divmod, MRB_ARGS_REQ(1)); /* 15.2.8.3.30 (x) */
#ifndef MRB_WITHOUT_FLOAT
......
......@@ -232,8 +232,16 @@ assert('Integer#to_i', '15.2.8.3.24') do
end
assert('Integer#to_s', '15.2.8.3.25') do
assert_equal '1', 1.to_s
assert_equal("-1", -1.to_s)
assert_equal "1", 1.to_s
assert_equal "-1", -1.to_s
assert_equal "1010", 10.to_s(2)
assert_equal "a", 10.to_s(36)
assert_equal "-a", -10.to_s(36)
assert_equal "30071", 12345.to_s(8)
assert_raise(ArgumentError) { 10.to_s(-1) }
assert_raise(ArgumentError) { 10.to_s(0) }
assert_raise(ArgumentError) { 10.to_s(1) }
assert_raise(ArgumentError) { 10.to_s(37) }
end
assert('Integer#truncate', '15.2.8.3.26') do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment