Skip to content

Commit a73c84e

Browse files
Add tests and Update refs.
1 parent e7f70b5 commit a73c84e

15 files changed

+31
-18
lines changed

tests/parser/comprehension1.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,7 @@
3838
(string[i] for i in range(len(string)-1, -1, -1))
3939

4040
k = (j + k for j, k in range(10) if j > 0)
41+
42+
(left + size + right for size, (left, right) in zip(array.shape, pad_width))
43+
44+
viter = ((i, j) for ((i, _), (j, _)) in zip(newargs[1:], args[1:]))

tests/parser/for2.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,8 @@ async def test():
5050
for a in (b, c): a**2; pass;
5151

5252
async for a in range(5): print(a)
53+
54+
for like_function in np.zeros_like, np.ones_like, np.empty_like:
55+
pass
56+
for a, in t:
57+
pass

tests/parser/statements1.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
(x, y, z) = t
2121
x, = t
2222
(x,) = t
23+
obj = obj,
2324

2425
x += 1
2526

tests/parser/tuple1.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ def test():
2424

2525
_promotion_table = { (int8, int8): int8 }
2626

27-
# TODO
28-
# 1, 2,
29-
# 1, 2
27+
x, y
28+
x, y,
29+
assert_(np.isnan(div)), 'dt: %s, rem: %s' % (dt, rem)

tests/parser/yield.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ def func():
1515
for _ in x:
1616
yield
1717

18+
yield x, y
19+
yield x, y,
20+
1821
def iterable1():
1922
yield 1
2023
yield 2

tests/reference/ast_new-comprehension1-69cf2af.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
"basename": "ast_new-comprehension1-69cf2af",
33
"cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}",
44
"infile": "tests/parser/comprehension1.py",
5-
"infile_hash": "db1a35055ce4df698bffbd406fc34ab9fb183a91366f6289575b71d8",
5+
"infile_hash": "86299dc3e7927f4d06bb55bce36c88a6833bb6e1801a3f1c758c6266",
66
"outfile": null,
77
"outfile_hash": null,
88
"stdout": "ast_new-comprehension1-69cf2af.stdout",
9-
"stdout_hash": "965115c1326ba5d293a5e01ecd8b5d83bbd4392a7ba1eea0f08ef82f",
9+
"stdout_hash": "2215f7cfded5c53e72d9f7768eb71be7d0514402ad2ec993ed1b577e",
1010
"stderr": null,
1111
"stderr_hash": null,
1212
"returncode": 0
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +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)]) ()) (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)]) ())] [])
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)]) ()) (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)]) ()) (Expr (GeneratorExp (BinOp (BinOp (Name left Load) Add (Name size Load)) Add (Name right Load)) [((Tuple [(Name size Store) (Tuple [(Name left Store) (Name right Store)] Store)] Store) (Call (Name zip Load) [(Attribute (Name array Load) shape Load) (Name pad_width Load)] []) [] 0)])) (Assign [(Name viter Store)] (GeneratorExp (Tuple [(Name i Load) (Name j Load)] Load) [((Tuple [(Tuple [(Name i Store) (Name _ Store)] Store) (Tuple [(Name j Store) (Name _ Store)] Store)] Store) (Call (Name zip Load) [(Subscript (Name newargs Load) (Slice (ConstantInt 1 ()) () ()) Load) (Subscript (Name args Load) (Slice (ConstantInt 1 ()) () ()) Load)] []) [] 0)]) ())] [])

