diff options
author | Kevin Newton <kddnewton@gmail.com> | 2023-10-12 08:46:40 -0400 |
---|---|---|
committer | Kevin Newton <kddnewton@gmail.com> | 2023-10-13 15:31:30 -0400 |
commit | fa76cddc5b1eebf77c9c5bbe951f70fd6c115716 (patch) | |
tree | bf98c1898db99a2d35aa759c98dfb259f02055a5 /test/prism/unescape_test.rb | |
parent | e4f1c06a9bb6012ac155b7a7789d2b5cb4e8abdc (diff) |
[ruby/prism] Properly handle unescaping in regexp
https://github.com/ruby/prism/commit/abf9fd6863
Diffstat (limited to 'test/prism/unescape_test.rb')
-rw-r--r-- | test/prism/unescape_test.rb | 72 |
1 files changed, 41 insertions, 31 deletions
diff --git a/test/prism/unescape_test.rb b/test/prism/unescape_test.rb index 123c139077..051b5e29d1 100644 --- a/test/prism/unescape_test.rb +++ b/test/prism/unescape_test.rb @@ -108,40 +108,50 @@ module Prism escapes = [*ascii, *ascii8, *newlines, *octal, *hex2, *hex4, *hex6, *ctrls] contexts = [ - [Context::String.new("?", ""), escapes], - [Context::String.new("'", "'"), escapes], - [Context::String.new("\"", "\""), escapes], - [Context::String.new("%q[", "]"), escapes], - [Context::String.new("%Q[", "]"), escapes], - [Context::String.new("%[", "]"), escapes], - [Context::String.new("`", "`"), escapes], - [Context::String.new("%x[", "]"), escapes], - [Context::String.new("<<H\n", "\nH"), escapes], - [Context::String.new("<<'H'\n", "\nH"), escapes], - [Context::String.new("<<\"H\"\n", "\nH"), escapes], - [Context::String.new("<<`H`\n", "\nH"), escapes], - [Context::String.new("<<-H\n", "\nH"), escapes], - [Context::String.new("<<-'H'\n", "\nH"), escapes], - [Context::String.new("<<-\"H\"\n", "\nH"), escapes], - [Context::String.new("<<-`H`\n", "\nH"), escapes], - [Context::Heredoc.new("<<~H\n", "\nH"), escapes], - [Context::Heredoc.new("<<~'H'\n", "\nH"), escapes], - [Context::Heredoc.new("<<~\"H\"\n", "\nH"), escapes], - [Context::Heredoc.new("<<~`H`\n", "\nH"), escapes], - [Context::List.new("%w[", "]"), escapes], - [Context::List.new("%W[", "]"), escapes], - [Context::List.new("%i[", "]"), escapes], - [Context::List.new("%I[", "]"), escapes], - [Context::Symbol.new("%s[", "]"), escapes], - [Context::Symbol.new(":'", "'"), escapes], - [Context::Symbol.new(":\"", "\""), escapes], - # [Context::RegExp.new("/", "/"), escapes], - # [Context::RegExp.new("%r[", "]"), escapes] + Context::String.new("?", ""), + Context::String.new("'", "'"), + Context::String.new("\"", "\""), + Context::String.new("%q[", "]"), + Context::String.new("%Q[", "]"), + Context::String.new("%[", "]"), + Context::String.new("`", "`"), + Context::String.new("%x[", "]"), + Context::String.new("<<H\n", "\nH"), + Context::String.new("<<'H'\n", "\nH"), + Context::String.new("<<\"H\"\n", "\nH"), + Context::String.new("<<`H`\n", "\nH"), + Context::String.new("<<-H\n", "\nH"), + Context::String.new("<<-'H'\n", "\nH"), + Context::String.new("<<-\"H\"\n", "\nH"), + Context::String.new("<<-`H`\n", "\nH"), + Context::Heredoc.new("<<~H\n", "\nH"), + Context::Heredoc.new("<<~'H'\n", "\nH"), + Context::Heredoc.new("<<~\"H\"\n", "\nH"), + Context::Heredoc.new("<<~`H`\n", "\nH"), + Context::List.new("%w[", "]"), + Context::List.new("%w<", ">"), + Context::List.new("%W[", "]"), + Context::List.new("%i[", "]"), + Context::List.new("%I[", "]"), + Context::Symbol.new("%s[", "]"), + Context::Symbol.new(":'", "'"), + Context::Symbol.new(":\"", "\""), + Context::RegExp.new("/", "/"), + Context::RegExp.new("%r[", "]"), + Context::RegExp.new("%r<", ">"), + Context::RegExp.new("%r{", "}"), + Context::RegExp.new("%r(", ")"), + Context::RegExp.new("%r|", "|"), ] - contexts.each do |(context, escapes)| + contexts.each do |context| escapes.each do |escape| - next if context.name == "?" && escape == "\xFF".b # wat? + # I think this might be a bug in Ruby. + next if context.name == "?" && escape == "\xFF".b + + # We don't currently support scanning for the number of capture groups, + # so these are all going to fail. + next if (context.name == "//" || context.name.start_with?("%r")) && escape.start_with?(/\d/) define_method(:"test_#{context.name}_#{escape.inspect}") do assert_unescape(context, escape) |