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

Fix error message

* array.c (ary_take_first_or_last): expected optional argument.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2018-12-04 09:16:49 +00:00
parent c01a5ee85e
commit c28c20ee88
2 changed files with 12 additions and 4 deletions

10
array.c
View file

@ -1108,13 +1108,17 @@ enum ary_take_pos_flags
static VALUE
ary_take_first_or_last(int argc, const VALUE *argv, VALUE ary, enum ary_take_pos_flags last)
{
VALUE nv;
long n;
long len;
long offset = 0;
rb_scan_args(argc, argv, "1", &nv);
n = NUM2LONG(nv);
argc = rb_check_arity(argc, 0, 1);
/* the case optional argument is ommited should be handled in
* callers of this function. if another arity case is added,
* this arity check needs to rewrite. */
RUBY_ASSERT_WHEN(TRUE, argc == 1);
n = NUM2LONG(argv[0]);
len = RARRAY_LEN(ary);
if (n > len) {
n = len;

View file

@ -146,14 +146,17 @@ class TestArray < Test::Unit::TestCase
assert_equal(1, x.first)
assert_equal([1], x.first(1))
assert_equal([1, 2, 3], x.first(3))
assert_raise_with_message(ArgumentError, /0\.\.1/) {x.first(1, 2)}
assert_equal(5, x.last)
assert_equal([5], x.last(1))
assert_equal([3, 4, 5], x.last(3))
assert_raise_with_message(ArgumentError, /0\.\.1/) {x.last(1, 2)}
assert_equal(1, x.shift)
assert_equal([2, 3, 4], x.shift(3))
assert_equal([5], x)
assert_raise_with_message(ArgumentError, /0\.\.1/) {x.first(1, 2)}
assert_equal([2, 3, 4, 5], x.unshift(2, 3, 4))
assert_equal([1, 2, 3, 4, 5], x.unshift(1))
@ -162,6 +165,7 @@ class TestArray < Test::Unit::TestCase
assert_equal(5, x.pop)
assert_equal([3, 4], x.pop(2))
assert_equal([1, 2], x)
assert_raise_with_message(ArgumentError, /0\.\.1/) {x.pop(1, 2)}
assert_equal([1, 2, 3, 4], x.push(3, 4))
assert_equal([1, 2, 3, 4, 5], x.push(5))
@ -1585,7 +1589,7 @@ class TestArray < Test::Unit::TestCase
def o.to_ary
foo_bar()
end
assert_match(/foo_bar/, assert_raise(NoMethodError) {a.concat(o)}.message)
assert_raise_with_message(NoMethodError, /foo_bar/) {a.concat(o)}
end
def test_to_s