diff options
Diffstat (limited to 'spec/ruby/core/regexp')
-rw-r--r-- | spec/ruby/core/regexp/shared/quote.rb | 5 | ||||
-rw-r--r-- | spec/ruby/core/regexp/source_spec.rb | 22 |
2 files changed, 25 insertions, 2 deletions
diff --git a/spec/ruby/core/regexp/shared/quote.rb b/spec/ruby/core/regexp/shared/quote.rb index 33bdfd9979..9533102766 100644 --- a/spec/ruby/core/regexp/shared/quote.rb +++ b/spec/ruby/core/regexp/shared/quote.rb @@ -17,6 +17,11 @@ describe :regexp_quote, shared: true do Regexp.send(@method, str).should == '\+\[\]\(' end + it "works for broken strings" do + Regexp.send(@method, "a.\x85b.".force_encoding("US-ASCII")).should =="a\\.\x85b\\.".force_encoding("US-ASCII") + Regexp.send(@method, "a.\x80".force_encoding("UTF-8")).should == "a\\.\x80".force_encoding("UTF-8") + end + it "sets the encoding of the result to US-ASCII if there are only US-ASCII characters present in the input String" do str = "abc".force_encoding("euc-jp") Regexp.send(@method, str).encoding.should == Encoding::US_ASCII diff --git a/spec/ruby/core/regexp/source_spec.rb b/spec/ruby/core/regexp/source_spec.rb index 709fee49b3..5f253da9ea 100644 --- a/spec/ruby/core/regexp/source_spec.rb +++ b/spec/ruby/core/regexp/source_spec.rb @@ -9,8 +9,26 @@ describe "Regexp#source" do /x(.)xz/.source.should == "x(.)xz" end - it "will remove escape characters" do - /foo\/bar/.source.should == "foo/bar" + it "keeps escape sequences as is" do + /\x20\+/.source.should == '\x20\+' + end + + describe "escaping" do + it "keeps escaping of metacharacter" do + /\$/.source.should == "\\$" + end + + it "keeps escaping of metacharacter used as a terminator" do + %r+\++.source.should == "\\+" + end + + it "removes escaping of non-metacharacter used as a terminator" do + %r@\@@.source.should == "@" + end + + it "keeps escaping of non-metacharacter not used as a terminator" do + /\@/.source.should == "\\@" + end end not_supported_on :opal do |