Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions core/set/classify_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,10 @@
classified = @set.classify { |x| x.length }
classified.should == { 3 => Set["one", "two"], 4 => Set["four"], 5 => Set["three"] }
end

it "does not retain compare_by_identity flag" do
set = Set["one", "two"].compare_by_identity
classified = set.classify { |x| x.length }
classified.values.each { |s| s.compare_by_identity?.should == false }
end
end
6 changes: 6 additions & 0 deletions core/set/divide_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
ret.should.is_a?(Enumerator)
ret.each(&:even?).should == Set[Set[1, 3], Set[2, 4]]
end

it "does not retain compare_by_identity flag" do
set = Set["one", "two"].compare_by_identity
res = set.divide { |x| x.length }
res.each { |s| s.compare_by_identity?.should == false }
end
end

describe "Set#divide when passed a block with an arity of 2" do
Expand Down
15 changes: 15 additions & 0 deletions core/set/exclusion_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,19 @@
-> { @set ^ 3 }.should.raise(ArgumentError)
-> { @set ^ Object.new }.should.raise(ArgumentError)
end

ruby_version_is ""..."4.0" do
it "does not retain compare_by_identity flag" do
@set.compare_by_identity
(@set ^ Set[3, 4, 5]).compare_by_identity?.should == false
(@set ^ [3, 4, 5]).compare_by_identity?.should == false
end
end
ruby_version_is "4.0" do
it "retains compare_by_identity flag" do
@set.compare_by_identity
(@set ^ Set[3, 4, 5]).compare_by_identity?.should == true
(@set ^ [3, 4, 5]).compare_by_identity?.should == true
end
end
end
17 changes: 17 additions & 0 deletions core/set/flatten_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
end
end
end

it "does not retain compare_by_identity flag" do
set = Set[1, 2, Set[3, 4]].compare_by_identity
set.flatten.compare_by_identity?.should == false
end
end

describe "Set#flatten!" do
Expand All @@ -46,4 +51,16 @@
(set = Set[]) << set
-> { set.flatten! }.should.raise(ArgumentError)
end

it "does not retain compare_by_identity flag when flattening elements" do
set = Set[1, 2, Set[3, 4]].compare_by_identity
set.flatten!
set.compare_by_identity?.should == false
end

it "retains compare_by_identity flag if no elements are flattened" do
set = Set[1, 2].compare_by_identity
set.flatten!
set.compare_by_identity?.should == true
end
end
6 changes: 6 additions & 0 deletions core/set/intersection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@
-> { @set & 1 }.should.raise(ArgumentError)
-> { @set & Object.new }.should.raise(ArgumentError)
end

it "does not retain compare_by_identity flag" do
@set.compare_by_identity
(@set & Set[:b, :c, :d, :e]).compare_by_identity?.should == false
(@set & [:b, :c, :d]).compare_by_identity?.should == false
end
end
6 changes: 6 additions & 0 deletions core/set/map_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@
@set.map! { |x| x * 2 }
@set.should == Set[2, 4, 6, 8, 10]
end

it "does not retain compare_by_identity flag" do
@set.compare_by_identity
@set.map! { |x| x * 2 }
@set.compare_by_identity?.should == false
end
end
10 changes: 10 additions & 0 deletions core/set/merge_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,14 @@
it "accepts multiple arguments" do
Set[:a, :b].merge(Set[:b, :c], [:d]).should == Set[:a, :b, :c, :d]
end

it "retains compare_by_identity flag" do
set = Set[1, 2].compare_by_identity
set.merge([3, 4])
set.compare_by_identity?.should == true

set2 = Set[1, 2].compare_by_identity
set2.merge(Set[3, 4])
set2.compare_by_identity?.should == true
end
end
6 changes: 6 additions & 0 deletions core/set/minus_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@
-> { @set - 1 }.should.raise(ArgumentError)
-> { @set - Object.new }.should.raise(ArgumentError)
end

it "retains compare_by_identity flag" do
@set.compare_by_identity
(@set - Set[:a, :b]).compare_by_identity?.should == true
(@set - [:a, :b]).compare_by_identity?.should == true
end
end
18 changes: 18 additions & 0 deletions core/set/replace_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,22 @@
it "accepts any enumerable as other" do
@set.replace([1, 2, 3]).should == Set[1, 2, 3]
end

it "transfers compare_by_identity flag of the argument if it is a Set" do
set1 = Set[:a].compare_by_identity
set2 = Set[1, 2]
set1.replace(set2)
set1.compare_by_identity?.should == false

set3 = Set[:a]
set4 = Set[1, 2].compare_by_identity
set3.replace(set4)
set3.compare_by_identity?.should == true
end

it "retains compare_by_identity flag if the argument is a non-Set Enumerable" do
set1 = Set[:a].compare_by_identity
set1.replace([1, 2])
set1.compare_by_identity?.should == true
end
end
6 changes: 6 additions & 0 deletions core/set/union_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@
-> { @set | 1 }.should.raise(ArgumentError)
-> { @set | Object.new }.should.raise(ArgumentError)
end

it "retains compare_by_identity flag" do
@set.compare_by_identity
(@set | Set[:b, :d, :e]).compare_by_identity?.should == true
(@set | [:b, :d, :e]).compare_by_identity?.should == true
end
end
20 changes: 20 additions & 0 deletions language/for_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,26 @@
end
end

it "iterates over a list of arrays and destructures with a multi-assignment" do
for (i, j, k) in [[1,2,3]]
[i, j, k].should == [1, 2, 3]
end

for i, (j, k) in [[1,[2,3]]]
[i, j, k].should == [1, 2, 3]
end

# Prism-related bug
# https://github.com/ruby/prism/pull/4156
ruby_version_is "4.1" do
eval <<~RUBY
for (i, j), k in [[[1,2],3]]
[i, j, k].should == [1, 2, 3]
end
RUBY
end
end

it "iterates over an Hash passing each key-value pair to the block" do
k = 0
l = 0
Expand Down
6 changes: 5 additions & 1 deletion optional/capi/regexp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@
end

it "returns a Regexp with the given options" do
@p.a_re("a", 0).options == 0
@p.a_re("a", 0).options.should == 0
@p.a_re("a", Regexp::IGNORECASE).options.should == Regexp::IGNORECASE
@p.a_re("a", Regexp::EXTENDED).options.should == Regexp::EXTENDED
@p.a_re("a", Regexp::EXTENDED | Regexp::IGNORECASE).options.should == Regexp::EXTENDED | Regexp::IGNORECASE
@p.a_re("a", Regexp::MULTILINE).options.should == Regexp::MULTILINE
end

it "returns a Regexp that equals an equivalent Regexp literal" do
@p.a_re("^[0-9]", 0).should == /^[0-9]/
end
end

describe "rb_reg_nth_match" do
Expand Down
Loading