tests/reference/ast_new-for2-af08901.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
"basename": "ast_new-for2-af08901",
33
"cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}",
44
"infile": "tests/parser/for2.py",
5-
"infile_hash": "5b2063381273e132aae18d9ba76c775c5743c66592fd42046b030543",
5+
"infile_hash": "32c45d5c5edc44504a3fa5d24c6c1660977d2ceceeef311ee5a37410",
66
"outfile": null,
77
"outfile_hash": null,
88
"stdout": "ast_new-for2-af08901.stdout",
9-
"stdout_hash": "a6ef674db9539591e9e5c0409f91b616ba70008d77b975d5074196fa",
9+
"stdout_hash": "d8c03cf0ef7c1473ea457b1282da26a047e1b110c5fab6494cf434cd",
1010
"stderr": null,
1111
"stderr_hash": null,
1212
"returncode": 0
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
(Module [(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))) ())] [] "parallel") (AnnAssign (Name i Store) (Name i32 Load) () 1) (For (Name i Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [(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) (Compare (Name a Load) In [(Name list1 Load)]) [(Pass)] [] ()) (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)] []) (For (Name f Store) (Tuple [(Name a Load) (Name b Load) (Name c Load) (Name d Load)] Load) [(Pass)] [] ()) (For (Name x Store) (Tuple [(Name a Load)] Load) [(Pass)] [] ()) (For (Name x Store) (Tuple [(Name a Load)] Load) [(Pass)] [] ()) (For (Name x Store) (Tuple [(Name a Load) (Name b Load)] Load) [(Pass)] [] ()) (AsyncFunctionDef test ([] [] [] [] [] [] []) [(AsyncFor (Name x Store) (Tuple [(Name a Load) (Name b Load)] Load) [(Pass)] [] ()) (AsyncFor (Name x Store) (Tuple [(Name a Load)] Load) [(Pass)] [] ())] [] () ()) (For (Name a Store) (Tuple [(Name b Load) (Name c Load)] Load) [(Expr (BinOp (Name a Load) Pow (ConstantInt 2 ()))) (Pass)] [] ()) (AsyncFor (Name a Store) (Call (Name range Load) [(ConstantInt 5 ())] []) [(Expr (Call (Name print Load) [(Name a Load)] []))] [] ())] [])
1+
(Module [(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))) ())] [] "parallel") (AnnAssign (Name i Store) (Name i32 Load) () 1) (For (Name i Store) (Call (Name range Load) [(ConstantInt 10 ())] []) [(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) (Compare (Name a Load) In [(Name list1 Load)]) [(Pass)] [] ()) (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)] []) (For (Name f Store) (Tuple [(Name a Load) (Name b Load) (Name c Load) (Name d Load)] Load) [(Pass)] [] ()) (For (Name x Store) (Tuple [(Name a Load)] Load) [(Pass)] [] ()) (For (Name x Store) (Tuple [(Name a Load)] Load) [(Pass)] [] ()) (For (Name x Store) (Tuple [(Name a Load) (Name b Load)] Load) [(Pass)] [] ()) (AsyncFunctionDef test ([] [] [] [] [] [] []) [(AsyncFor (Name x Store) (Tuple [(Name a Load) (Name b Load)] Load) [(Pass)] [] ()) (AsyncFor (Name x Store) (Tuple [(Name a Load)] Load) [(Pass)] [] ())] [] () ()) (For (Name a Store) (Tuple [(Name b Load) (Name c Load)] Load) [(Expr (BinOp (Name a Load) Pow (ConstantInt 2 ()))) (Pass)] [] ()) (AsyncFor (Name a Store) (Call (Name range Load) [(ConstantInt 5 ())] []) [(Expr (Call (Name print Load) [(Name a Load)] []))] [] ()) (For (Name like_function Store) (Tuple [(Attribute (Name np Load) zeros_like Load) (Attribute (Name np Load) ones_like Load) (Attribute (Name np Load) empty_like Load)] Load) [(Pass)] [] ()) (For (Tuple [(Name a Store)] Store) (Name t Load) [(Pass)] [] ())] [])

tests/reference/ast_new-statements1-e081093.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
"basename": "ast_new-statements1-e081093",
33
"cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}",
44
"infile": "tests/parser/statements1.py",
5-
"infile_hash": "cec0db26e0950c7680ae773a867e0f6c1e6c1c6d8d782e42c0e6ee5c",
5+
"infile_hash": "795f2671c2e282f01d1715deac8bdb342dbef6df5962ded5a3a045d1",
66
"outfile": null,
77
"outfile_hash": null,
88
"stdout": "ast_new-statements1-e081093.stdout",
9-
"stdout_hash": "0aec07bcf0f9f9c7ad8f3098d37a9d8a498af6adf0c9953499220991",
9+
"stdout_hash": "8c0a1dd6e96f4b8ec7a5fd2996b0474d5d2e2f947b02e74658656067",
1010
"stderr": null,
1111
"stderr_hash": null,
1212
"returncode": 0

0 commit comments

Comments
 (0)