diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-03-20 05:17:19 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2010-03-20 05:17:19 +0000 |
commit | 4b6a7a46e8f68ca77f8741cecc3108632bf34c9f (patch) | |
tree | ff090dfd5767ed59520bb3d0e80c64ca7a40519c /test/ruby/test_array.rb | |
parent | 9ce419a45c521d8c41773ad29cb9ccec3be05028 (diff) |
add tests.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@26988 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_array.rb')
-rw-r--r-- | test/ruby/test_array.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index 69d3f1d75c..8208b3a2a4 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -1345,6 +1345,26 @@ class TestArray < Test::Unit::TestCase assert_equal(@cls[1, 2, 3], @cls[1, 2, 3].uniq) end + def test_uniq_with_block + a = [] + b = a.uniq {|v| v.even? } + assert_equal([], a) + assert_equal([], b) + assert_not_same(a, b) + + a = [1] + b = a.uniq {|v| v.even? } + assert_equal([1], a) + assert_equal([1], b) + assert_not_same(a, b) + + a = [1,3] + b = a.uniq {|v| v.even? } + assert_equal([1,3], a) + assert_equal([1], b) + assert_not_same(a, b) + end + def test_uniq! a = [] b = a.uniq! @@ -1385,6 +1405,27 @@ class TestArray < Test::Unit::TestCase assert_raise(RuntimeError) { f.uniq! } end + def test_uniq_bang_with_block + a = [] + b = a.uniq! {|v| v.even? } + assert_equal(nil, b) + + a = [1] + b = a.uniq! {|v| v.even? } + assert_equal(nil, b) + + a = [1,3] + b = a.uniq! {|v| v.even? } + assert_equal([1], a) + assert_equal([1], b) + assert_same(a, b) + + a = [1,2] + b = a.uniq! {|v| v.even? } + assert_equal([1,2], a) + assert_equal(nil, b) + end + def test_unshift a = @cls[] assert_equal(@cls['cat'], a.unshift('cat')) |