summaryrefslogtreecommitdiff
path: root/spec/ruby/language/regexp_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/language/regexp_spec.rb')
-rw-r--r--spec/ruby/language/regexp_spec.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/spec/ruby/language/regexp_spec.rb b/spec/ruby/language/regexp_spec.rb
index d4b0c81128..684808f5ab 100644
--- a/spec/ruby/language/regexp_spec.rb
+++ b/spec/ruby/language/regexp_spec.rb
@@ -147,4 +147,24 @@ describe "Literal Regexps" do
pattern.should_not =~ 'fooF'
pattern.should_not =~ 'T'
end
+
+ escapable_terminators = ['!', '"', '#', '%', '&', "'", ',', '-', ':', ';', '@', '_', '`']
+
+ it "supports escaping characters when used as a terminator" do
+ escapable_terminators.each do |c|
+ ref = "(?-mix:#{c})"
+ pattern = eval("%r" + c + "\\" + c + c)
+ pattern.to_s.should == ref
+ end
+ end
+
+ it "treats an escaped non-escapable character normally when used as a terminator" do
+ all_terminators = [*("!".."/"), *(":".."@"), *("[".."`"), *("{".."~")]
+ special_cases = ['(', '{', '[', '<', '\\', '=', '~']
+ (all_terminators - special_cases - escapable_terminators).each do |c|
+ ref = "(?-mix:\\#{c})"
+ pattern = eval("%r" + c + "\\" + c + c)
+ pattern.to_s.should == ref
+ end
+ end
end