diff --git a/core/regexp/match_spec.rb b/core/regexp/match_spec.rb index 34ddb25cd8..872c3ff59e 100644 --- a/core/regexp/match_spec.rb +++ b/core/regexp/match_spec.rb @@ -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" diff --git a/core/string/match_spec.rb b/core/string/match_spec.rb index 3f5daf823f..94e28e7297 100644 --- a/core/string/match_spec.rb +++ b/core/string/match_spec.rb @@ -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 diff --git a/core/symbol/match_spec.rb b/core/symbol/match_spec.rb index 66c12ecc45..768e3b00da 100644 --- a/core/symbol/match_spec.rb +++ b/core/symbol/match_spec.rb @@ -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