mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
array.c: check position to insert
* array.c (rb_ary_insert): check position to insert even if no elements to be inserted. [ruby-core:81125] [Bug #13558] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58693 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
9c38f3e6c3
commit
e95cac18bd
2 changed files with 2 additions and 1 deletions
2
array.c
2
array.c
|
@ -1781,8 +1781,8 @@ rb_ary_insert(int argc, VALUE *argv, VALUE ary)
|
|||
|
||||
rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS);
|
||||
rb_ary_modify_check(ary);
|
||||
if (argc == 1) return ary;
|
||||
pos = NUM2LONG(argv[0]);
|
||||
if (argc == 1) return ary;
|
||||
if (pos == -1) {
|
||||
pos = RARRAY_LEN(ary);
|
||||
}
|
||||
|
|
|
@ -2121,6 +2121,7 @@ class TestArray < Test::Unit::TestCase
|
|||
assert_equal([0], a.insert(1))
|
||||
assert_equal([0, 1], a.insert(1, 1))
|
||||
assert_raise(ArgumentError) { a.insert }
|
||||
assert_raise(TypeError) { a.insert(Object.new) }
|
||||
assert_equal([0, 1, 2], a.insert(-1, 2))
|
||||
assert_equal([0, 1, 3, 2], a.insert(-2, 3))
|
||||
assert_raise(RuntimeError) { [0].freeze.insert(0)}
|
||||
|
|
Loading…
Add table
Reference in a new issue