1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Optimize Enumerable#grep{_v}

[Bug #17030]
This commit is contained in:
Marc-Andre Lafortune 2020-12-08 21:20:37 -05:00 committed by Marc-André Lafortune
parent a039dc018c
commit d5f0d338c7
Notes: git 2020-12-16 02:55:10 +09:00
5 changed files with 99 additions and 26 deletions

View file

@ -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