summaryrefslogtreecommitdiff
path: root/spec/ruby/core/matchdata
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2019-10-26 20:53:01 +0200
committerBenoit Daloze <eregontp@gmail.com>2019-10-26 20:53:01 +0200
commit664e96b1de816c813c29f61e16a2031a7af7ba86 (patch)
tree7f4691847cd6b3282812eea7e2be3758e08d1433 /spec/ruby/core/matchdata
parent3eb0d50c0baae916f4486c264605b18e77bee0dc (diff)
Update to ruby/spec@28a728b
Diffstat (limited to 'spec/ruby/core/matchdata')
-rw-r--r--spec/ruby/core/matchdata/regexp_spec.rb5
-rw-r--r--spec/ruby/core/matchdata/string_spec.rb11
2 files changed, 16 insertions, 0 deletions
diff --git a/spec/ruby/core/matchdata/regexp_spec.rb b/spec/ruby/core/matchdata/regexp_spec.rb
index 05a8e80567..7a4783434c 100644
--- a/spec/ruby/core/matchdata/regexp_spec.rb
+++ b/spec/ruby/core/matchdata/regexp_spec.rb
@@ -10,4 +10,9 @@ describe "MatchData#regexp" do
m = 'haystack'.match(/hay/)
m.regexp.should == /hay/
end
+
+ it "returns a Regexp for the result of gsub(String)" do
+ 'he[[o'.gsub('[', ']')
+ $~.regexp.should == /\[/
+ end
end
diff --git a/spec/ruby/core/matchdata/string_spec.rb b/spec/ruby/core/matchdata/string_spec.rb
index ff1b4eab5b..db0d5dfbdc 100644
--- a/spec/ruby/core/matchdata/string_spec.rb
+++ b/spec/ruby/core/matchdata/string_spec.rb
@@ -11,4 +11,15 @@ describe "MatchData#string" do
str.should == "THX1138."
str.frozen?.should == true
end
+
+ it "returns the same frozen string for every call" do
+ md = /(.)(.)(\d+)(\d)/.match("THX1138.")
+ md.string.should equal(md.string)
+ end
+
+ it "returns a frozen copy of the matched string for gsub(String)" do
+ 'he[[o'.gsub!('[', ']')
+ $~.string.should == 'he[[o'
+ $~.string.frozen?.should == true
+ end
end