summaryrefslogtreecommitdiff
path: root/test/ruby/test_array.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_array.rb')
-rw-r--r--test/ruby/test_array.rb391
1 files changed, 112 insertions, 279 deletions
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb
index f2956a7fba..3212ed3aca 100644
--- a/test/ruby/test_array.rb
+++ b/test/ruby/test_array.rb
@@ -41,9 +41,6 @@ class TestArray < Test::Unit::TestCase
assert_equal(2, x[2])
assert_equal([1, 2, 3], x[1..3])
assert_equal([1, 2, 3], x[1,3])
- assert_equal([3, 4, 5], x[3..])
- assert_equal([0, 1, 2], x[..2])
- assert_equal([0, 1], x[...2])
x[0, 2] = 10
assert_equal([10, 2, 3, 4, 5], x)
@@ -148,17 +145,14 @@ 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))
@@ -167,7 +161,6 @@ 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))
@@ -177,7 +170,6 @@ class TestArray < Test::Unit::TestCase
def test_find_all_0
assert_respond_to([], :find_all)
assert_respond_to([], :select) # Alias
- assert_respond_to([], :filter) # Alias
assert_equal([], [].find_all{ |obj| obj == "foo"})
x = ["foo", "bar", "baz", "baz", 1, 2, 3, 3, 4]
@@ -206,8 +198,6 @@ class TestArray < Test::Unit::TestCase
assert_equal([0, 1, 2, 13, 4, 5], [0, 1, 2, 3, 4, 5].fill(3...4){|i| i+10})
assert_equal([0, 1, 12, 13, 14, 5], [0, 1, 2, 3, 4, 5].fill(2..-2){|i| i+10})
assert_equal([0, 1, 12, 13, 4, 5], [0, 1, 2, 3, 4, 5].fill(2...-2){|i| i+10})
- assert_equal([0, 1, 2, 13, 14, 15], [0, 1, 2, 3, 4, 5].fill(3..){|i| i+10})
- assert_equal([0, 1, 2, 13, 14, 15], [0, 1, 2, 3, 4, 5].fill(3...){|i| i+10})
end
# From rubicon
@@ -241,23 +231,6 @@ class TestArray < Test::Unit::TestCase
assert_equal(@cls[], @cls[ 1, 2, 3 ]*64 & @cls[ 4, 5, 6 ]*64)
end
- def test_intersection
- assert_equal(@cls[1, 2], @cls[1, 2, 3].intersection(@cls[1, 2]))
- assert_equal(@cls[ ], @cls[1].intersection(@cls[ ]))
- assert_equal(@cls[ ], @cls[ ].intersection(@cls[1]))
- assert_equal(@cls[1], @cls[1, 2, 3].intersection(@cls[1, 2], @cls[1]))
- assert_equal(@cls[ ], @cls[1, 2, 3].intersection(@cls[1, 2], @cls[3]))
- assert_equal(@cls[ ], @cls[1, 2, 3].intersection(@cls[4, 5, 6]))
- end
-
- def test_intersection_big_array
- assert_equal(@cls[1, 2], (@cls[1, 2, 3] * 64).intersection(@cls[1, 2] * 64))
- assert_equal(@cls[ ], (@cls[1] * 64).intersection(@cls[ ]))
- assert_equal(@cls[ ], @cls[ ].intersection(@cls[1] * 64))
- assert_equal(@cls[1], (@cls[1, 2, 3] * 64).intersection((@cls[1, 2] * 64), (@cls[1] * 64)))
- assert_equal(@cls[ ], (@cls[1, 2, 3] * 64).intersection(@cls[4, 5, 6] * 64))
- end
-
def test_MUL # '*'
assert_equal(@cls[], @cls[]*3)
assert_equal(@cls[1, 1, 1], @cls[1]*3)
@@ -281,39 +254,29 @@ class TestArray < Test::Unit::TestCase
def test_MINUS # '-'
assert_equal(@cls[], @cls[1] - @cls[1])
assert_equal(@cls[1], @cls[1, 2, 3, 4, 5] - @cls[2, 3, 4, 5])
+ # Ruby 1.8 feature change
+ #assert_equal(@cls[1], @cls[1, 2, 1, 3, 1, 4, 1, 5] - @cls[2, 3, 4, 5])
assert_equal(@cls[1, 1, 1, 1], @cls[1, 2, 1, 3, 1, 4, 1, 5] - @cls[2, 3, 4, 5])
+ a = @cls[]
+ 1000.times { a << 1 }
+ assert_equal(1000, a.length)
+ #assert_equal(@cls[1], a - @cls[2])
+ assert_equal(@cls[1] * 1000, a - @cls[2])
+ #assert_equal(@cls[1], @cls[1, 2, 1] - @cls[2])
assert_equal(@cls[1, 1], @cls[1, 2, 1] - @cls[2])
assert_equal(@cls[1, 2, 3], @cls[1, 2, 3] - @cls[4, 5, 6])
end
def test_MINUS_big_array # '-'
assert_equal(@cls[1]*64, @cls[1, 2, 3, 4, 5]*64 - @cls[2, 3, 4, 5]*64)
+ # Ruby 1.8 feature change
+ #assert_equal(@cls[1], @cls[1, 2, 1, 3, 1, 4, 1, 5]*64 - @cls[2, 3, 4, 5]*64)
assert_equal(@cls[1, 1, 1, 1]*64, @cls[1, 2, 1, 3, 1, 4, 1, 5]*64 - @cls[2, 3, 4, 5]*64)
a = @cls[]
1000.times { a << 1 }
assert_equal(1000, a.length)
- assert_equal(@cls[1] * 1000, a - @cls[2])
- end
-
- def test_difference
- assert_equal(@cls[], @cls[1].difference(@cls[1]))
- assert_equal(@cls[1], @cls[1, 2, 3, 4, 5].difference(@cls[2, 3, 4, 5]))
- assert_equal(@cls[1, 1], @cls[1, 2, 1].difference(@cls[2]))
- assert_equal(@cls[1, 1, 1, 1], @cls[1, 2, 1, 3, 1, 4, 1, 5].difference(@cls[2, 3, 4, 5]))
- assert_equal(@cls[], @cls[1, 2, 3, 4].difference(@cls[1], @cls[2], @cls[3], @cls[4]))
- a = [1]
- assert_equal(@cls[1], a.difference(@cls[2], @cls[2]))
- assert_equal(@cls[], a.difference(@cls[1]))
- assert_equal(@cls[1], a)
- end
-
- def test_difference_big_array
- assert_equal(@cls[1]*64, (@cls[1, 2, 3, 4, 5] * 64).difference(@cls[2, 3, 4] * 64, @cls[3, 5] * 64))
- assert_equal(@cls[1, 1, 1, 1]*64, (@cls[1, 2, 1, 3, 1, 4, 1, 5] * 64).difference(@cls[2, 3, 4, 5] * 64))
- a = @cls[1] * 1000
- assert_equal(@cls[1] * 1000, a.difference(@cls[2], @cls[2]))
- assert_equal(@cls[], a.difference(@cls[1]))
- assert_equal(@cls[1] * 1000, a)
+ #assert_equal(@cls[1], a - @cls[2])
+ assert_equal(@cls[1] * 1000, a - @cls[2])
end
def test_LSHIFT # '<<'
@@ -389,15 +352,12 @@ class TestArray < Test::Unit::TestCase
assert_equal(@cls[99], a[-2..-2])
assert_equal(@cls[10, 11, 12], a[9..11])
- assert_equal(@cls[98, 99, 100], a[97..])
- assert_equal(@cls[1, 2, 3], a[..2])
- assert_equal(@cls[1, 2], a[...2])
assert_equal(@cls[10, 11, 12], a[-91..-89])
- assert_equal(@cls[98, 99, 100], a[-3..])
- assert_equal(@cls[1, 2, 3], a[..-98])
- assert_equal(@cls[1, 2], a[...-98])
assert_nil(a[10, -3])
+ # Ruby 1.8 feature change:
+ # Array#[size..x] returns [] instead of nil.
+ #assert_nil(a[10..7])
assert_equal [], a[10..7]
assert_raise(TypeError) {a['cat']}
@@ -453,41 +413,33 @@ class TestArray < Test::Unit::TestCase
assert_equal(b, a[10..19] = b)
assert_equal(@cls[*(0..9).to_a] + b + @cls[*(20..99).to_a], a)
+ # Ruby 1.8 feature change:
+ # assigning nil does not remove elements.
+=begin
a = @cls[*(0..99).to_a]
assert_equal(nil, a[0,1] = nil)
- assert_equal(@cls[nil] + @cls[*(1..99).to_a], a)
+ assert_equal(@cls[*(1..99).to_a], a)
a = @cls[*(0..99).to_a]
assert_equal(nil, a[10,10] = nil)
- assert_equal(@cls[*(0..9).to_a] + @cls[nil] + @cls[*(20..99).to_a], a)
+ assert_equal(@cls[*(0..9).to_a] + @cls[*(20..99).to_a], a)
a = @cls[*(0..99).to_a]
assert_equal(nil, a[-1, 1] = nil)
- assert_equal(@cls[*(0..98).to_a] + @cls[nil], a)
+ assert_equal(@cls[*(0..98).to_a], a)
a = @cls[*(0..99).to_a]
assert_equal(nil, a[-10, 10] = nil)
- assert_equal(@cls[*(0..89).to_a] + @cls[nil], a)
+ assert_equal(@cls[*(0..89).to_a], a)
a = @cls[*(0..99).to_a]
assert_equal(nil, a[0,1000] = nil)
- assert_equal(@cls[nil] , a)
+ assert_equal(@cls[] , a)
a = @cls[*(0..99).to_a]
assert_equal(nil, a[10..19] = nil)
- assert_equal(@cls[*(0..9).to_a] + @cls[nil] + @cls[*(20..99).to_a], a)
-
- a = @cls[*(0..99).to_a]
- assert_equal(nil, a[10..] = nil)
- assert_equal(@cls[*(0..9).to_a] + @cls[nil], a)
-
- a = @cls[*(0..99).to_a]
- assert_equal(nil, a[..10] = nil)
- assert_equal(@cls[nil] + @cls[*(11..99).to_a], a)
-
- a = @cls[*(0..99).to_a]
- assert_equal(nil, a[...10] = nil)
- assert_equal(@cls[nil] + @cls[*(10..99).to_a], a)
+ assert_equal(@cls[*(0..9).to_a] + @cls[*(20..99).to_a], a)
+=end
a = @cls[1, 2, 3]
a[1, 0] = a
@@ -556,14 +508,18 @@ class TestArray < Test::Unit::TestCase
end
def test_clone
- for frozen in [ false, true ]
- a = @cls[*(0..99).to_a]
- a.freeze if frozen
- b = a.clone
-
- assert_equal(a, b)
- assert_not_equal(a.__id__, b.__id__)
- assert_equal(a.frozen?, b.frozen?)
+ for taint in [ false, true ]
+ for frozen in [ false, true ]
+ a = @cls[*(0..99).to_a]
+ a.taint if taint
+ a.freeze if frozen
+ b = a.clone
+
+ assert_equal(a, b)
+ assert_not_equal(a.__id__, b.__id__)
+ assert_equal(a.frozen?, b.frozen?)
+ assert_equal(a.tainted?, b.tainted?)
+ end
end
end
@@ -574,11 +530,12 @@ class TestArray < Test::Unit::TestCase
assert_equal([], @cls[].collect { 99 })
+ # Ruby 1.9 feature change:
+ # Enumerable#collect without block returns an Enumerator.
+ #assert_equal([1, 2, 3], @cls[1, 2, 3].collect)
assert_kind_of Enumerator, @cls[1, 2, 3].collect
- assert_raise(ArgumentError) {
- assert_equal([[1, 2, 3]], [[1, 2, 3]].collect(&->(a, b, c) {[a, b, c]}))
- }
+ assert_equal([[1, 2, 3]], [[1, 2, 3]].collect(&->(a, b, c) {[a, b, c]}))
end
# also update map!
@@ -750,14 +707,18 @@ class TestArray < Test::Unit::TestCase
end
def test_dup
- for frozen in [ false, true ]
- a = @cls[*(0..99).to_a]
- a.freeze if frozen
- b = a.dup
-
- assert_equal(a, b)
- assert_not_equal(a.__id__, b.__id__)
- assert_equal(false, b.frozen?)
+ for taint in [ false, true ]
+ for frozen in [ false, true ]
+ a = @cls[*(0..99).to_a]
+ a.taint if taint
+ a.freeze if frozen
+ b = a.dup
+
+ assert_equal(a, b)
+ assert_not_equal(a.__id__, b.__id__)
+ assert_equal(false, b.frozen?)
+ assert_equal(a.tainted?, b.tainted?)
+ end
end
end
@@ -773,7 +734,7 @@ class TestArray < Test::Unit::TestCase
a = @cls[]
i = 0
a.each { |e|
- assert(false, "Never get here")
+ assert_equal(a[i], e)
i += 1
}
assert_equal(0, i)
@@ -793,7 +754,7 @@ class TestArray < Test::Unit::TestCase
a = @cls[]
i = 0
a.each_index { |ind|
- assert(false, "Never get here")
+ assert_equal(i, ind)
i += 1
}
assert_equal(0, i)
@@ -857,6 +818,13 @@ class TestArray < Test::Unit::TestCase
assert_raise(TypeError, "[ruby-dev:31197]") { [[]].flatten("") }
end
+ def test_flatten_taint
+ a6 = @cls[[1, 2], 3]
+ a6.taint
+ a7 = a6.flatten
+ assert_equal(true, a7.tainted?)
+ end
+
def test_flatten_level0
a8 = @cls[[1, 2], 3]
a9 = a8.flatten(0)
@@ -886,17 +854,6 @@ class TestArray < Test::Unit::TestCase
assert_raise(NoMethodError, bug12738) { a.flatten.m }
end
- def test_flatten_recursive
- a = []
- a << a
- assert_raise(ArgumentError) { a.flatten }
- b = [1]; c = [2, b]; b << c
- assert_raise(ArgumentError) { b.flatten }
-
- assert_equal([1, 2, b], b.flatten(1))
- assert_equal([1, 2, 1, 2, 1, c], b.flatten(4))
- end
-
def test_flatten!
a1 = @cls[ 1, 2, 3]
a2 = @cls[ 5, 6 ]
@@ -1128,6 +1085,20 @@ class TestArray < Test::Unit::TestCase
assert_equal("1,2,3", a.join(','))
$, = ""
+ a = @cls[1, 2, 3]
+ a.taint
+ s = a.join
+ assert_equal(true, s.tainted?)
+
+ bug5902 = '[ruby-core:42161]'
+ sep = ":".taint
+
+ s = @cls[].join(sep)
+ assert_equal(false, s.tainted?, bug5902)
+ s = @cls[1].join(sep)
+ assert_equal(false, s.tainted?, bug5902)
+ s = @cls[1, 2].join(sep)
+ assert_equal(true, s.tainted?, bug5902)
e = ''.force_encoding('EUC-JP')
u = ''.force_encoding('UTF-8')
@@ -1278,6 +1249,9 @@ class TestArray < Test::Unit::TestCase
a = @cls[1, 2, 3]
assert_equal(@cls[1, 2, 3, 4, 5], a.push(4, 5))
assert_equal(@cls[1, 2, 3, 4, 5, nil], a.push(nil))
+ # Ruby 1.8 feature:
+ # Array#push accepts any number of arguments.
+ #assert_raise(ArgumentError, "a.push()") { a.push() }
a.push
assert_equal @cls[1, 2, 3, 4, 5, nil], a
a.push 6, 7
@@ -1403,6 +1377,9 @@ class TestArray < Test::Unit::TestCase
a = @cls[*%w( dog cat bee ant )]
assert_equal(@cls[*%w(ant bee cat dog)], a.reverse!)
assert_equal(@cls[*%w(ant bee cat dog)], a)
+ # Ruby 1.8 feature change:
+ # Array#reverse always returns self.
+ #assert_nil(@cls[].reverse!)
assert_equal @cls[], @cls[].reverse!
end
@@ -1433,16 +1410,6 @@ class TestArray < Test::Unit::TestCase
assert_nil(a.rindex([1,2]))
assert_equal(3, a.rindex(99) {|x| x == [1,2,3] })
-
- bug15951 = "[Bug #15951]"
- o2 = Object.new
- def o2.==(other)
- other.replace([]) if Array === other
- false
- end
- a = Array.new(10)
- a.fill(o2)
- assert_nil(a.rindex(a), bug15951)
end
def test_shift
@@ -1492,14 +1459,14 @@ class TestArray < Test::Unit::TestCase
assert_equal(@cls[99], a.slice(-2..-2))
assert_equal(@cls[10, 11, 12], a.slice(9..11))
- assert_equal(@cls[98, 99, 100], a.slice(97..))
- assert_equal(@cls[10, 11, 12], a.slice(-91..-89))
assert_equal(@cls[10, 11, 12], a.slice(-91..-89))
assert_nil(a.slice(-101..-1))
- assert_nil(a.slice(-101..))
assert_nil(a.slice(10, -3))
+ # Ruby 1.8 feature change:
+ # Array#slice[size..x] always returns [].
+ #assert_nil(a.slice(10..7))
assert_equal @cls[], a.slice(10..7)
end
@@ -1540,8 +1507,6 @@ class TestArray < Test::Unit::TestCase
assert_equal(nil, a.slice!(-6,2))
assert_equal(@cls[1, 2, 3, 4, 5], a)
- assert_equal("[2, 3]", [1,2,3].slice!(1,10000).inspect, "moved from btest/knownbug")
-
assert_raise(ArgumentError) { @cls[1].slice! }
assert_raise(ArgumentError) { @cls[1].slice!(0, 0, 0) }
end
@@ -1605,21 +1570,13 @@ class TestArray < Test::Unit::TestCase
end
def test_sort_with_replace
- bug = '[ruby-core:34732]'
- assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}", timeout: 30)
- bug = "#{bug}"
- begin;
- xary = (1..100).to_a
- 100.times do
- ary = (1..100).to_a
- ary.sort! {|a,b| ary.replace(xary); a <=> b}
- GC.start
- assert_equal(xary, ary, '[ruby-dev:34732]')
- end
- assert_nothing_raised(SystemStackError, bug) do
- assert_equal(:ok, Array.new(100_000, nil).permutation {break :ok})
- end
- end;
+ xary = (1..100).to_a
+ 100.times do
+ ary = (1..100).to_a
+ ary.sort! {|a,b| ary.replace(xary); a <=> b}
+ GC.start
+ assert_equal(xary, ary, '[ruby-dev:34732]')
+ end
end
def test_sort_bang_with_freeze
@@ -1675,7 +1632,7 @@ class TestArray < Test::Unit::TestCase
def o.to_ary
foo_bar()
end
- assert_raise_with_message(NoMethodError, /foo_bar/) {a.concat(o)}
+ assert_match(/foo_bar/, assert_raise(NoMethodError) {a.concat(o)}.message)
end
def test_to_s
@@ -1698,17 +1655,15 @@ class TestArray < Test::Unit::TestCase
$, = nil
end
- StubToH = [
- [:key, :value],
- Object.new.tap do |kvp|
- def kvp.to_ary
- [:obtained, :via_to_ary]
- end
- end,
- ]
-
def test_to_h
- array = StubToH
+ kvp = Object.new
+ def kvp.to_ary
+ [:obtained, :via_to_ary]
+ end
+ array = [
+ [:key, :value],
+ kvp,
+ ]
assert_equal({key: :value, obtained: :via_to_ary}, array.to_h)
e = assert_raise(TypeError) {
@@ -1723,27 +1678,6 @@ class TestArray < Test::Unit::TestCase
assert_equal "wrong array length at 2 (expected 2, was 1)", e.message
end
- def test_to_h_block
- array = StubToH
- assert_equal({"key" => "value", "obtained" => "via_to_ary"},
- array.to_h {|k, v| [k.to_s, v.to_s]})
-
- assert_equal({first_one: :ok, not_ok: :ng},
- [[:first_one, :ok], :not_ok].to_h {|k, v| [k, v || :ng]})
-
- e = assert_raise(TypeError) {
- [[:first_one, :ok], :not_ok].to_h {|k, v| v ? [k, v] : k}
- }
- assert_equal "wrong element type Symbol at 1 (expected array)", e.message
- array = [1]
- k = eval("class C\u{1f5ff}; self; end").new
- assert_raise_with_message(TypeError, /C\u{1f5ff}/) {array.to_h {k}}
- e = assert_raise(ArgumentError) {
- [[:first_one, :ok], [1, 2], [:not_ok]].to_h {|kv| kv}
- }
- assert_equal "wrong array length at 2 (expected 2, was 1)", e.message
- end
-
def test_min
assert_equal(1, [1, 2, 3, 1, 2].min)
assert_equal(3, [1, 2, 3, 1, 2].min {|a,b| b <=> a })
@@ -1787,25 +1721,6 @@ class TestArray < Test::Unit::TestCase
assert_same(obj, [obj, 1.0].max)
end
- def test_minmax
- assert_equal([1, 3], [1, 2, 3, 1, 2].minmax)
- assert_equal([3, 1], [1, 2, 3, 1, 2].minmax {|a,b| b <=> a })
- cond = ->((a, ia), (b, ib)) { (b <=> a).nonzero? or ia <=> ib }
- assert_equal([[3, 2], [1, 3]], [1, 2, 3, 1, 2].each_with_index.minmax(&cond))
- ary = %w(albatross dog horse)
- assert_equal(["albatross", "horse"], ary.minmax)
- assert_equal(["dog", "albatross"], ary.minmax {|a,b| a.length <=> b.length })
- assert_equal([1, 3], [3,2,1].minmax)
-
- class << (obj = Object.new)
- def <=>(x) 1 <=> x end
- def coerce(x) [x, 1] end
- end
- ary = [obj, 1.0].minmax
- assert_same(obj, ary[0])
- assert_equal(obj, ary[1])
- end
-
def test_uniq
a = []
b = a.uniq
@@ -1854,31 +1769,6 @@ class TestArray < Test::Unit::TestCase
ary = [bug9340, bug9340.dup, bug9340.dup]
assert_equal 1, ary.uniq.size
assert_same bug9340, ary.uniq[0]
-
- sc = Class.new(@cls)
- a = sc[]
- b = a.dup
- assert_instance_of(sc, a.uniq)
- assert_equal(sc[], a.uniq)
- assert_equal(b, a)
-
- a = sc[1]
- b = a.dup
- assert_instance_of(sc, a.uniq)
- assert_equal(sc[1], a.uniq)
- assert_equal(b, a)
-
- a = sc[1, 1]
- b = a.dup
- assert_instance_of(sc, a.uniq)
- assert_equal(sc[1], a.uniq)
- assert_equal(b, a)
-
- a = sc[1, 1]
- b = a.dup
- assert_instance_of(sc, a.uniq{|x| x})
- assert_equal(sc[1], a.uniq{|x| x})
- assert_equal(b, a)
end
def test_uniq_with_block
@@ -2075,44 +1965,6 @@ class TestArray < Test::Unit::TestCase
assert_equal((1..128).to_a, b)
end
- def test_union
- assert_equal(@cls[], @cls[].union(@cls[]))
- assert_equal(@cls[1], @cls[1].union(@cls[]))
- assert_equal(@cls[1], @cls[].union(@cls[1]))
- assert_equal(@cls[1], @cls[].union(@cls[], @cls[1]))
- assert_equal(@cls[1], @cls[1].union(@cls[1]))
- assert_equal(@cls[1], @cls[1].union(@cls[1], @cls[1], @cls[1]))
-
- assert_equal(@cls[1,2], @cls[1].union(@cls[2]))
- assert_equal(@cls[1,2], @cls[1, 1].union(@cls[2, 2]))
- assert_equal(@cls[1,2], @cls[1, 2].union(@cls[1, 2]))
- assert_equal(@cls[1,2], @cls[1, 1].union(@cls[1, 1], @cls[1, 2], @cls[2, 1], @cls[2, 2, 2]))
-
- a = %w(a b c)
- b = %w(a b c d e)
- c = a.union(b)
- assert_equal(c, b)
- assert_not_same(c, b)
- assert_equal(%w(a b c), a)
- assert_equal(%w(a b c d e), b)
- assert(a.none?(&:frozen?))
- assert(b.none?(&:frozen?))
- assert(c.none?(&:frozen?))
- end
-
- def test_union_big_array
- assert_equal(@cls[1,2], (@cls[1]*64).union(@cls[2]*64))
- assert_equal(@cls[1,2,3], (@cls[1, 2]*64).union(@cls[1, 2]*64, @cls[3]*60))
-
- a = (1..64).to_a
- b = (1..128).to_a
- c = a | b
- assert_equal(c, b)
- assert_not_same(c, b)
- assert_equal((1..64).to_a, a)
- assert_equal((1..128).to_a, b)
- end
-
def test_combination
a = @cls[]
assert_equal(1, a.combination(0).size)
@@ -2347,7 +2199,6 @@ class TestArray < Test::Unit::TestCase
assert_raise(IndexError) { [0][LONGP] = 2 }
assert_raise(IndexError) { [0][(LONGP + 1) / 2 - 1] = 2 }
assert_raise(IndexError) { [0][LONGP..-1] = 2 }
- assert_raise(IndexError) { [0][LONGP..] = 2 }
a = [0]
a[2] = 4
assert_equal([0, nil, 4], a)
@@ -2385,7 +2236,6 @@ class TestArray < Test::Unit::TestCase
def test_aref
assert_raise(ArgumentError) { [][0, 0, 0] }
- assert_raise(TypeError) { [][(1..10).step(2)] }
end
def test_fetch
@@ -2523,25 +2373,6 @@ class TestArray < Test::Unit::TestCase
assert_equal(@cls[4, 5], a)
end
- def test_filter
- assert_equal([0, 2], [0, 1, 2, 3].filter {|x| x % 2 == 0 })
- end
-
- # alias for select!
- def test_filter!
- a = @cls[ 1, 2, 3, 4, 5 ]
- assert_equal(nil, a.filter! { true })
- assert_equal(@cls[1, 2, 3, 4, 5], a)
-
- a = @cls[ 1, 2, 3, 4, 5 ]
- assert_equal(a, a.filter! { false })
- assert_equal(@cls[], a)
-
- a = @cls[ 1, 2, 3, 4, 5 ]
- assert_equal(a, a.filter! { |i| i > 3 })
- assert_equal(@cls[4, 5], a)
- end
-
def test_delete2
a = [0] * 1024 + [1] + [0] * 1024
a.delete(0)
@@ -2635,6 +2466,9 @@ class TestArray < Test::Unit::TestCase
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) }
@@ -2878,6 +2712,13 @@ class TestArray < Test::Unit::TestCase
assert_equal(Array2, Array2[*(1..100)][1..99].class) #not embedded
end
+ def test_inspect
+ a = @cls[1, 2, 3]
+ a.taint
+ s = a.inspect
+ assert_equal(true, s.tainted?)
+ end
+
def test_initialize2
a = [1] * 1000
a.instance_eval { initialize }
@@ -3081,7 +2922,7 @@ class TestArray < Test::Unit::TestCase
Bug11235 = '[ruby-dev:49043] [Bug #11235]'
def test_push_over_ary_max
- assert_separately(['-', ARY_MAX.to_s, Bug11235], "#{<<~"begin;"}\n#{<<~'end;'}", timeout: 120)
+ assert_separately(['-', ARY_MAX.to_s, Bug11235], "#{<<~"begin;"}\n#{<<~'end;'}", timeout: 30)
begin;
a = Array.new(ARGV[0].to_i)
assert_raise(IndexError, ARGV[1]) {0x1000.times {a.push(1)}}
@@ -3202,14 +3043,6 @@ class TestArray < Test::Unit::TestCase
assert_raise(TypeError) {[1].sum("")}
end
- def test_big_array_literal_with_kwsplat
- lit = "["
- 10000.times { lit << "{}," }
- lit << "**{}]"
-
- assert_equal(10000, eval(lit).size)
- end
-
private
def need_continuation
unless respond_to?(:callcc, true)