-- Test cases for parser -- Python 2 syntax.
--
-- See parse.test for a description of this file format.

[case testEmptyFile]
[out]
MypyFile:1()

[case testStringLiterals]
'bar'
u'foo'
ur'foo'
u'''bar'''
b'foo'
[out]
MypyFile:1(
  ExpressionStmt:1(
    StrExpr(bar))
  ExpressionStmt:2(
    UnicodeExpr(foo))
  ExpressionStmt:3(
    UnicodeExpr(foo))
  ExpressionStmt:4(
    UnicodeExpr(bar))
  ExpressionStmt:5(
    StrExpr(foo)))

[case testSimplePrint]
print 1
print 2, 3
print (4, 5)
[out]
MypyFile:1(
  PrintStmt:1(
    IntExpr(1)
    Newline)
  PrintStmt:2(
    IntExpr(2)
    IntExpr(3)
    Newline)
  PrintStmt:3(
    TupleExpr:3(
      IntExpr(4)
      IntExpr(5))
    Newline))

[case testPrintWithNoArgs]
print
[out]
MypyFile:1(
  PrintStmt:1(
    Newline))

[case testPrintWithTarget]
print >>foo
[out]
MypyFile:1(
  PrintStmt:1(
    Target(
      NameExpr(foo))
    Newline))

[case testPrintWithTargetAndArgs]
print >>foo, x
[out]
MypyFile:1(
  PrintStmt:1(
    NameExpr(x)
    Target(
      NameExpr(foo))
    Newline))

[case testPrintWithTargetAndArgsAndTrailingComma]
print >>foo, x, y,
[out]
MypyFile:1(
  PrintStmt:1(
    NameExpr(x)
    NameExpr(y)
    Target(
      NameExpr(foo))))

[case testSimpleWithTrailingComma]
print 1,
print 2, 3,
print (4, 5),
[out]
MypyFile:1(
  PrintStmt:1(
    IntExpr(1))
  PrintStmt:2(
    IntExpr(2)
    IntExpr(3))
  PrintStmt:3(
    TupleExpr:3(
      IntExpr(4)
      IntExpr(5))))

[case testOctalIntLiteral]
00
01
0377
[out]
MypyFile:1(
  ExpressionStmt:1(
    IntExpr(0))
  ExpressionStmt:2(
    IntExpr(1))
  ExpressionStmt:3(
    IntExpr(255)))

[case testLongLiteral-skip]
# see typed_ast issue #26
0L
123L
012L
0x123l
[out]
MypyFile:1(
  ExpressionStmt:1(
    IntExpr(0))
  ExpressionStmt:2(
    IntExpr(123))
  ExpressionStmt:3(
    IntExpr(10))
  ExpressionStmt:4(
    IntExpr(291)))

[case testTryExceptWithComma]
try:
    x
except Exception, e:
    y
[out]
MypyFile:1(
  TryStmt:1(
    Block:1(
      ExpressionStmt:2(
        NameExpr(x)))
    NameExpr(Exception)
    NameExpr(e)
    Block:3(
      ExpressionStmt:4(
        NameExpr(y)))))

[case testTryExceptWithNestedComma]
try:
    x
except (KeyError, IndexError):
    y
[out]
MypyFile:1(
  TryStmt:1(
    Block:1(
      ExpressionStmt:2(
        NameExpr(x)))
    TupleExpr:3(
      NameExpr(KeyError)
      NameExpr(IndexError))
    Block:3(
      ExpressionStmt:4(
        NameExpr(y)))))

[case testExecStatement]
exec a
[out]
MypyFile:1(
  ExecStmt:1(
    NameExpr(a)))

[case testExecStatementWithIn]
exec a in globals()
[out]
MypyFile:1(
  ExecStmt:1(
    NameExpr(a)
    CallExpr:1(
      NameExpr(globals)
      Args())))

[case testExecStatementWithInAnd2Expressions]
exec a in x, y
[out]
MypyFile:1(
  ExecStmt:1(
    NameExpr(a)
    NameExpr(x)
    NameExpr(y)))

[case testEllipsisInExpression_python2]
x = ... # E: invalid syntax
[out]

[case testStrLiteralConcatenationWithMixedLiteralTypes]
u'foo' 'bar'
'bar' u'foo'
[out]
MypyFile:1(
  ExpressionStmt:1(
    UnicodeExpr(foobar))
  ExpressionStmt:2(
    UnicodeExpr(barfoo)))

[case testLegacyInequality]
1 <> 2
[out]
MypyFile:1(
  ExpressionStmt:1(
    ComparisonExpr:1(
      !=
      IntExpr(1)
      IntExpr(2))))

