summaryrefslogtreecommitdiff
path: root/spec/ruby/core/matchdata/string_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/matchdata/string_spec.rb')
-rw-r--r--spec/ruby/core/matchdata/string_spec.rb26
1 files changed, 26 insertions, 0 deletions
diff --git a/spec/ruby/core/matchdata/string_spec.rb b/spec/ruby/core/matchdata/string_spec.rb
new file mode 100644
index 0000000000..952e953318
--- /dev/null
+++ b/spec/ruby/core/matchdata/string_spec.rb
@@ -0,0 +1,26 @@
+require_relative '../../spec_helper'
+
+describe "MatchData#string" do
+ it "returns a copy of the match string" do
+ str = /(.)(.)(\d+)(\d)/.match("THX1138.").string
+ str.should == "THX1138."
+ end
+
+ it "returns a frozen copy of the match string" do
+ str = /(.)(.)(\d+)(\d)/.match("THX1138.").string
+ str.should == "THX1138."
+ str.should.frozen?
+ 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
+ s = +'he[[o'
+ s.gsub!('[', ']')
+ $~.string.should == 'he[[o'
+ $~.string.should.frozen?
+ end
+end