mirror of
https://github.com/ruby/ruby.git
synced 2025-09-16 09:04:05 +02:00
* array.c (rb_ary_uniq_bang, rb_ary_uniq): unique by the result of
given block. [ruby-dev:37998] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22307 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e1646e639a
commit
766df600db
3 changed files with 89 additions and 18 deletions
|
@ -1240,6 +1240,11 @@ class TestArray < Test::Unit::TestCase
|
|||
assert_equal(@cls[1, 2, 3, 4, nil], a.uniq)
|
||||
assert_equal(b, a)
|
||||
|
||||
c = @cls["a:def", "a:xyz", "b:abc", "b:xyz", "c:jkl"]
|
||||
d = c.dup
|
||||
assert_equal(@cls[ "a:def", "b:abc", "c:jkl" ], c.uniq {|s| s[/^\w+/]})
|
||||
assert_equal(d, c)
|
||||
|
||||
assert_equal(@cls[1, 2, 3], @cls[1, 2, 3].uniq)
|
||||
end
|
||||
|
||||
|
@ -1248,6 +1253,10 @@ class TestArray < Test::Unit::TestCase
|
|||
assert_equal(@cls[1, 2, 3, 4, nil], a.uniq!)
|
||||
assert_equal(@cls[1, 2, 3, 4, nil], a)
|
||||
|
||||
c = @cls["a:def", "a:xyz", "b:abc", "b:xyz", "c:jkl"]
|
||||
assert_equal(@cls[ "a:def", "b:abc", "c:jkl" ], c.uniq! {|s| s[/^\w+/]})
|
||||
assert_equal(@cls[ "a:def", "b:abc", "c:jkl" ], c)
|
||||
|
||||
assert_nil(@cls[1, 2, 3].uniq!)
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue