diff --git a/core/set/classify_spec.rb b/core/set/classify_spec.rb index a225ab7cb..1cfacf357 100644 --- a/core/set/classify_spec.rb +++ b/core/set/classify_spec.rb @@ -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 diff --git a/core/set/divide_spec.rb b/core/set/divide_spec.rb index 409a22df7..e00e4616e 100644 --- a/core/set/divide_spec.rb +++ b/core/set/divide_spec.rb @@ -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 diff --git a/core/set/exclusion_spec.rb b/core/set/exclusion_spec.rb index 52ee34fe7..5457e6e3d 100644 --- a/core/set/exclusion_spec.rb +++ b/core/set/exclusion_spec.rb @@ -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 diff --git a/core/set/flatten_spec.rb b/core/set/flatten_spec.rb index ca6323fac..65c63a9b7 100644 --- a/core/set/flatten_spec.rb +++ b/core/set/flatten_spec.rb @@ -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 @@ -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 diff --git a/core/set/intersection_spec.rb b/core/set/intersection_spec.rb index c14e1f62a..3551fe701 100644 --- a/core/set/intersection_spec.rb +++ b/core/set/intersection_spec.rb @@ -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 diff --git a/core/set/map_spec.rb b/core/set/map_spec.rb index fd04a8bde..6f6959fee 100644 --- a/core/set/map_spec.rb +++ b/core/set/map_spec.rb @@ -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 diff --git a/core/set/merge_spec.rb b/core/set/merge_spec.rb index a2c1a7e70..c7f2cd90b 100644 --- a/core/set/merge_spec.rb +++ b/core/set/merge_spec.rb @@ -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 diff --git a/core/set/minus_spec.rb b/core/set/minus_spec.rb index 857470855..4e3387138 100644 --- a/core/set/minus_spec.rb +++ b/core/set/minus_spec.rb @@ -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 diff --git a/core/set/replace_spec.rb b/core/set/replace_spec.rb index 2a51a024d..bd3a32734 100644 --- a/core/set/replace_spec.rb +++ b/core/set/replace_spec.rb @@ -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 diff --git a/core/set/union_spec.rb b/core/set/union_spec.rb index 206535aae..5b15d89a3 100644 --- a/core/set/union_spec.rb +++ b/core/set/union_spec.rb @@ -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 diff --git a/language/for_spec.rb b/language/for_spec.rb index b0f3aef40..b8a0c9deb 100644 --- a/language/for_spec.rb +++ b/language/for_spec.rb @@ -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 diff --git a/optional/capi/regexp_spec.rb b/optional/capi/regexp_spec.rb index f233b5e3b..0a7ec4b17 100644 --- a/optional/capi/regexp_spec.rb +++ b/optional/capi/regexp_spec.rb @@ -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