aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--test/ruby/test_array.rb41
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'))