Skip to content

Commit

Permalink
Add tests and update refs.
Browse files Browse the repository at this point in the history
  • Loading branch information
akshanshbhatt committed Jul 9, 2022
1 parent 8c612b6 commit 877872c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
9 changes: 9 additions & 0 deletions tests/parser/statements1.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,15 @@
for i in a in list1:
pass

a.b[1]
a.b[1:]
a.b[:-1]
a.b[1:2]
a.b[:]
y.z[1:2:3]
y.z[1::3]
y.z[1::]

i: i32 = 4
if 2 > i : pass
if i > 5 : break
Expand Down
4 changes: 2 additions & 2 deletions tests/reference/ast_new-statements1-e081093.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"basename": "ast_new-statements1-e081093",
"cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}",
"infile": "tests/parser/statements1.py",
"infile_hash": "66cb8201a6ed513a62942f47e6a061b83420dbab629c5906578ddbab",
"infile_hash": "57c83f799b0bb53eaba09687c23c0285a45a466c493dc3269105b66b",
"outfile": null,
"outfile_hash": null,
"stdout": "ast_new-statements1-e081093.stdout",
"stdout_hash": "93d913a264c511bb0d7debfce35ebad5ae13ec8bea4be92ada47a561",
"stdout_hash": "add4cf6ce0ccfcca63f5a9f79f3440b897957b39274c5665d5c17a5f",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
2 changes: 1 addition & 1 deletion tests/reference/ast_new-statements1-e081093.stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(Module [(Pass) (Break) (Continue) (Raise () ()) (Raise (Call (Name NameError Load) [(ConstantStr "String" ())] []) ()) (Raise (Name RuntimeError Load) (Name exc Load)) (Assert (Compare (Call (Name len Load) [(Name marks Load)] []) NotEq [(ConstantInt 0 ())]) (ConstantStr "List is empty." ())) (Assert (Compare (Name x Load) Eq [(ConstantStr "String" ())]) ()) (Assign [(Name x Store)] (ConstantInt 1 ()) ()) (Assign [(Tuple [(Name x Store) (Name y Store)] Store)] (Call (Name x Load) [] []) ()) (Assign [(Name x Store) (Name y Store)] (ConstantInt 1 ()) ()) (Assign [(Tuple [(Name x Store) (Name y Store)] Store)] (Tuple [(ConstantInt 1 ()) (ConstantInt 2 ())] Load) ()) (Assign [(Subscript (Name x Load) (Name i Load) Store)] (Tuple [(ConstantInt 1 ()) (ConstantInt 2 ())] Load) ()) (Assign [(Tuple [(Name x Store) (Name y Store) (Name z Store)] Store)] (Name t Load) ()) (Assign [(Tuple [(Name x Store) (Name y Store) (Name z Store)] Store)] (Name t Load) ()) (Assign [(Tuple [(Name x Store)] Store)] (Name t Load) ()) (Assign [(Tuple [(Name x Store)] Store)] (Name t Load) ()) (AugAssign (Name x Store) Add (ConstantInt 1 ())) (AnnAssign (Name x Store) (Name i64 Load) () 1) (AnnAssign (Name y Store) (Name i32 Load) (ConstantInt 1 ()) 1) (Delete [(Name x Del)]) (Delete [(Tuple [] Del)]) (Delete [(Tuple [(Name x Del) (Name y Del)] Del)]) (Delete [(Tuple [(Name x Del) (Name y Del)] Del)]) (Delete [(Name x Del) (Name y Del)]) (Delete [(Name x Del) (Name y Del)]) (Return ()) (Return (BinOp (Name a Load) Add (Name b Load))) (Return (Call (Name x Load) [(Name a Load)] [])) (Return (Tuple [] Load)) (Return (Tuple [(Name x Load) (Name y Load)] Load)) (Return (Tuple [(Name x Load) (Name y Load)] Load)) (Return (Tuple [(Name x Load) (Name y Load)] Load)) (Return (Tuple [(Name x Load) (Name y Load)] Load)) (Global [a]) (Global [a b]) (Nonlocal [a]) (Nonlocal [a b]) (Expr (ConstantInt 123 ())) (Expr (UnaryOp USub (ConstantInt 123 ()))) (Expr (UnaryOp USub (ConstantInt 291 ()))) (Expr (ConstantInt 6844 ())) (Expr (UnaryOp USub (ConstantInt 83 ()))) (Expr (ConstantInt 87 ())) (Expr (UnaryOp USub (ConstantInt 13 ()))) (Expr (ConstantInt 13 ())) (Expr (ConstantInt 32768 ())) (Expr (ConstantInt 12 ())) (Expr (ConstantInt 23440334322333 ())) (Expr (ConstantFloat 1.23000000000000000e+02 ())) (Expr (ConstantFloat 1.23450000000000003e+02 ())) (Expr (ConstantFloat 1.23400000000000000e+11 ())) (Expr (BinOp (ConstantInt 12 ()) Add (ConstantComplex 0.00000000000000000e+00 3.00000000000000000e+00 ()))) (Expr (BinOp (ConstantFloat 1.19999999999999996e-01 ()) Add (ConstantComplex 0.00000000000000000e+00 1.00000000000000002e-03 ()))) (Expr (ConstantStr "String" ())) (Expr (ConstantStr "String String" ())) (Expr (ConstantStr "String String" ())) (Expr (ConstantStr "String String" ())) (Expr (Subscript (ConstantStr "String String" ()) (Slice (ConstantInt 1 ()) () ()) Load)) (Assign [(Name x Store)] (ConstantStr "String String" ()) ()) (Assign [(Name x Store)] (BinOp (ConstantStr "String " ()) Add (ConstantStr "String" ())) ()) (Assign [(Name x Store)] (ConstantStr "String String" ()) ()) (Assign [(Name x Store)] (ConstantStr "String String" ()) ()) (Assign [(Name x Store)] (ConstantStr "String " ()) ()) (Expr (ConstantStr "String" ())) (Expr (ConstantBool .true. ())) (Expr (ConstantBool .false. ())) (Expr (BinOp (BinOp (Name x Load) Add (Name y Load)) Mult (Name z Load))) (Expr (BinOp (Name x Load) Sub (Name y Load))) (Expr (BinOp (Name x Load) Mult (Name y Load))) (Expr (BinOp (Name x Load) Div (Name y Load))) (Expr (BinOp (Name x Load) Mod (Name y Load))) (Expr (UnaryOp USub (Name y Load))) (Expr (UnaryOp UAdd (Name y Load))) (Expr (UnaryOp Invert (Name y Load))) (Expr (BinOp (Name x Load) Pow (Name y Load))) (Expr (BinOp (Name x Load) FloorDiv (Name y Load))) (Expr (BinOp (Name x Load) MatMult (Name y Load))) (Expr (BinOp (Name x Load) BitAnd (Name y Load))) (Expr (BinOp (Name x Load) BitOr (Name y Load))) (Expr (BinOp (Name x Load) BitXor (Name y Load))) (Expr (BinOp (Name x Load) LShift (Name y Load))) (Expr (BinOp (Name x Load) RShift (Name y Load))) (Expr (Compare (Name x Load) Eq [(Name y Load)])) (Expr (Compare (Name x Load) NotEq [(Name y Load)])) (Expr (Compare (Name x Load) Lt [(Name y Load)])) (Expr (Compare (Name x Load) LtE [(Name y Load)])) (Expr (Compare (Name x Load) Gt [(Name y Load)])) (Expr (Compare (Name x Load) GtE [(Name y Load)])) (If (Compare (Call (Name type Load) [(Name x Load)] []) Is [(Name int Load)]) [(Pass)] []) (If (Compare (Compare (BinOp (BinOp (BinOp (ConstantInt 2 ()) Add (ConstantInt 3 ())) Div (ConstantInt 2 ())) Sub (ConstantInt 1 ())) Is [(ConstantInt 5 ())]) Is [(ConstantBool .true. ())]) [(Pass)] []) (If (Compare (Name x Load) IsNot [(Call (Name type Load) [(Name float Load)] [])]) [(Pass)] []) (If (Compare (Name x Load) IsNot [(Call (Name type Load) [(Name int Load)] [])]) [(Pass)] []) (Assign [(Name a Store)] (List [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())] Load) ()) (If (Compare (Name a Load) NotIn [(List [(ConstantInt 1 ()) (ConstantInt 2 ())] Load)]) [(Pass)] []) (If (Compare (Compare (Name a Load) NotIn [(List [(ConstantInt 1 ()) (ConstantInt 2 ())] Load)]) NotIn [(List [(ConstantBool .true. ()) (ConstantBool .false. ())] Load)]) [(Pass)] []) (If (Compare (Name field Load) In [(List [(ConstantStr "vararg" ()) (ConstantStr "kwarg" ())] Load)]) [(If (Compare (Name value Load) Is [(ConstantNone ())]) [(Pass)] [])] []) (If (Compare (Name a Load) In [(Name list1 Load)]) [(Pass)] []) (Expr (Compare (ConstantStr "hello" ()) In [(Name x Load)])) (Expr (Compare (ConstantStr "a" ()) In [(Call (Attribute (Name a Load) func Load) [] [])])) (Expr (Compare (ConstantStr "lo" ()) In [(ConstantStr "hello" ())])) (For (Name item Store) (Name list1 Load) [(If (Compare (Name item Load) In [(Name list2 Load)]) [(Pass)] [])] [] ()) (If (BoolOp Or [(BoolOp And [(Compare (Name a Load) In [(Name list1 Load)]) (Compare (Name b Load) NotIn [(Name list2 Load)])]) (Compare (Name c Load) In [(Name list3 Load)])]) [(Pass)] []) (Assign [(Name comp Store)] (ListComp (BinOp (Name i Load) Pow (ConstantInt 2 ())) [((Name i Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [(BoolOp And [(Compare (Name i Load) NotIn [(List [(ConstantInt 3 ()) (ConstantInt 5 ()) (ConstantInt 7 ())] Load)]) (Compare (Name i Load) In [(Name list3 Load)])])] 0)]) ()) (For (Name i Store) (Compare (Name a Load) In [(Name list1 Load)]) [(Pass)] [] ()) (AnnAssign (Name i Store) (Name i32 Load) (ConstantInt 4 ()) 1) (If (Compare (ConstantInt 2 ()) Gt [(Name i Load)]) [(Pass)] []) (If (Compare (Name i Load) Gt [(ConstantInt 5 ())]) [(Break)] []) (If (BoolOp And [(Compare (Name i Load) Eq [(ConstantInt 5 ())]) (Compare (Name i Load) Lt [(ConstantInt 10 ())])]) [(Assign [(Name i Store)] (ConstantInt 3 ()) ())] []) (For (Name i Store) (Call (Name range Load) [(Name N Load)] []) [(Assign [(Subscript (Name c Load) (Name i Load) Store)] (BinOp (Subscript (Name a Load) (Name i Load) Load) Add (BinOp (Name scalar Load) Mult (Subscript (Name b Load) (Name i Load) Load))) ())] [] ()) (Assign [(Name x Store)] (NamedExpr (Name y Store) (ConstantInt 0 ())) ()) (If (NamedExpr (Name a Store) (Call (Name ord Load) [(ConstantStr "3" ())] [])) [(Assign [(Name x Store)] (ConstantInt 1 ()) ())] []) (Assign [(Name a Store)] (Set [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())]) ()) (Assign [(Name b Store)] (IfExp (Compare (Name a Load) Eq [(ConstantInt 2 ())]) (ConstantInt 6 ()) (ConstantInt 8 ())) ()) (Expr (IfExp (ConstantBool .true. ()) (ConstantStr "true" ()) (ConstantStr "false" ()))) (Assign [(Name result Store)] (IfExp (UnaryOp Not (Compare (Name a Load) Gt [(Name b Load)])) (Name x Load) (Name y Load)) ()) (Expr (IfExp (Compare (Name a Load) Gt [(Name b Load)]) (Call (Name print Load) [(Name a Load) (ConstantStr "is greater" ())] []) (Call (Name print Load) [(Name b Load) (ConstantStr "is Greater" ())] [])))] [])
(Module [(Pass) (Break) (Continue) (Raise () ()) (Raise (Call (Name NameError Load) [(ConstantStr "String" ())] []) ()) (Raise (Name RuntimeError Load) (Name exc Load)) (Assert (Compare (Call (Name len Load) [(Name marks Load)] []) NotEq [(ConstantInt 0 ())]) (ConstantStr "List is empty." ())) (Assert (Compare (Name x Load) Eq [(ConstantStr "String" ())]) ()) (Assign [(Name x Store)] (ConstantInt 1 ()) ()) (Assign [(Tuple [(Name x Store) (Name y Store)] Store)] (Call (Name x Load) [] []) ()) (Assign [(Name x Store) (Name y Store)] (ConstantInt 1 ()) ()) (Assign [(Tuple [(Name x Store) (Name y Store)] Store)] (Tuple [(ConstantInt 1 ()) (ConstantInt 2 ())] Load) ()) (Assign [(Subscript (Name x Load) (Name i Load) Store)] (Tuple [(ConstantInt 1 ()) (ConstantInt 2 ())] Load) ()) (Assign [(Tuple [(Name x Store) (Name y Store) (Name z Store)] Store)] (Name t Load) ()) (Assign [(Tuple [(Name x Store) (Name y Store) (Name z Store)] Store)] (Name t Load) ()) (Assign [(Tuple [(Name x Store)] Store)] (Name t Load) ()) (Assign [(Tuple [(Name x Store)] Store)] (Name t Load) ()) (AugAssign (Name x Store) Add (ConstantInt 1 ())) (AnnAssign (Name x Store) (Name i64 Load) () 1) (AnnAssign (Name y Store) (Name i32 Load) (ConstantInt 1 ()) 1) (Delete [(Name x Del)]) (Delete [(Tuple [] Del)]) (Delete [(Tuple [(Name x Del) (Name y Del)] Del)]) (Delete [(Tuple [(Name x Del) (Name y Del)] Del)]) (Delete [(Name x Del) (Name y Del)]) (Delete [(Name x Del) (Name y Del)]) (Return ()) (Return (BinOp (Name a Load) Add (Name b Load))) (Return (Call (Name x Load) [(Name a Load)] [])) (Return (Tuple [] Load)) (Return (Tuple [(Name x Load) (Name y Load)] Load)) (Return (Tuple [(Name x Load) (Name y Load)] Load)) (Return (Tuple [(Name x Load) (Name y Load)] Load)) (Return (Tuple [(Name x Load) (Name y Load)] Load)) (Global [a]) (Global [a b]) (Nonlocal [a]) (Nonlocal [a b]) (Expr (ConstantInt 123 ())) (Expr (UnaryOp USub (ConstantInt 123 ()))) (Expr (UnaryOp USub (ConstantInt 291 ()))) (Expr (ConstantInt 6844 ())) (Expr (UnaryOp USub (ConstantInt 83 ()))) (Expr (ConstantInt 87 ())) (Expr (UnaryOp USub (ConstantInt 13 ()))) (Expr (ConstantInt 13 ())) (Expr (ConstantInt 32768 ())) (Expr (ConstantInt 12 ())) (Expr (ConstantInt 23440334322333 ())) (Expr (ConstantFloat 1.23000000000000000e+02 ())) (Expr (ConstantFloat 1.23450000000000003e+02 ())) (Expr (ConstantFloat 1.23400000000000000e+11 ())) (Expr (BinOp (ConstantInt 12 ()) Add (ConstantComplex 0.00000000000000000e+00 3.00000000000000000e+00 ()))) (Expr (BinOp (ConstantFloat 1.19999999999999996e-01 ()) Add (ConstantComplex 0.00000000000000000e+00 1.00000000000000002e-03 ()))) (Expr (ConstantStr "String" ())) (Expr (ConstantStr "String String" ())) (Expr (ConstantStr "String String" ())) (Expr (ConstantStr "String String" ())) (Expr (Subscript (ConstantStr "String String" ()) (Slice (ConstantInt 1 ()) () ()) Load)) (Assign [(Name x Store)] (ConstantStr "String String" ()) ()) (Assign [(Name x Store)] (BinOp (ConstantStr "String " ()) Add (ConstantStr "String" ())) ()) (Assign [(Name x Store)] (ConstantStr "String String" ()) ()) (Assign [(Name x Store)] (ConstantStr "String String" ()) ()) (Assign [(Name x Store)] (ConstantStr "String " ()) ()) (Expr (ConstantStr "String" ())) (Expr (ConstantBool .true. ())) (Expr (ConstantBool .false. ())) (Expr (BinOp (BinOp (Name x Load) Add (Name y Load)) Mult (Name z Load))) (Expr (BinOp (Name x Load) Sub (Name y Load))) (Expr (BinOp (Name x Load) Mult (Name y Load))) (Expr (BinOp (Name x Load) Div (Name y Load))) (Expr (BinOp (Name x Load) Mod (Name y Load))) (Expr (UnaryOp USub (Name y Load))) (Expr (UnaryOp UAdd (Name y Load))) (Expr (UnaryOp Invert (Name y Load))) (Expr (BinOp (Name x Load) Pow (Name y Load))) (Expr (BinOp (Name x Load) FloorDiv (Name y Load))) (Expr (BinOp (Name x Load) MatMult (Name y Load))) (Expr (BinOp (Name x Load) BitAnd (Name y Load))) (Expr (BinOp (Name x Load) BitOr (Name y Load))) (Expr (BinOp (Name x Load) BitXor (Name y Load))) (Expr (BinOp (Name x Load) LShift (Name y Load))) (Expr (BinOp (Name x Load) RShift (Name y Load))) (Expr (Compare (Name x Load) Eq [(Name y Load)])) (Expr (Compare (Name x Load) NotEq [(Name y Load)])) (Expr (Compare (Name x Load) Lt [(Name y Load)])) (Expr (Compare (Name x Load) LtE [(Name y Load)])) (Expr (Compare (Name x Load) Gt [(Name y Load)])) (Expr (Compare (Name x Load) GtE [(Name y Load)])) (If (Compare (Call (Name type Load) [(Name x Load)] []) Is [(Name int Load)]) [(Pass)] []) (If (Compare (Compare (BinOp (BinOp (BinOp (ConstantInt 2 ()) Add (ConstantInt 3 ())) Div (ConstantInt 2 ())) Sub (ConstantInt 1 ())) Is [(ConstantInt 5 ())]) Is [(ConstantBool .true. ())]) [(Pass)] []) (If (Compare (Name x Load) IsNot [(Call (Name type Load) [(Name float Load)] [])]) [(Pass)] []) (If (Compare (Name x Load) IsNot [(Call (Name type Load) [(Name int Load)] [])]) [(Pass)] []) (Assign [(Name a Store)] (List [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())] Load) ()) (If (Compare (Name a Load) NotIn [(List [(ConstantInt 1 ()) (ConstantInt 2 ())] Load)]) [(Pass)] []) (If (Compare (Compare (Name a Load) NotIn [(List [(ConstantInt 1 ()) (ConstantInt 2 ())] Load)]) NotIn [(List [(ConstantBool .true. ()) (ConstantBool .false. ())] Load)]) [(Pass)] []) (If (Compare (Name field Load) In [(List [(ConstantStr "vararg" ()) (ConstantStr "kwarg" ())] Load)]) [(If (Compare (Name value Load) Is [(ConstantNone ())]) [(Pass)] [])] []) (If (Compare (Name a Load) In [(Name list1 Load)]) [(Pass)] []) (Expr (Compare (ConstantStr "hello" ()) In [(Name x Load)])) (Expr (Compare (ConstantStr "a" ()) In [(Call (Attribute (Name a Load) func Load) [] [])])) (Expr (Compare (ConstantStr "lo" ()) In [(ConstantStr "hello" ())])) (For (Name item Store) (Name list1 Load) [(If (Compare (Name item Load) In [(Name list2 Load)]) [(Pass)] [])] [] ()) (If (BoolOp Or [(BoolOp And [(Compare (Name a Load) In [(Name list1 Load)]) (Compare (Name b Load) NotIn [(Name list2 Load)])]) (Compare (Name c Load) In [(Name list3 Load)])]) [(Pass)] []) (Assign [(Name comp Store)] (ListComp (BinOp (Name i Load) Pow (ConstantInt 2 ())) [((Name i Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [(BoolOp And [(Compare (Name i Load) NotIn [(List [(ConstantInt 3 ()) (ConstantInt 5 ()) (ConstantInt 7 ())] Load)]) (Compare (Name i Load) In [(Name list3 Load)])])] 0)]) ()) (For (Name i Store) (Compare (Name a Load) In [(Name list1 Load)]) [(Pass)] [] ()) (Expr (Subscript (Attribute (Name a Load) b Load) (ConstantInt 1 ()) Load)) (Expr (Subscript (Attribute (Name a Load) b Load) (Slice (ConstantInt 1 ()) () ()) Load)) (Expr (Subscript (Attribute (Name a Load) b Load) (Slice () (UnaryOp USub (ConstantInt 1 ())) ()) Load)) (Expr (Subscript (Attribute (Name a Load) b Load) (Slice (ConstantInt 1 ()) (ConstantInt 2 ()) ()) Load)) (Expr (Subscript (Attribute (Name a Load) b Load) (Slice () () ()) Load)) (Expr (Subscript (Attribute (Name y Load) z Load) (Slice (ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())) Load)) (Expr (Subscript (Attribute (Name y Load) z Load) (Slice (ConstantInt 1 ()) () (ConstantInt 3 ())) Load)) (Expr (Subscript (Attribute (Name y Load) z Load) (Slice (ConstantInt 1 ()) () ()) Load)) (AnnAssign (Name i Store) (Name i32 Load) (ConstantInt 4 ()) 1) (If (Compare (ConstantInt 2 ()) Gt [(Name i Load)]) [(Pass)] []) (If (Compare (Name i Load) Gt [(ConstantInt 5 ())]) [(Break)] []) (If (BoolOp And [(Compare (Name i Load) Eq [(ConstantInt 5 ())]) (Compare (Name i Load) Lt [(ConstantInt 10 ())])]) [(Assign [(Name i Store)] (ConstantInt 3 ()) ())] []) (For (Name i Store) (Call (Name range Load) [(Name N Load)] []) [(Assign [(Subscript (Name c Load) (Name i Load) Store)] (BinOp (Subscript (Name a Load) (Name i Load) Load) Add (BinOp (Name scalar Load) Mult (Subscript (Name b Load) (Name i Load) Load))) ())] [] ()) (Assign [(Name x Store)] (NamedExpr (Name y Store) (ConstantInt 0 ())) ()) (If (NamedExpr (Name a Store) (Call (Name ord Load) [(ConstantStr "3" ())] [])) [(Assign [(Name x Store)] (ConstantInt 1 ()) ())] []) (Assign [(Name a Store)] (Set [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())]) ()) (Assign [(Name b Store)] (IfExp (Compare (Name a Load) Eq [(ConstantInt 2 ())]) (ConstantInt 6 ()) (ConstantInt 8 ())) ()) (Expr (IfExp (ConstantBool .true. ()) (ConstantStr "true" ()) (ConstantStr "false" ()))) (Assign [(Name result Store)] (IfExp (UnaryOp Not (Compare (Name a Load) Gt [(Name b Load)])) (Name x Load) (Name y Load)) ()) (Expr (IfExp (Compare (Name a Load) Gt [(Name b Load)]) (Call (Name print Load) [(Name a Load) (ConstantStr "is greater" ())] []) (Call (Name print Load) [(Name b Load) (ConstantStr "is Greater" ())] [])))] [])

0 comments on commit 877872c

Please sign in to comment.