mirror of
https://github.com/ruby/ruby.git
synced 2025-09-16 09:04:05 +02:00
* array.c (rb_ary_push_m, rb_ary_unshift_m, rb_ary_aset),
(rb_ary_insert, rb_ary_replace, rb_ary_concat), (rb_ary_uniq_bang, rb_ary_flatten_bang): check if frozen after wrong number of arguments but before TypeError. [ruby-core:28140] * hash.c (rb_hash_replace): ditto. * string.c (rb_str_replace): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26632 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
6942afef5f
commit
f3f43cdbee
7 changed files with 79 additions and 10 deletions
|
@ -539,6 +539,9 @@ class TestArray < Test::Unit::TestCase
|
|||
a = @cls[1, 2, 3]
|
||||
a.concat(a)
|
||||
assert_equal([1, 2, 3, 1, 2, 3], a)
|
||||
|
||||
assert_raise(TypeError) { [0].concat(:foo) }
|
||||
assert_raise(RuntimeError) { [0].freeze.concat(:foo) }
|
||||
end
|
||||
|
||||
def test_count
|
||||
|
@ -1033,6 +1036,13 @@ class TestArray < Test::Unit::TestCase
|
|||
assert_equal(@cls[4, 5, 6], a)
|
||||
assert_equal(a_id, a.__id__)
|
||||
assert_equal(@cls[], a.replace(@cls[]))
|
||||
|
||||
fa = a.dup.freeze
|
||||
assert_nothing_raised(RuntimeError) { a.replace(a) }
|
||||
assert_raise(RuntimeError) { fa.replace(fa) }
|
||||
assert_raise(ArgumentError) { fa.replace() }
|
||||
assert_raise(TypeError) { a.replace(42) }
|
||||
assert_raise(RuntimeError) { fa.replace(42) }
|
||||
end
|
||||
|
||||
def test_reverse
|
||||
|
@ -1325,6 +1335,11 @@ class TestArray < Test::Unit::TestCase
|
|||
assert_equal(@cls[ "a:def", "b:abc", "c:jkl" ], c)
|
||||
|
||||
assert_nil(@cls[1, 2, 3].uniq!)
|
||||
|
||||
f = a.dup.freeze
|
||||
assert_raise(ArgumentError) { a.uniq!(1) }
|
||||
assert_raise(ArgumentError) { f.uniq!(1) }
|
||||
assert_raise(RuntimeError) { f.uniq! }
|
||||
end
|
||||
|
||||
def test_unshift
|
||||
|
@ -1452,7 +1467,7 @@ class TestArray < Test::Unit::TestCase
|
|||
assert_equal([1, 1, 1], Array.new(3, 1) { 1 })
|
||||
end
|
||||
|
||||
def test_aset
|
||||
def test_aset_error
|
||||
assert_raise(IndexError) { [0][-2] = 1 }
|
||||
assert_raise(IndexError) { [0][LONGP] = 2 }
|
||||
assert_raise(IndexError) { [0][(LONGP + 1) / 2 - 1] = 2 }
|
||||
|
@ -1461,6 +1476,9 @@ class TestArray < Test::Unit::TestCase
|
|||
a[2] = 4
|
||||
assert_equal([0, nil, 4], a)
|
||||
assert_raise(ArgumentError) { [0][0, 0, 0] = 0 }
|
||||
assert_raise(ArgumentError) { [0].freeze[0, 0, 0] = 0 }
|
||||
assert_raise(TypeError) { [0][:foo] = 0 }
|
||||
assert_raise(RuntimeError) { [0].freeze[:foo] = 0 }
|
||||
end
|
||||
|
||||
def test_first2
|
||||
|
@ -1477,8 +1495,9 @@ class TestArray < Test::Unit::TestCase
|
|||
assert_equal([2, 3], a)
|
||||
end
|
||||
|
||||
def test_unshift2
|
||||
Struct.new(:a, :b, :c)
|
||||
def test_unshift_error
|
||||
assert_raise(RuntimeError) { [].freeze.unshift('cat') }
|
||||
assert_raise(RuntimeError) { [].freeze.unshift() }
|
||||
end
|
||||
|
||||
def test_aref
|
||||
|
@ -1537,6 +1556,8 @@ class TestArray < Test::Unit::TestCase
|
|||
assert_raise(ArgumentError) { a.insert }
|
||||
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)}
|
||||
assert_raise(ArgumentError) { [0].freeze.insert }
|
||||
end
|
||||
|
||||
def test_join2
|
||||
|
@ -1628,10 +1649,17 @@ class TestArray < Test::Unit::TestCase
|
|||
assert_not_equal([a, a].hash, a.hash) # Implementation dependent
|
||||
end
|
||||
|
||||
def test_flatten2
|
||||
def test_flatten_error
|
||||
a = []
|
||||
a << a
|
||||
assert_raise(ArgumentError) { a.flatten }
|
||||
|
||||
f = [].freeze
|
||||
assert_raise(ArgumentError) { a.flatten!(1, 2) }
|
||||
assert_raise(TypeError) { a.flatten!(:foo) }
|
||||
assert_raise(ArgumentError) { f.flatten!(1, 2) }
|
||||
assert_raise(RuntimeError) { f.flatten! }
|
||||
assert_raise(RuntimeError) { f.flatten!(:foo) }
|
||||
end
|
||||
|
||||
def test_shuffle
|
||||
|
@ -1756,7 +1784,7 @@ class TestArray < Test::Unit::TestCase
|
|||
assert_equal((1..10).to_a, a)
|
||||
end
|
||||
|
||||
def test_slice_freezed_array
|
||||
def test_slice_frozen_array
|
||||
a = [1,2,3,4,5].freeze
|
||||
assert_equal([1,2,3,4], a[0,4])
|
||||
assert_equal([2,3,4,5], a[1,4])
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue