blob: f2251a9e6e2a6431eaea747a4895dec0350004fe [file]
-- Test cases for parser errors. Each test case consists of two sections.
-- The first section contains [case NAME] followed by the input code, while
-- the second section contains [out] followed by the output from the parser.
--
-- The input file name in errors is "file".
--
-- Comments starting with "--" in this file will be ignored, except for lines
-- starting with "----" that are not ignored. The first two dashes of these
-- lines are interpreted as escapes and removed.
[case testInvalidFunction]
def f()
pass
[out]
file:1: error: Parse error before end of line
file:2: error: Inconsistent indentation
[case testMissingIndent]
if x:
1
[out]
file:2: error: Expected an indented block
[case testUnexpectedIndent]
1
2
[out]
file:2: error: Inconsistent indentation
[case testInconsistentIndent]
if x:
1
1
[out]
file:3: error: Inconsistent indentation
[case testInconsistentIndent]
if x:
1
1
[out]
file:3: error: Inconsistent indentation
[case testInvalidBinaryOp]
1>
a*
a+1*
[out]
file:1: error: Parse error before end of line
file:2: error: Parse error before end of line
file:3: error: Parse error before end of line
[case testDoubleStar]
**a
[out]
file:1: error: Parse error before **
[case testInvalidSuperClass]
class A(C[):
pass
[out]
file:1: error: Parse error before )
file:2: error: Parse error before end of file
[case testMissingSuperClass]
class A(:
pass
[out]
file:1: error: Parse error before :
file:2: error: Parse error before end of file
[case testUnexpectedEof]
if 1:
[out]
file:1: error: Expected an indented block
[case testInvalidKeywordArguments1]
f(x=y, z)
[out]
file:1: error: Parse error before "z"
[case testInvalidKeywordArguments2]
f(**x, y=z)
[out]
file:1: error: Parse error before "y"
[case testInvalidKeywordArguments3]
f(**x, y)
[out]
file:1: error: Parse error before "y"
[case testInvalidVarArgs]
f(*x, y)
[out]
file:1: error: Parse error before "y"
[case testInvalidBareAsteriskAndVarArgs2]
def f(*x: A, *) -> None: pass
[out]
file:1: error: Parse error before )
file:1: error: Parse error before end of line
[case testInvalidBareAsteriskAndVarArgs3]
def f(*, *x: A) -> None: pass
[out]
file:1: error: Parse error before *
file:1: error: Parse error before end of line
[case testInvalidBareAsteriskAndVarArgs4]
def f(*, **x: A) -> None: pass
[out]
file:1: error: Parse error before **
file:1: error: Parse error before end of line
[case testInvalidBareAsterisk1]
def f(*) -> None: pass
[out]
file:1: error: Parse error before )
file:1: error: Parse error before end of line
[case testInvalidBareAsterisk2]
def f(x, *) -> None: pass
[out]
file:1: error: Parse error before )
file:1: error: Parse error before end of line
[case testInvalidFuncDefArgs1]
def f(x = y, x): pass
[out]
file:1: error: Invalid argument list
[case testInvalidFuncDefArgs3]
def f(**x, y):
pass
[out]
file:1: error: Invalid argument list
[case testInvalidFuncDefArgs4]
def f(**x, y=x):
pass
[out]
file:1: error: Invalid argument list
[case testInvalidStringLiteralType]
def f(x:
'A['
) -> None: pass
[out]
file:2: error: Parse error before end of line
file:3: error: Parse error before end of line
[case testInvalidStringLiteralType2]
def f(x:
'A B'
) -> None: pass
[out]
file:2: error: Parse error before "B"
file:3: error: Parse error before end of line
[case testInvalidTypeComment]
0
x = 0 # type: A A
[out]
file:2: error: Parse error before "A"
[case testInvalidTypeComment2]
0
x = 0 # type: A[
[out]
file:2: error: Parse error before end of line
[case testInvalidTypeComment3]
0
x = 0 # type:
[out]
file:2: error: Empty type annotation
[case testInvalidTypeComment4]
0
x = 0 # type: *
[out]
file:2: error: Parse error before end of line
[case testInvalidMultilineLiteralType]
def f() -> "A\nB": pass
[out]
file:1: error: Parse error before end of line
[case testInvalidMetaclass]
class A(metaclass=1): pass
[out]
file:1: error: Parse error before numeric literal
file:1: error: Parse error before end of file
[case testInvalidSignatureInComment1]
def f(): # type: x
pass
[out]
file:1: error: Parse error before "x"
[case testInvalidSignatureInComment2]
def f(): # type:
pass
[out]
file:1: error: Empty type annotation
[case testInvalidSignatureInComment3]
def f(): # type: (
pass
[out]
file:1: error: Parse error before end of line
[case testInvalidSignatureInComment4]
def f(): # type: (.
pass
[out]
file:1: error: Parse error before .
[case testInvalidSignatureInComment5]
def f(): # type: (x
pass
[out]
file:1: error: Parse error before end of line
[case testInvalidSignatureInComment6]
def f(): # type: (x)
pass
[out]
file:1: error: Parse error before end of line
[case testInvalidSignatureInComment7]
def f(): # type: (x) -
pass
[out]
file:1: error: Parse error before -
[case testInvalidSignatureInComment8]
def f(): # type: (x) ->
pass
[out]
file:1: error: Parse error before end of line
[case testInvalidSignatureInComment9]
def f(): # type: (x) -> .
pass
[out]
file:1: error: Parse error before .
[case testInvalidSignatureInComment10]
def f(): # type: (x) -> x x
pass
[out]
file:1: error: Parse error before "x"
[case testDuplicateSignatures1]
def f() -> None: # type: () -> None
pass
def f(): # type: () -> None
pass
[out]
file:1: error: Function has duplicate type signatures
[case testDuplicateSignatures2]
def f(x, y: Z): # type: (x, y) -> z
pass
[out]
file:1: error: Function has duplicate type signatures
[case testTooManyTypes]
def f(x, y): # type: (X, Y, Z) -> z
pass
[out]
file:1: error: Type signature has too many arguments
[case testTooFewTypes]
def f(x, y): # type: (X) -> z
pass
[out]
file:1: error: Type signature has too few arguments
[case testCommentFunctionAnnotationVarArgMispatch]
def f(x): # type: (*X) -> Y
pass
def g(*x): # type: (X) -> Y
pass
[out]
file:1: error: Inconsistent use of '*' in function signature
file:3: error: Inconsistent use of '*' in function signature
[case testCommentFunctionAnnotationVarArgMispatch2]
def f(*x, **y): # type: (**X, *Y) -> Z
pass
def g(*x, **y): # type: (*X, *Y) -> Z
pass
[out]
file:1: error: Inconsistent use of '*' in function signature
file:1: error: Inconsistent use of '**' in function signature
file:3: error: Inconsistent use of '*' in function signature
file:3: error: Inconsistent use of '**' in function signature
[case testPrintStatementInPython3]
print 1
[out]
file:1: error: Parse error before numeric literal
[case testInvalidConditionInConditionalExpression]
1 if 2, 3 else 4
[out]
file:1: error: Parse error before ,
[case testInvalidConditionInConditionalExpression2]
1 if x for y in z else 4
[out]
file:1: error: Parse error before "for"
[case testInvalidConditionInConditionalExpression2]
1 if x else for y in z
[out]
file:1: error: Parse error before "for"
[case testYieldFromNotRightParameter]
def f():
yield from
[out]
file:2: error: Parse error before end of line
[case testYieldFromAfterReturn]
def f():
return yield from h()
[out]
file:2: error: Parse error before "yield"
[case testImportDotModule]
import .x
[out]
file:1: error: Parse error before .
[case testImportDot]
import .
[out]
file:1: error: Parse error before .
[case testInvalidFunctionName]
def while(): pass
[out]
file:1: error: Parse error before "while"
file:1: error: Parse error before end of line
[case testInvalidEllipsis1]
...0
..._
...a
[out]
file:1: error: Parse error before numeric literal
file:2: error: Parse error before "_"
file:3: error: Parse error before "a"
[case testBlockStatementInSingleLineIf]
if 1: if 2: pass
[out]
file:1: error: Parse error before "if"
[case testBlockStatementInSingleLineIf2]
if 1: while 2: pass
[out]
file:1: error: Parse error before "while"
[case testBlockStatementInSingleLineIf3]
if 1: for x in y: pass
[out]
file:1: error: Parse error before "for"
[case testUnexpectedEllipsis]
a = a...
[out]
file:1: error: Parse error before ...
[case testFromFutureImportStar]
from __future__ import *
x = 1
[out]
file:1: error: Parse error before *
[case testParseErrorBeforeUnicodeLiteral]
x u'y'
[out]
file:1: error: Parse error before string literal
[case testParseErrorInExtendedSlicing]
x[:,
[out]
file:1: error: Parse error before end of line
[case testParseErrorInExtendedSlicing2]
x[:,::
[out]
file:1: error: Parse error before end of line
[case testParseErrorInExtendedSlicing3]
x[:,:
[out]
file:1: error: Parse error before end of line
[case testPython2OctalIntLiteralInPython3]
0377
[out]
file:1: error: Invalid numeric literal
[case testInvalidEncoding]
# foo
# coding: uft-8
[out]
file:2: error: Unknown encoding 'uft-8'
[case testInvalidEncoding2]
# coding=Uft.8
[out]
file:1: error: Unknown encoding 'Uft.8'
[case testInvalidEncoding3]
#!/usr/bin python
# vim: set fileencoding=uft8 :
[out]
file:2: error: Unknown encoding 'uft8'
[case testDoubleEncoding]
# coding: uft8
# coding: utf8
# The first coding cookie should be used and fail.
[out]
file:1: error: Unknown encoding 'uft8'
[case testDoubleEncoding2]
# Again the first cookie should be used and fail.
# coding: uft8
# coding: utf8
[out]
file:2: error: Unknown encoding 'uft8'
[case testDoubleEncoding3]
# If the third line were interpreted as a coding cookie, we'd get a
# different error message.
# coding: ascii
á = 1
[out]
file:4: error: Unrecognized character
[case testDoubleEncoding4]
# coding: ascii
á = 1
[out]
file:4: error: Unrecognized character
[case testLongLiteralInPython3]
2L
0x2L
[out]
file:1: error: Invalid numeric literal
file:2: error: Invalid numeric literal
[case testPython2LegacyInequalityInPython3]
1 <> 2
[out]
file:1: error: Parse error before >
[case testLambdaInListComprehensionInPython3]
([ 0 for x in 1, 2 if 3 ])
[out]
file:1: error: Parse error before ,
[case testTupleArgListInPython3]
def f(x, (y, z)): pass
[out]
file:1: error: Tuples in argument lists only supported in Python 2 mode
[case testBackquoteInPython3]
`1 + 2`
[out]
file:1: error: Unrecognized character `
[case testSmartQuotes]
foo = ‘bar’
[out]
file:1: error: Unrecognized character
[case testExceptCommaInPython3]
try:
pass
except KeyError, IndexError:
pass
[out]
file:3: error: Parse error before ,
file:3: error: Parse error before :
file:4: error: Inconsistent indentation