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 Aug 4, 2022
1 parent e71e7f7 commit 6e20b66
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions tests/parser/comprehension1.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@
{x: x**3 for x in range(10) if x**3 % 4 == 0}

square_dict = {num: num*num for num in range(1, 11)}

(string[i] for i in range(len(string)-1, -1, -1))

k = (j + k for j, k in range(10) if j > 0)
4 changes: 2 additions & 2 deletions tests/reference/ast_new-comprehension1-69cf2af.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"basename": "ast_new-comprehension1-69cf2af",
"cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}",
"infile": "tests/parser/comprehension1.py",
"infile_hash": "b208b52ae0d54e7ad38ab8ca293018e057f0f1a10f2453ea7a69f229",
"infile_hash": "db1a35055ce4df698bffbd406fc34ab9fb183a91366f6289575b71d8",
"outfile": null,
"outfile_hash": null,
"stdout": "ast_new-comprehension1-69cf2af.stdout",
"stdout_hash": "cbbbb76c34214739a7641941ea4a3eda8054591526dc8eee88a77af5",
"stdout_hash": "965115c1326ba5d293a5e01ecd8b5d83bbd4392a7ba1eea0f08ef82f",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
2 changes: 1 addition & 1 deletion tests/reference/ast_new-comprehension1-69cf2af.stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(Module [(Assign [(Name fruits Store)] (ListComp (Name f Load) [((Name f Store) (Name fruit_list Load) [(Call (Attribute (Name f Load) startswith Load) [(ConstantStr "a" ())] [])] 0)]) ()) (Assign [(Name fruit_list Store)] (ListComp (Name fruit Load) [((Name fruit Store) (Name fruits Load) [] 0)]) ()) (Assign [(Name sum_cord Store)] (ListComp (BinOp (Name x Load) Add (Name y Load)) [((Tuple [(Name x Store) (Name y Store)] Store) (Name points Load) [(BoolOp And [(Compare (Name x Load) Gt [(ConstantInt 0 ())]) (Compare (Name y Load) Gt [(ConstantInt 0 ())])])] 0)]) ()) (Assign [(Name transform_1 Store)] (ListComp (BinOp (BinOp (ConstantInt 2 ()) Mult (Name x Load)) Add (ConstantInt 6 ())) [((Name x Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [] 0)]) ()) (Assign [(Name distance_orig Store)] (ListComp (BinOp (BinOp (BinOp (Name x Load) Pow (ConstantInt 2 ())) Add (BinOp (Name y Load) Pow (ConstantInt 2 ()))) Add (BinOp (Name z Load) Pow (ConstantInt 2 ()))) [((Tuple [(Name x Store) (Name y Store) (Name z Store)] Store) (Name points Load) [] 0)]) ()) (Assign [(Name odd_elements Store)] (ListComp (Name i Load) [((Name i Store) (Name main_list Load) [(BinOp (Name i Load) BitAnd (ConstantInt 1 ()))] 0)]) ()) (Assign [(Name first_ten_elements Store)] (ListComp (Name i Load) [((Name i Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [] 0)]) ()) (Assign [(Name another_ten_elements Store)] (ListComp (Name i Load) [((Name i Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [] 0)]) ()) (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)]) ()) (Assign [(Name prm_tup Store)] (Call (Name tuple Load) [(GeneratorExp (Call (Name next Load) [(Name parameters Load)] []) [((Name _ Store) (Attribute (Name i Load) __parameters__ Load) [] 0)])] []) ()) (Assign [(Name args Store)] (Call (Attribute (ConstantStr ", " ()) join Load) [(GeneratorExp (Call (Name _to_str Load) [(Name i Load)] []) [((Name i Store) (Attribute (Name self Load) __args__ Load) [] 0)])] []) ()) (Assign [(Name rest Store)] (Call (Name tuple Load) [(GeneratorExp (Name i Load) [((Name i Store) (Call (Name range Load) [(Attribute (Name a Load) ndim Load)] []) [(Compare (Name i Load) NotIn [(Name axis Load)])] 0)])] []) ()) (Assign [(Name newSet Store)] (SetComp (BinOp (Name element Load) Mult (ConstantInt 3 ())) [((Name element Store) (Name myList Load) [] 0)]) ()) (Assign [(Name newSet Store)] (SetComp (BinOp (Name element Load) Mult (ConstantInt 3 ())) [((Name element Store) (Name myList Load) [(Compare (BinOp (Name element Load) Mod (ConstantInt 2 ())) Eq [(ConstantInt 0 ())])] 0)]) ()) (Expr (DictComp (Name x Load) (BinOp (Name x Load) Pow (ConstantInt 3 ())) [((Name x Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [(Compare (BinOp (BinOp (Name x Load) Pow (ConstantInt 3 ())) Mod (ConstantInt 4 ())) Eq [(ConstantInt 0 ())])] 0)])) (Assign [(Name square_dict Store)] (DictComp (Name num Load) (BinOp (Name num Load) Mult (Name num Load)) [((Name num Store) (Call (Name range Load) [(ConstantInt 1 ()) (ConstantInt 11 ())] []) [] 0)]) ())] [])
(Module [(Assign [(Name fruits Store)] (ListComp (Name f Load) [((Name f Store) (Name fruit_list Load) [(Call (Attribute (Name f Load) startswith Load) [(ConstantStr "a" ())] [])] 0)]) ()) (Assign [(Name fruit_list Store)] (ListComp (Name fruit Load) [((Name fruit Store) (Name fruits Load) [] 0)]) ()) (Assign [(Name sum_cord Store)] (ListComp (BinOp (Name x Load) Add (Name y Load)) [((Tuple [(Name x Store) (Name y Store)] Store) (Name points Load) [(BoolOp And [(Compare (Name x Load) Gt [(ConstantInt 0 ())]) (Compare (Name y Load) Gt [(ConstantInt 0 ())])])] 0)]) ()) (Assign [(Name transform_1 Store)] (ListComp (BinOp (BinOp (ConstantInt 2 ()) Mult (Name x Load)) Add (ConstantInt 6 ())) [((Name x Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [] 0)]) ()) (Assign [(Name distance_orig Store)] (ListComp (BinOp (BinOp (BinOp (Name x Load) Pow (ConstantInt 2 ())) Add (BinOp (Name y Load) Pow (ConstantInt 2 ()))) Add (BinOp (Name z Load) Pow (ConstantInt 2 ()))) [((Tuple [(Name x Store) (Name y Store) (Name z Store)] Store) (Name points Load) [] 0)]) ()) (Assign [(Name odd_elements Store)] (ListComp (Name i Load) [((Name i Store) (Name main_list Load) [(BinOp (Name i Load) BitAnd (ConstantInt 1 ()))] 0)]) ()) (Assign [(Name first_ten_elements Store)] (ListComp (Name i Load) [((Name i Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [] 0)]) ()) (Assign [(Name another_ten_elements Store)] (ListComp (Name i Load) [((Name i Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [] 0)]) ()) (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)]) ()) (Assign [(Name prm_tup Store)] (Call (Name tuple Load) [(GeneratorExp (Call (Name next Load) [(Name parameters Load)] []) [((Name _ Store) (Attribute (Name i Load) __parameters__ Load) [] 0)])] []) ()) (Assign [(Name args Store)] (Call (Attribute (ConstantStr ", " ()) join Load) [(GeneratorExp (Call (Name _to_str Load) [(Name i Load)] []) [((Name i Store) (Attribute (Name self Load) __args__ Load) [] 0)])] []) ()) (Assign [(Name rest Store)] (Call (Name tuple Load) [(GeneratorExp (Name i Load) [((Name i Store) (Call (Name range Load) [(Attribute (Name a Load) ndim Load)] []) [(Compare (Name i Load) NotIn [(Name axis Load)])] 0)])] []) ()) (Assign [(Name newSet Store)] (SetComp (BinOp (Name element Load) Mult (ConstantInt 3 ())) [((Name element Store) (Name myList Load) [] 0)]) ()) (Assign [(Name newSet Store)] (SetComp (BinOp (Name element Load) Mult (ConstantInt 3 ())) [((Name element Store) (Name myList Load) [(Compare (BinOp (Name element Load) Mod (ConstantInt 2 ())) Eq [(ConstantInt 0 ())])] 0)]) ()) (Expr (DictComp (Name x Load) (BinOp (Name x Load) Pow (ConstantInt 3 ())) [((Name x Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [(Compare (BinOp (BinOp (Name x Load) Pow (ConstantInt 3 ())) Mod (ConstantInt 4 ())) Eq [(ConstantInt 0 ())])] 0)])) (Assign [(Name square_dict Store)] (DictComp (Name num Load) (BinOp (Name num Load) Mult (Name num Load)) [((Name num Store) (Call (Name range Load) [(ConstantInt 1 ()) (ConstantInt 11 ())] []) [] 0)]) ()) (Expr (GeneratorExp (Subscript (Name string Load) (Name i Load) Load) [((Name i Store) (Call (Name range Load) [(BinOp (Call (Name len Load) [(Name string Load)] []) Sub (ConstantInt 1 ())) (UnaryOp USub (ConstantInt 1 ())) (UnaryOp USub (ConstantInt 1 ()))] []) [] 0)])) (Assign [(Name k Store)] (GeneratorExp (BinOp (Name j Load) Add (Name k Load)) [((Tuple [(Name j Store) (Name k Store)] Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [(Compare (Name j Load) Gt [(ConstantInt 0 ())])] 0)]) ())] [])

0 comments on commit 6e20b66

Please sign in to comment.