summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorMarc-Andre Lafortune <github@marc-andre.ca>2020-12-08 21:20:37 -0500
committerMarc-André Lafortune <github@marc-andre.ca>2020-12-15 12:54:45 -0500
commitd5f0d338c7b5d3d64929b51d29061d369550e8c4 (patch)
treedf9905cc1d66eda457942bceecfde4f66c4a5944 /spec
parenta039dc018ccf34e217f767eac500b9400c58f069 (diff)
Optimize `Enumerable#grep{_v}`
[Bug #17030]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3868
Diffstat (limited to 'spec')
-rw-r--r--spec/ruby/core/enumerable/grep_spec.rb24
-rw-r--r--spec/ruby/core/enumerable/grep_v_spec.rb24
2 files changed, 34 insertions, 14 deletions
diff --git a/spec/ruby/core/enumerable/grep_spec.rb b/spec/ruby/core/enumerable/grep_spec.rb
index c9c0f34e27..4e66bb85ea 100644
--- a/spec/ruby/core/enumerable/grep_spec.rb
+++ b/spec/ruby/core/enumerable/grep_spec.rb
@@ -40,15 +40,25 @@ describe "Enumerable#grep" do
$~.should == nil
end
- it "sets $~ to the last match when given no block" do
- "z" =~ /z/ # Reset $~
- ["abc", "def"].grep(/b/).should == ["abc"]
+ ruby_version_is ""..."3.0.0" do
+ it "sets $~ to the last match when given no block" do
+ "z" =~ /z/ # Reset $~
+ ["abc", "def"].grep(/b/).should == ["abc"]
- # Set by the failed match of "def"
- $~.should == nil
+ # Set by the failed match of "def"
+ $~.should == nil
- ["abc", "def"].grep(/e/)
- $&.should == "e"
+ ["abc", "def"].grep(/e/)
+ $&.should == "e"
+ end
+ end
+
+ ruby_version_is "3.0.0" do
+ it "does not set $~ when given no block" do
+ "z" =~ /z/ # Reset $~
+ ["abc", "def"].grep(/b/).should == ["abc"]
+ $&.should == "z"
+ end
end
describe "with a block" do
diff --git a/spec/ruby/core/enumerable/grep_v_spec.rb b/spec/ruby/core/enumerable/grep_v_spec.rb
index 6dec487065..8cae3ac618 100644
--- a/spec/ruby/core/enumerable/grep_v_spec.rb
+++ b/spec/ruby/core/enumerable/grep_v_spec.rb
@@ -20,15 +20,25 @@ describe "Enumerable#grep_v" do
$&.should == "e"
end
- it "sets $~ to the last match when given no block" do
- "z" =~ /z/ # Reset $~
- ["abc", "def"].grep_v(/e/).should == ["abc"]
+ ruby_version_is ""..."3.0.0" do
+ it "sets $~ to the last match when given no block" do
+ "z" =~ /z/ # Reset $~
+ ["abc", "def"].grep_v(/e/).should == ["abc"]
- # Set by the match of "def"
- $&.should == "e"
+ # Set by the match of "def"
+ $&.should == "e"
- ["abc", "def"].grep_v(/b/)
- $&.should == nil
+ ["abc", "def"].grep_v(/b/)
+ $&.should == nil
+ end
+ end
+
+ ruby_version_is "3.0.0" do
+ it "does not set $~ when given no block" do
+ "z" =~ /z/ # Reset $~
+ ["abc", "def"].grep_v(/e/).should == ["abc"]
+ $&.should == "z"
+ end
end
describe "without block" do