Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions core/regexp/match_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,35 @@
end
end

ruby_version_is "2.4" do
describe "Regexp#match?" do
before :each do
# Resetting Regexp.last_match
/DONTMATCH/.match ''
end

context "when matches the given value" do
it "returns true but does not set Regexp.last_match" do
/string/i.match?('string').should be_true
Regexp.last_match.should be_nil
end
end

it "returns false when does not match the given value" do
/STRING/.match?('string').should be_false
end

it "takes matching position as the 2nd argument" do
/str/i.match?('string', 0).should be_true
/str/i.match?('string', 1).should be_false
end

it "returns false when given nil" do
/./.match?(nil).should be_false
end
end
end

describe "Regexp#~" do
it "matches against the contents of $_" do
$_ = "input data"
Expand Down
25 changes: 25 additions & 0 deletions core/string/match_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,28 @@ def obj.method_missing(*args) "." end
'hello'.match(regexp).should == :foo
end
end

ruby_version_is "2.4" do
describe "String#match?" do
before :each do
# Resetting Regexp.last_match
/DONTMATCH/.match ''
end

context "when matches the given regex" do
it "returns true but does not set Regexp.last_match" do
'string'.match?(/string/i).should be_true
Regexp.last_match.should be_nil
end
end

it "returns false when does not match the given regex" do
'string'.match?(/STRING/).should be_false
end

it "takes matching position as the 2nd argument" do
'string'.match?(/str/i, 0).should be_true
'string'.match?(/str/i, 1).should be_false
end
end
end
25 changes: 25 additions & 0 deletions core/symbol/match_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,28 @@
end
end
end

ruby_version_is "2.4" do
describe "Symbol#match?" do
before :each do
# Resetting Regexp.last_match
/DONTMATCH/.match ''
end

context "when matches the given regex" do
it "returns true but does not set Regexp.last_match" do
:string.match?(/string/i).should be_true
Regexp.last_match.should be_nil
end
end

it "returns false when does not match the given regex" do
:string.match?(/STRING/).should be_false
end

it "takes matching position as the 2nd argument" do
:string.match?(/str/i, 0).should be_true
:string.match?(/str/i, 1).should be_false
end
end
end