зеркало из https://github.com/github/ruby.git
[ruby/prism] Reconfigure error tests
https://github.com/ruby/prism/commit/fb7e1ebb7f
This commit is contained in:
Родитель
c0ad0c3e43
Коммит
678dd769e5
|
@ -575,6 +575,7 @@ module Prism
|
|||
# This is a result specific to the `parse` and `parse_file` methods.
|
||||
class ParseResult < Result
|
||||
autoload :Comments, "prism/parse_result/comments"
|
||||
autoload :Errors, "prism/parse_result/errors"
|
||||
autoload :Newlines, "prism/parse_result/newlines"
|
||||
|
||||
private_constant :Comments
|
||||
|
@ -604,6 +605,12 @@ module Prism
|
|||
def mark_newlines!
|
||||
value.accept(Newlines.new(source.offsets.size)) # steep:ignore
|
||||
end
|
||||
|
||||
# Returns a string representation of the syntax tree with the errors
|
||||
# displayed inline.
|
||||
def errors_format
|
||||
Errors.new(self).format
|
||||
end
|
||||
end
|
||||
|
||||
# This is a result specific to the `lex` and `lex_file` methods.
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "stringio"
|
||||
|
||||
module Prism
|
||||
class ParseResult < Result
|
||||
class Errors
|
||||
attr_reader :parse_result
|
||||
|
||||
def initialize(parse_result)
|
||||
@parse_result = parse_result
|
||||
end
|
||||
|
||||
def format
|
||||
error_lines = {}
|
||||
parse_result.errors.each do |error|
|
||||
location = error.location
|
||||
(location.start_line..location.end_line).each do |line|
|
||||
error_lines[line] ||= []
|
||||
error_lines[line] << error
|
||||
end
|
||||
end
|
||||
|
||||
source_lines = parse_result.source.source.lines
|
||||
source_lines << "" if error_lines.key?(source_lines.size + 1)
|
||||
|
||||
io = StringIO.new
|
||||
source_lines.each.with_index(1) do |line, line_number|
|
||||
io.puts(line)
|
||||
|
||||
(error_lines.delete(line_number) || []).each do |error|
|
||||
location = error.location
|
||||
|
||||
case line_number
|
||||
when location.start_line
|
||||
io.print(" " * location.start_column + "^")
|
||||
|
||||
if location.start_line == location.end_line
|
||||
if location.start_column != location.end_column
|
||||
io.print("~" * (location.end_column - location.start_column - 1))
|
||||
end
|
||||
|
||||
io.puts(" " + error.message)
|
||||
else
|
||||
io.puts("~" * (line.bytesize - location.start_column))
|
||||
end
|
||||
when location.end_line
|
||||
io.puts("~" * location.end_column + " " + error.message)
|
||||
else
|
||||
io.puts("~" * line.bytesize)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
io.puts
|
||||
io.string
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,11 @@
|
|||
(1, 2, 3)
|
||||
^ unexpected ',', expecting end-of-input
|
||||
^ unexpected ',', ignoring it
|
||||
^ expected a matching `)`
|
||||
^ unexpected ',', expecting end-of-input
|
||||
^ unexpected ',', ignoring it
|
||||
^ unexpected ',', expecting end-of-input
|
||||
^ unexpected ',', ignoring it
|
||||
^ unexpected ')', expecting end-of-input
|
||||
^ unexpected ')', ignoring it
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
alias $a $1
|
||||
^~ invalid argument being passed to `alias`; can't make alias for the number variables
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
alias $a b
|
||||
^ invalid argument being passed to `alias`; expected a bare word, symbol, constant, or global variable
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
alias a $b
|
||||
^~ invalid argument being passed to `alias`; expected a bare word, symbol, constant, or global variable
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
%qXfooX
|
||||
^ unknown type of %string
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
%QXfooX
|
||||
^ unknown type of %string
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
%wXfooX
|
||||
^ unknown type of %string
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
%WxfooX
|
||||
^ unknown type of %string
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
%iXfooX
|
||||
^ unknown type of %string
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
%IXfooX
|
||||
^ unknown type of %string
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
%xXfooX
|
||||
^ unknown type of %string
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
%rXfooX
|
||||
^ unknown type of %string
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
%sXfooX
|
||||
^ unknown type of %string
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
def foo(...); foo(..., 1); end
|
||||
^ unexpected argument after `...`
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
def a(...); b(...); end; def c(x, y, z); b(...); end
|
||||
^~~ unexpected ... when the parent method is not forwarding
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
def a(x, y, z); b(...); end
|
||||
^~~ unexpected ... when the parent method is not forwarding
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
a(&block, foo)
|
||||
^~~ unexpected argument after a block argument
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
foo(*bar and baz)
|
||||
^~~ unexpected 'and'; expected a `)` to close the arguments
|
||||
^ unexpected ')', expecting end-of-input
|
||||
^ unexpected ')', ignoring it
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
a in _1
|
||||
^~ _1 is reserved for numbered parameters
|
||||
a => _1
|
||||
^~ _1 is reserved for numbered parameters
|
||||
1 => a, _1
|
||||
^~ _1 is reserved for numbered parameters
|
||||
1 in a, _1
|
||||
^~ _1 is reserved for numbered parameters
|
||||
/(?<_1>)/ =~ a
|
||||
^~ _1 is reserved for numbered parameters
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
def foo(A, @a, $A, @@a);end
|
||||
^ invalid formal argument; formal argument cannot be a constant
|
||||
^~ invalid formal argument; formal argument cannot be an instance variable
|
||||
^~ invalid formal argument; formal argument cannot be a global variable
|
||||
^~~ invalid formal argument; formal argument cannot be a class variable
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
def foo; BEGIN {}; end
|
||||
^~~~~ BEGIN is permitted only at toplevel
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
..1..
|
||||
^~ unexpected range operator; .. and ... are non-associative and cannot be chained
|
||||
...1..
|
||||
^~ unexpected range operator; .. and ... are non-associative and cannot be chained
|
||||
^~ unexpected .., expecting end-of-input
|
||||
^~ unexpected .., ignoring it
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
foo(&1) { }
|
||||
^~~ both block arg and actual block given; only one block is allowed
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
x.each { x end
|
||||
^~~ unexpected 'end', expecting end-of-input
|
||||
^~~ unexpected 'end', ignoring it
|
||||
^ unexpected end-of-input, assuming it is closing the parent top level context
|
||||
^ expected a block beginning with `{` to end with `}`
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
break 1,;
|
||||
^ expected an argument
|
||||
^~~~~~~~ Invalid break
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
break(1, 2, 3)
|
||||
^ unexpected ',', expecting end-of-input
|
||||
^ unexpected ',', ignoring it
|
||||
^ expected a matching `)`
|
||||
^ unexpected ')', expecting end-of-input
|
||||
^ unexpected ')', ignoring it
|
||||
^~~~~~~~~~~~~ Invalid break
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
foo {} &&= 1
|
||||
^~~~~~ unexpected write target
|
||||
^~~ unexpected operator after a call with a block
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
foo {} += 1
|
||||
^~~~~~ unexpected write target
|
||||
^~ unexpected operator after a call with a block
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
foo {} ||= 1
|
||||
^~~~~~ unexpected write target
|
||||
^~~ unexpected operator after a call with a block
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
begin
|
||||
_1=:a;_2=:a;_3=:a;_4=:a;_5=:a
|
||||
^~ _1 is reserved for numbered parameters
|
||||
^~ _2 is reserved for numbered parameters
|
||||
^~ _3 is reserved for numbered parameters
|
||||
^~ _4 is reserved for numbered parameters
|
||||
^~ _5 is reserved for numbered parameters
|
||||
_6=:a;_7=:a;_8=:a;_9=:a;_10=:a
|
||||
^~ _6 is reserved for numbered parameters
|
||||
^~ _7 is reserved for numbered parameters
|
||||
^~ _8 is reserved for numbered parameters
|
||||
^~ _9 is reserved for numbered parameters
|
||||
end
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
case :a
|
||||
^~~~ expected a `when` or `in` clause after `case`
|
||||
end
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
case :a
|
||||
^~~~ expected a `when` or `in` clause after `case`
|
||||
else
|
||||
end
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
1 => ^(return)
|
||||
^~~~~~ unexpected void value expression
|
||||
while true
|
||||
1 => ^(break)
|
||||
^~~~~ unexpected void value expression
|
||||
1 => ^(next)
|
||||
^~~~ unexpected void value expression
|
||||
1 => ^(redo)
|
||||
^~~~ unexpected void value expression
|
||||
1 => ^(retry)
|
||||
^~~~~ Invalid retry without rescue
|
||||
^~~~~ unexpected void value expression
|
||||
1 => ^(2 => a)
|
||||
^~~~~~ unexpected void value expression
|
||||
end
|
||||
1 => ^(if 1; (return) else (return) end)
|
||||
^~~~~~ unexpected void value expression
|
||||
1 => ^(unless 1; (return) else (return) end)
|
||||
^~~~~~ unexpected void value expression
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
def foo;class A;end;end
|
||||
^~~~~ unexpected class definition in method body
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
def foo(bar = class A;end);end
|
||||
^~~~~ unexpected class definition in method body
|
||||
def foo;rescue;class A;end;end
|
||||
^~~~~ unexpected class definition in method body
|
||||
def foo;ensure;class A;end;end
|
||||
^~~~~ unexpected class definition in method body
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
class 0.X end
|
||||
^~~ unexpected constant path after `class`; class/module name must be CONSTANT
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
foo 1 in a
|
||||
^ unexpected `in` keyword in arguments
|
||||
^ unexpected local variable or method, expecting end-of-input
|
||||
a = foo 2 in b
|
||||
^ unexpected `in` keyword in arguments
|
||||
^ unexpected local variable or method, expecting end-of-input
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
[a b]
|
||||
^ unexpected local variable or method; expected a `,` separator for the array elements
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
+a b
|
||||
^ unexpected local variable or method, expecting end-of-input
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
a + b c
|
||||
^ unexpected local variable or method, expecting end-of-input
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
a && b c
|
||||
^ unexpected local variable or method, expecting end-of-input
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
a =~ b c
|
||||
^ unexpected local variable or method, expecting end-of-input
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
a = b, c d
|
||||
^ unexpected local variable or method, expecting end-of-input
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
a = *b c
|
||||
^ unexpected local variable or method, expecting end-of-input
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
a, b = c = d f
|
||||
^ unexpected local variable or method, expecting end-of-input
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
a ? b c : d e
|
||||
^ expected a `:` after the true expression of a ternary operator
|
||||
^ unexpected ':', expecting end-of-input
|
||||
^ unexpected ':', ignoring it
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
defined? a b
|
||||
^ unexpected local variable or method, expecting end-of-input
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
! ! a b
|
||||
^ unexpected local variable or method, expecting end-of-input
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
{a: b c}
|
||||
^ expected a `}` to close the hash literal
|
||||
^ unexpected local variable or method, expecting end-of-input
|
||||
^ unexpected '}', expecting end-of-input
|
||||
^ unexpected '}', ignoring it
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
def f a = b c; end
|
||||
^ expected a delimiter to close the parameters
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
def f(a = b c); end
|
||||
^ unexpected local variable or method; expected a `)` to close the parameters
|
||||
^ unexpected ')', expecting end-of-input
|
||||
^ unexpected ')', ignoring it
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
a = b rescue c d
|
||||
^ unexpected local variable or method, expecting end-of-input
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
def a = b rescue c d
|
||||
^ unexpected local variable or method, expecting end-of-input
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
->a=b c{}
|
||||
^ expected a `do` keyword or a `{` to open the lambda block
|
||||
^ unexpected end-of-input, assuming it is closing the parent top level context
|
||||
^ expected a lambda block beginning with `do` to end with `end`
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
->(a=b c){}
|
||||
^ expected a matching `)`
|
||||
^ expected a `do` keyword or a `{` to open the lambda block
|
||||
^ unexpected ')', expecting end-of-input
|
||||
^ unexpected ')', ignoring it
|
||||
^ unexpected end-of-input, assuming it is closing the parent top level context
|
||||
^ expected a lambda block beginning with `do` to end with `end`
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
case; when a b; end
|
||||
^ expected a delimiter after the predicates of a `when` clause
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
case; in a if a b; end
|
||||
^~~~ expected a predicate for a case matching statement
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
case; in a unless a b; end
|
||||
^~~~ expected a predicate for a case matching statement
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
begin; rescue a b; end
|
||||
^ expected a closing delimiter for the `rescue` clause
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
...a b
|
||||
^ unexpected local variable or method, expecting end-of-input
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
begin; rescue a b => c; end
|
||||
^ expected a closing delimiter for the `rescue` clause
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
if ...a b; end
|
||||
^ expected `then` or `;` or '\n'
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
a b, c d
|
||||
^ unexpected local variable or method, expecting end-of-input
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
a(b, c d)
|
||||
^ unexpected local variable or method; expected a `)` to close the arguments
|
||||
^ unexpected local variable or method, expecting end-of-input
|
||||
^ unexpected ')', expecting end-of-input
|
||||
^ unexpected ')', ignoring it
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
a(*b c)
|
||||
^ unexpected local variable or method; expected a `)` to close the arguments
|
||||
^ unexpected local variable or method, expecting end-of-input
|
||||
^ unexpected ')', expecting end-of-input
|
||||
^ unexpected ')', ignoring it
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
a(**b c)
|
||||
^ unexpected local variable or method; expected a `)` to close the arguments
|
||||
^ unexpected local variable or method, expecting end-of-input
|
||||
^ unexpected ')', expecting end-of-input
|
||||
^ unexpected ')', ignoring it
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
a(&b c)
|
||||
^ unexpected local variable or method; expected a `)` to close the arguments
|
||||
^ unexpected local variable or method, expecting end-of-input
|
||||
^ unexpected ')', expecting end-of-input
|
||||
^ unexpected ')', ignoring it
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
if 0 0; elsif 0 0; end
|
||||
^ expected `then` or `;` or '\n'
|
||||
^ expected `then` or `;` or '\n'
|
||||
unless 0 0; end
|
||||
^ expected `then` or `;` or '\n'
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
def foo();A=1;end
|
||||
^~~ dynamic constant assignment
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
A::$b
|
||||
^ expected a constant after the `::` operator
|
||||
^~ unexpected global variable, expecting end-of-input
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
<<~FOO.foo
|
||||
^~~ unterminated heredoc; can't find string "FOO" anywhere before EOF
|
|
@ -0,0 +1,3 @@
|
|||
%
|
||||
^ unterminated string meets end of file
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
def ().a; end
|
||||
^ expected a receiver for the method definition
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
def (a); end
|
||||
^ expected a `.` or `::` after the receiver in a method definition
|
||||
^ unexpected ';'; expected a method name
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
def (
|
||||
a
|
||||
b
|
||||
^ expected a matching `)`
|
||||
^ expected a `.` or `::` after the receiver in a method definition
|
||||
^ expected a delimiter to close the parameters
|
||||
).c; end
|
||||
^ unexpected ')', ignoring it
|
||||
^ unexpected '.', ignoring it
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
def _1; end
|
||||
^~ _1 is reserved for numbered parameters
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
def self._1; end
|
||||
^~ _1 is reserved for numbered parameters
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
"\u{000z}"
|
||||
^ invalid Unicode escape sequence
|
||||
^ unterminated Unicode escape
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
a {|...|}
|
||||
^~~ unexpected ... when the parent method is not forwarding
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
->(...) {}
|
||||
^~~ unexpected ... when the parent method is not forwarding
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
"\u{0000001}"
|
||||
^~~~~~~ invalid Unicode escape sequence; maximum length is 6 digits
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
?\u{0001 0002}
|
||||
^~~ invalid Unicode escape sequence; Multiple codepoints at single character literal are disallowed
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
-> (a, b, ) {}
|
||||
^ unexpected `,` in parameters
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
def foo(a,b,c,);end
|
||||
^ unexpected `,` in parameters
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
class A; return; end
|
||||
^~~~~~ Invalid return in class/module body
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
module A; return; end
|
||||
^~~~~~ Invalid return in class/module body
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
begin
|
||||
$+ = nil
|
||||
^~ Can't set variable $+
|
||||
$1466 = nil
|
||||
^~~~~ Can't set variable $1466
|
||||
end
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
def foo(..., ...)
|
||||
^~~ unexpected parameter order
|
||||
end
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
-> { _1 + -> { _2 } }
|
||||
^~ numbered parameter is already used in outer block
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
a(**kwargs, *args)
|
||||
^~~~~ unexpected `*` splat argument after a `**` keyword splat argument
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
case (); in [a, a]; end
|
||||
^ duplicated variable name
|
||||
case (); in [a, *a]; end
|
||||
^ duplicated variable name
|
||||
case (); in {a: a, b: a}; end
|
||||
^ duplicated variable name
|
||||
case (); in {a: a, **a}; end
|
||||
^ duplicated variable name
|
||||
case (); in [a, {a:}]; end
|
||||
^ duplicated variable name
|
||||
case (); in [a, {a: {a: {a: [a]}}}]; end
|
||||
^ duplicated variable name
|
||||
case (); in a => a; end
|
||||
^ duplicated variable name
|
||||
case (); in [A => a, {a: b => a}]; end
|
||||
^ duplicated variable name
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
case (); in {a:, a:}; end
|
||||
^~ duplicated key name
|
||||
^ duplicated variable name
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
case (); in {a:1, a:2}; end
|
||||
^~ duplicated key name
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
def foo(a,b,a);end
|
||||
^ duplicated argument name
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
def foo(a,b,*a);end
|
||||
^ duplicated argument name
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
def foo(a,b,**a);end
|
||||
^ duplicated argument name
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
def foo(a,b,&a);end
|
||||
^ duplicated argument name
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
def foo(a = 1,b,*c);end
|
||||
^ unexpected parameter `*`
|
||||
|
Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше
Загрузка…
Ссылка в новой задаче