2018-03-04 15:09:32 +00:00
|
|
|
require_relative '../../spec_helper'
|
2017-05-07 12:04:49 +00:00
|
|
|
|
|
|
|
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.frozen?.should == true
|
|
|
|
end
|
2019-10-26 20:53:01 +02:00
|
|
|
|
|
|
|
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
|
2017-05-07 12:04:49 +00:00
|
|
|
end
|