diff options
author | Benoit Daloze <eregontp@gmail.com> | 2021-11-29 15:50:28 +0100 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2021-11-29 15:50:28 +0100 |
commit | 67a1e2258974df4b597d019739595c18fbb9a7c1 (patch) | |
tree | 992ad4fc0fc08a6af8f04373703a339f957eb143 /spec/ruby/core/enumerable | |
parent | e6d93a27afa058319e6dad093bbef637e49fce47 (diff) | |
download | ruby-67a1e2258974df4b597d019739595c18fbb9a7c1.tar.gz |
Update to ruby/spec@7f22a0b
Diffstat (limited to 'spec/ruby/core/enumerable')
-rw-r--r-- | spec/ruby/core/enumerable/grep_spec.rb | 12 | ||||
-rw-r--r-- | spec/ruby/core/enumerable/grep_v_spec.rb | 12 |
2 files changed, 24 insertions, 0 deletions
diff --git a/spec/ruby/core/enumerable/grep_spec.rb b/spec/ruby/core/enumerable/grep_spec.rb index ac3d3db641..b81075291f 100644 --- a/spec/ruby/core/enumerable/grep_spec.rb +++ b/spec/ruby/core/enumerable/grep_spec.rb @@ -65,6 +65,18 @@ describe "Enumerable#grep" do ["abc", "def"].grep(/b/).should == ["abc"] Regexp.last_match[0].should == "z" end + + it "correctly handles non-string elements" do + 'set last match' =~ /set last (.*)/ + [:a, 'b', 'z', :c, 42, nil].grep(/[a-d]/).should == [:a, 'b', :c] + $1.should == 'match' + + o = Object.new + def o.to_str + 'hello' + end + [o].grep(/ll/).first.should.equal?(o) + 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 892640efa4..35fde27eb6 100644 --- a/spec/ruby/core/enumerable/grep_v_spec.rb +++ b/spec/ruby/core/enumerable/grep_v_spec.rb @@ -45,6 +45,18 @@ describe "Enumerable#grep_v" do ["abc", "def"].grep_v(/e/).should == ["abc"] Regexp.last_match[0].should == "z" end + + it "correctly handles non-string elements" do + 'set last match' =~ /set last (.*)/ + [:a, 'b', 'z', :c, 42, nil].grep_v(/[a-d]/).should == ['z', 42, nil] + $1.should == 'match' + + o = Object.new + def o.to_str + 'hello' + end + [o].grep_v(/mm/).first.should.equal?(o) + end end describe "without block" do |