summaryrefslogtreecommitdiff
path: root/test/ruby/test_array.rb
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-07-15 14:03:28 -0700
committerJeremy Evans <code@jeremyevans.net>2019-09-02 13:42:31 -0700
commit1994adf938afcdc562f87497156e6d4900f3f06b (patch)
tree12cb5d84f7b2f6779703bc55150357e50bd41bbb /test/ruby/test_array.rb
parenta848b62819c78e12c420b1ed29605242e292358b (diff)
Make Array#uniq return subclass instance if called on subclass instance
Previously, Array#uniq would return subclass instance if the length of the array were 2 or greater, and would return Array instance if the length of the array were 0 or 1. Fixes [Bug #7768]
Diffstat (limited to 'test/ruby/test_array.rb')
-rw-r--r--test/ruby/test_array.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb
index 05f48abc8e..335c2dc042 100644
--- a/test/ruby/test_array.rb
+++ b/test/ruby/test_array.rb
@@ -1855,6 +1855,31 @@ 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