summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-10-09 16:04:12 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-10-09 16:04:12 +0000
commit0a57e6c975559abf5e2f16d5042117da1d46f525 (patch)
tree0dc5aa378bf57dbf039200a63ca927e068043fd1 /test
parentf4811c7e2b8dcbb49c63772bc70026f170612ca2 (diff)
merge revision(s) 42040,42041,42047: [Backport #8654]
* array.c (rb_ary_count): iterate items appropriately. [Bug #8654] * array.c (rb_ary_count): check length to avoid SEGV while iterating. Remove other pointer loop when arg is given. * test/ruby/test_array.rb (test_count): add test for bug. [ruby-core:56072] [Bug #8654] * test/ruby/test_array.rb (test_count): add a test case for #count with an argument. See Bug #8654. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@43228 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_array.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb
index 71b514419f..a8c975e961 100644
--- a/test/ruby/test_array.rb
+++ b/test/ruby/test_array.rb
@@ -576,6 +576,28 @@ class TestArray < Test::Unit::TestCase
assert_equal(3, a.count {|x| x % 2 == 1 })
assert_equal(2, a.count(1) {|x| x % 2 == 1 })
assert_raise(ArgumentError) { a.count(0, 1) }
+
+ bug8654 = '[ruby-core:56072]'
+ assert_in_out_err [], <<-EOS, ["0"], [], bug8654
+ a1 = []
+ a2 = Array.new(100) { |i| i }
+ r = a2.count do |i|
+ p i
+ a2.replace(a1) if i == 0
+ end
+ EOS
+
+ assert_in_out_err [], <<-EOS, ["[]", "0"], [], bug8654
+ ARY = Array.new(100) { |i| i }
+ class Fixnum
+ def == other
+ ARY.replace([]) if self.equal?(0)
+ p ARY
+ self.equal?(other)
+ end
+ end
+ p ARY.count(42)
+ EOS
end
def test_delete