Skip to content

Commit 50109a6

Browse files
mrhoribuclaude
andcommitted
Set operations retain compare_by_identity flag since 4.0.8
Set#&, #classify, #divide, #flatten, #flatten! and #map! keep the receiver's compare_by_identity flag since the fix for [Bug #22174] was backported to Ruby 4.0.8. See https://bugs.ruby-lang.org/issues/22174 Matches the layout of the specs from ruby/ruby#18848, with the guards moved from "4.1"/""..."4.0" to "4.0.8"/""..."4.0.8". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 417be8a commit 50109a6

5 files changed

Lines changed: 82 additions & 23 deletions

File tree

‎core/set/classify_spec.rb‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,19 @@
2424
classified.should == { 3 => Set["one", "two"], 4 => Set["four"], 5 => Set["three"] }
2525
end
2626

27-
it "does not retain compare_by_identity flag" do
28-
set = Set["one", "two"].compare_by_identity
29-
classified = set.classify { |x| x.length }
30-
classified.values.each { |s| s.compare_by_identity?.should == false }
27+
ruby_version_is "4.0.8" do
28+
it "retains compare_by_identity flag" do
29+
set = Set["one", "two"].compare_by_identity
30+
classified = set.classify { |x| x.length }
31+
classified.values.each { |s| s.compare_by_identity?.should == true }
32+
end
33+
end
34+
35+
ruby_version_is ""..."4.0.8" do
36+
it "does not retain compare_by_identity flag" do
37+
set = Set["one", "two"].compare_by_identity
38+
classified = set.classify { |x| x.length }
39+
classified.values.each { |s| s.compare_by_identity?.should == false }
40+
end
3141
end
3242
end

‎core/set/divide_spec.rb‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,20 @@
1818
ret.each(&:even?).should == Set[Set[1, 3], Set[2, 4]]
1919
end
2020

21-
it "does not retain compare_by_identity flag" do
22-
set = Set["one", "two"].compare_by_identity
23-
res = set.divide { |x| x.length }
24-
res.each { |s| s.compare_by_identity?.should == false }
21+
ruby_version_is "4.0.8" do
22+
it "retains compare_by_identity flag" do
23+
set = Set["one", "two"].compare_by_identity
24+
res = set.divide { |x| x.length }
25+
res.each { |s| s.compare_by_identity?.should == true }
26+
end
27+
end
28+
29+
ruby_version_is ""..."4.0.8" do
30+
it "does not retain compare_by_identity flag" do
31+
set = Set["one", "two"].compare_by_identity
32+
res = set.divide { |x| x.length }
33+
res.each { |s| s.compare_by_identity?.should == false }
34+
end
2535
end
2636
end
2737

‎core/set/flatten_spec.rb‎

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@
1616
-> { set.flatten }.should.raise(ArgumentError)
1717
end
1818

19+
ruby_version_is "4.0.8" do
20+
it "retains compare_by_identity flag" do
21+
set = Set[1, 2, Set[3, 4]].compare_by_identity
22+
set.flatten.compare_by_identity?.should == true
23+
end
24+
end
25+
1926
ruby_version_is ""..."4.0" do
2027
context "when Set contains a Set-like object" do
2128
it "returns a copy of self with each included Set-like object flattened" do
@@ -24,9 +31,11 @@
2431
end
2532
end
2633

27-
it "does not retain compare_by_identity flag" do
28-
set = Set[1, 2, Set[3, 4]].compare_by_identity
29-
set.flatten.compare_by_identity?.should == false
34+
ruby_version_is ""..."4.0.8" do
35+
it "does not retain compare_by_identity flag" do
36+
set = Set[1, 2, Set[3, 4]].compare_by_identity
37+
set.flatten.compare_by_identity?.should == false
38+
end
3039
end
3140
end
3241

@@ -52,10 +61,20 @@
5261
-> { set.flatten! }.should.raise(ArgumentError)
5362
end
5463

55-
it "does not retain compare_by_identity flag when flattening elements" do
56-
set = Set[1, 2, Set[3, 4]].compare_by_identity
57-
set.flatten!
58-
set.compare_by_identity?.should == false
64+
ruby_version_is "4.0.8" do
65+
it "retains compare_by_identity flag when flattening elements" do
66+
set = Set[1, 2, Set[3, 4]].compare_by_identity
67+
set.flatten!
68+
set.compare_by_identity?.should == true
69+
end
70+
end
71+
72+
ruby_version_is ""..."4.0.8" do
73+
it "does not retain compare_by_identity flag when flattening elements" do
74+
set = Set[1, 2, Set[3, 4]].compare_by_identity
75+
set.flatten!
76+
set.compare_by_identity?.should == false
77+
end
5978
end
6079

6180
it "retains compare_by_identity flag if no elements are flattened" do

‎core/set/intersection_spec.rb‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,19 @@
2121
-> { @set & Object.new }.should.raise(ArgumentError)
2222
end
2323

24-
it "does not retain compare_by_identity flag" do
25-
@set.compare_by_identity
26-
(@set & Set[:b, :c, :d, :e]).compare_by_identity?.should == false
27-
(@set & [:b, :c, :d]).compare_by_identity?.should == false
24+
ruby_version_is "4.0.8" do
25+
it "retains compare_by_identity flag" do
26+
@set.compare_by_identity
27+
(@set & Set[:b, :c, :d, :e]).compare_by_identity?.should == true
28+
(@set & [:b, :c, :d]).compare_by_identity?.should == true
29+
end
30+
end
31+
32+
ruby_version_is ""..."4.0.8" do
33+
it "does not retain compare_by_identity flag" do
34+
@set.compare_by_identity
35+
(@set & Set[:b, :c, :d, :e]).compare_by_identity?.should == false
36+
(@set & [:b, :c, :d]).compare_by_identity?.should == false
37+
end
2838
end
2939
end

‎core/set/map_spec.rb‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,19 @@
2020
@set.should == Set[2, 4, 6, 8, 10]
2121
end
2222

23-
it "does not retain compare_by_identity flag" do
24-
@set.compare_by_identity
25-
@set.map! { |x| x * 2 }
26-
@set.compare_by_identity?.should == false
23+
ruby_version_is "4.0.8" do
24+
it "retains compare_by_identity flag" do
25+
@set.compare_by_identity
26+
@set.map! { |x| x * 2 }
27+
@set.compare_by_identity?.should == true
28+
end
29+
end
30+
31+
ruby_version_is ""..."4.0.8" do
32+
it "does not retain compare_by_identity flag" do
33+
@set.compare_by_identity
34+
@set.map! { |x| x * 2 }
35+
@set.compare_by_identity?.should == false
36+
end
2737
end
2838
end

0 commit comments

Comments
 (0)