[case testLambdaInListComprehensionInPython2]
([ 0 for x in 1, 2 if 3 ])
[out]
MypyFile:1(
  ExpressionStmt:1(
    ListComprehension:1(
      GeneratorExpr:1(
        IntExpr(0)
        NameExpr(x)
        TupleExpr:1(
          IntExpr(1)
          IntExpr(2))
        IntExpr(3)))))

[case testTupleArgListInPython2]
def f(x, (y, z)): pass
[out]
MypyFile:1(
  FuncDef:1(
    f
    Args(
      Var(x)
      Var(__tuple_arg_2))
    Block:1(
      AssignmentStmt:1(
        TupleExpr:1(
          NameExpr(y)
          NameExpr(z))
        NameExpr(__tuple_arg_2))
      PassStmt:1())))

[case testTupleArgListWithTwoTupleArgsInPython2]
def f((x, y), (z, zz)): pass
[out]
MypyFile:1(
  FuncDef:1(
    f
    Args(
      Var(__tuple_arg_1)
      Var(__tuple_arg_2))
    Block:1(
      AssignmentStmt:1(
        TupleExpr:1(
          NameExpr(x)
          NameExpr(y))
        NameExpr(__tuple_arg_1))
      AssignmentStmt:1(
        TupleExpr:1(
          NameExpr(z)
          NameExpr(zz))
        NameExpr(__tuple_arg_2))
      PassStmt:1())))

[case testTupleArgListWithInitializerInPython2]
def f((y, z) = (1, 2)): pass
[out]
MypyFile:1(
  FuncDef:1(
    f
    Args(
      default(
        Var(__tuple_arg_1)
        TupleExpr:1(
          IntExpr(1)
          IntExpr(2))))
    Block:1(
      AssignmentStmt:1(
        TupleExpr:1(
          NameExpr(y)
          NameExpr(z))
        NameExpr(__tuple_arg_1))
      PassStmt:1())))

[case testLambdaTupleArgListInPython2]
lambda (x, y): z
[out]
MypyFile:1(
  ExpressionStmt:1(
    LambdaExpr:1(
      Args(
        Var(__tuple_arg_1))
      Block:1(
        AssignmentStmt:1(
          TupleExpr:1(
            NameExpr(x)
            NameExpr(y))
          NameExpr(__tuple_arg_1))
        ReturnStmt:1(
          NameExpr(z))))))

[case testLambdaSingletonTupleArgListInPython2]
lambda (x,): z
[out]
MypyFile:1(
  ExpressionStmt:1(
    LambdaExpr:1(
      Args(
        Var(__tuple_arg_1))
      Block:1(
        AssignmentStmt:1(
          TupleExpr:1(
            NameExpr(x))
          NameExpr(__tuple_arg_1))
        ReturnStmt:1(
          NameExpr(z))))))

[case testLambdaNoTupleArgListInPython2]
lambda (x): z
[out]
MypyFile:1(
  ExpressionStmt:1(
    LambdaExpr:1(
      Args(
        Var(x))
      Block:1(
        ReturnStmt:1(
          NameExpr(z))))))

[case testInvalidExprInTupleArgListInPython2_1]
def f(x, ()): pass
[out]
main:1: error: invalid syntax

[case testInvalidExprInTupleArgListInPython2_2]
def f(x, (y, x[1])): pass
[out]
main:1: error: invalid syntax

[case testListLiteralAsTupleArgInPython2]
def f(x, [x]): pass
[out]
main:1: error: invalid syntax

[case testTupleArgAfterStarArgInPython2]
def f(*a, (b, c)): pass
[out]
main:1: error: invalid syntax

[case testTupleArgAfterStarStarArgInPython2]
def f(*a, (b, c)): pass
[out]
main:1: error: invalid syntax

[case testParenthesizedArgumentInPython2]
def f(x, (y)): pass
[out]
MypyFile:1(
  FuncDef:1(
    f
    Args(
      Var(x)
      Var(y))
    Block:1(
      PassStmt:1())))

[case testDuplicateNameInTupleArgList_python2]
def f(a, (a, b)):
    pass
def g((x, (x, y))):
    pass
[out]
main:1: error: Duplicate argument 'a' in function definition
main:3: error: Duplicate argument 'x' in function definition

[case testBackquotesInPython2]
`1 + 2`
[out]
MypyFile:1(
  ExpressionStmt:1(
    BackquoteExpr:1(
      OpExpr:1(
        +
        IntExpr(1)
        IntExpr(2)))))

[case testBackquoteSpecialCasesInPython2]
`1, 2`
[out]
MypyFile:1(
  ExpressionStmt:1(
    BackquoteExpr:1(
      TupleExpr:1(
        IntExpr(1)
        IntExpr(2)))))
