Skip to content

Commit

Permalink
Message to pipe should end with a newline
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Jul 7, 2019
1 parent a33948f commit a13636e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion parse.y
Expand Up @@ -5581,7 +5581,7 @@ ruby_show_error_line(VALUE errbuf, const YYLTYPE *yylloc, int lineno, VALUE str)
p2 += (lim - ptr);
}
*p2 = '\0';
rb_str_catf(mesg, "%s%.*s%s\n""%s%s",
rb_str_catf(mesg, "%s%.*s%s\n""%s%s\n",
pre, (int)len, code, post,
pre, caret);
}
Expand Down
24 changes: 14 additions & 10 deletions test/ruby/test_parse.rb
Expand Up @@ -13,6 +13,10 @@ def teardown
$VERBOSE = @verbose
end

def test_error_line
assert_syntax_error('------,,', /\n\z/, 'Message to pipe should end with a newline')
end

def test_else_without_rescue
assert_syntax_error(<<-END, %r":#{__LINE__+2}: else without rescue"o, [__FILE__, __LINE__+1])
begin
Expand Down Expand Up @@ -514,13 +518,13 @@ def test_string
mesg = 'from the backslash through the invalid char'

e = assert_syntax_error('"\xg1"', /hex escape/)
assert_equal(' ^~', e.message.lines.last, mesg)
assert_equal(' ^~'"\n", e.message.lines.last, mesg)

e = assert_syntax_error('"\u{1234"', 'unterminated Unicode escape')
assert_equal(' ^', e.message.lines.last, mesg)
assert_equal(' ^'"\n", e.message.lines.last, mesg)

e = assert_syntax_error('"\u{xxxx}"', 'invalid Unicode escape')
assert_equal(' ^', e.message.lines.last, mesg)
assert_equal(' ^'"\n", e.message.lines.last, mesg)

e = assert_syntax_error('"\u{xxxx', 'Unicode escape')
assert_pattern_list([
Expand All @@ -531,14 +535,14 @@ def test_string
/ \^/,
/\n/,
/.*: unterminated string.*\n.*\n/,
/ \^/,
/ \^\n/,
], e.message)

e = assert_syntax_error('"\M1"', /escape character syntax/)
assert_equal(' ^~~', e.message.lines.last, mesg)
assert_equal(' ^~~'"\n", e.message.lines.last, mesg)

e = assert_syntax_error('"\C1"', /escape character syntax/)
assert_equal(' ^~~', e.message.lines.last, mesg)
assert_equal(' ^~~'"\n", e.message.lines.last, mesg)

src = '"\xD0\u{90'"\n""000000000000000000000000"
assert_syntax_error(src, /:#{__LINE__}: unterminated/o)
Expand Down Expand Up @@ -1115,13 +1119,13 @@ def test_unexpected_token_error
end

def test_unexpected_token_after_numeric
assert_raise_with_message(SyntaxError, /^ \^~~\z/) do
assert_raise_with_message(SyntaxError, /^ \^~~\Z/) do
eval('0000xyz')
end
assert_raise_with_message(SyntaxError, /^ \^~~\z/) do
assert_raise_with_message(SyntaxError, /^ \^~~\Z/) do
eval('1.2i1.1')
end
assert_raise_with_message(SyntaxError, /^ \^~\z/) do
assert_raise_with_message(SyntaxError, /^ \^~\Z/) do
eval('1.2.3')
end
end
Expand Down Expand Up @@ -1171,7 +1175,7 @@ def test_eof_in_def
end

def test_location_of_invalid_token
assert_raise_with_message(SyntaxError, /^ \^~~\z/) do
assert_raise_with_message(SyntaxError, /^ \^~~\Z/) do
eval('class xxx end')
end
end
Expand Down

0 comments on commit a13636e

Please sign in to comment.