2018-03-04 10:09:32 -05:00
|
|
|
require_relative '../../spec_helper'
|
|
|
|
require_relative 'fixtures/classes'
|
2018-12-28 19:22:52 -05:00
|
|
|
require_relative 'shared/union'
|
2017-05-07 08:04:49 -04:00
|
|
|
|
|
|
|
describe "Array#|" do
|
2018-12-28 19:22:52 -05:00
|
|
|
it_behaves_like :array_binary_union, :|
|
|
|
|
end
|
2017-05-07 08:04:49 -04:00
|
|
|
|
2018-12-28 19:22:52 -05:00
|
|
|
ruby_version_is "2.6" do
|
|
|
|
describe "Array#union" do
|
|
|
|
it_behaves_like :array_binary_union, :union
|
2017-05-07 08:04:49 -04:00
|
|
|
|
2018-12-28 19:22:52 -05:00
|
|
|
it "returns unique elements when given no argument" do
|
|
|
|
x = [1, 2, 3, 2]
|
|
|
|
x.union.should == [1, 2, 3]
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
2018-12-28 19:22:52 -05:00
|
|
|
it "does not return subclass instances for Array subclasses" do
|
|
|
|
ArraySpecs::MyArray[1, 2, 3].union.should be_an_instance_of(Array)
|
|
|
|
end
|
2017-05-07 08:04:49 -04:00
|
|
|
|
2018-12-28 19:22:52 -05:00
|
|
|
it "accepts multiple arguments" do
|
|
|
|
x = [1, 2, 3]
|
|
|
|
x.union(x, x, x, x, [3, 4], x).should == [1, 2, 3, 4]
|
|
|
|
end
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
end
|