parse.y: refine error messages

* parse.y (parser_read_escape, parser_tok_hex): refine error
  messages.  point from the backslash up to the invalid char.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59341 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-07-15 08:29:03 +00:00
parent a7452a8f4f
commit 70af8d3c9c
2 changed files with 15 additions and 6 deletions

View file

@ -484,21 +484,27 @@ class TestParse < Test::Unit::TestCase
end
def test_string
assert_raise(SyntaxError) do
mesg = 'from the backslash through the invalid char'
e = assert_raise_with_message(SyntaxError, /hex escape/) do
eval '"\xg1"'
end
assert_equal(' ^', e.message.lines.last, mesg)
assert_raise(SyntaxError) do
e = assert_raise(SyntaxError) do
eval '"\u{1234"'
end
assert_match(' ^~~~~~~', e.message.lines.last, mesg)
assert_raise(SyntaxError) do
e = assert_raise_with_message(SyntaxError, /escape character syntax/) do
eval '"\M1"'
end
assert_equal(' ^~~', e.message.lines.last, mesg)
assert_raise(SyntaxError) do
e = assert_raise_with_message(SyntaxError, /escape character syntax/) do
eval '"\C1"'
end
assert_equal(' ^~~', e.message.lines.last, mesg)
assert_equal("\x81", eval('"\C-\M-a"'))
assert_equal("\177", eval('"\c?"'))