Skip to content

Commit

Permalink
Merge pull request lcompilers#794 from Thirumalai-Shaktivel/tests
Browse files Browse the repository at this point in the history
Split statement tests into different tests
  • Loading branch information
certik committed Jul 19, 2022
2 parents 8e4ab9f + a1fe85a commit 14c789e
Show file tree
Hide file tree
Showing 17 changed files with 108 additions and 75 deletions.
File renamed without changes.
2 changes: 2 additions & 0 deletions tests/parser/comprehension1.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@
first_ten_elements = [i for (i) in range(10)]

another_ten_elements = [(i) for (i) in range(10)]

comp = [i**2 for i in range(10) if i not in [3, 5, 7] and i in list3]
20 changes: 20 additions & 0 deletions tests/parser/for2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
for i in range(N): # type: parallel
c[i] = a[i] + scalar * b[i]

i: i32
for i in range(10):
if 2 > i : pass
if i > 5 : break
if i == 5 and i < 10 : i = 3

# Fow showing the parsing order of 'in' in for-loop and 'in' in expr is correct
# and there is no conflict. Otherwise, the code below is gibberish.
for i in a in list1:
pass

for item in list1:
if item in list2:
pass

if a in list1 and b not in list2 or c in list3:
pass
37 changes: 37 additions & 0 deletions tests/parser/if2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
if type(x) is int:
pass

if ((2 + 3)/2 - 1 is 5) is True:
pass

if x is not type(float):
pass

if x is \
not type(int):
pass

a = [1, 2, 3]

if a not in [1, 2]:
pass

if (a not in [1, 2]) not \
in [True, False]:
pass

if field in ["vararg", "kwarg"]:
if value is None:
pass

if (a in list1):
pass

# Ternary operator (Conditional expressions)
b = 6 if a == 2 else 8

'true' if True else 'false'

result = x if not (a > b) else y

print(a,"is greater") if (a > b) else print(b,"is Greater")
61 changes: 0 additions & 61 deletions tests/parser/statements1.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,53 +108,10 @@
x > y
x >= y

if type(x) is int:
pass

if ((2 + 3)/2 - 1 is 5) is True:
pass

if x is not type(float):
pass

if x is \
not type(int):
pass

a = [1, 2, 3]

if a not in [1, 2]:
pass

if (a not in [1, 2]) not \
in [True, False]:
pass

if field in ["vararg", "kwarg"]:
if value is None:
pass

if (a in list1):
pass

"hello" in x
'a' in a.func()
'lo' in 'hello'

for item in list1:
if item in list2:
pass

if a in list1 and b not in list2 or c in list3:
pass

comp = [i**2 for i in range(10) if i not in [3, 5, 7] and i in list3]

# Fow showing the parsing order of 'in' in for-loop and 'in' in expr is correct
# and there is no conflict. Otherwise, the code below is gibberish.
for i in a in list1:
pass

a.b[1]
a.b[1:]
a.b[:-1]
Expand All @@ -164,26 +121,8 @@
y.z[1::3]
y.z[1::]

i: i32 = 4
if 2 > i : pass
if i > 5 : break
if i == 5 and i < 10 : i = 3

for i in range(N): # type: parallel
c[i] = a[i] + scalar * b[i]

x = (y := 0)
if a := ord('3'):
x = 1

a = {1, 2, 3}

# Ternary operator (Conditional expressions)

b = 6 if a == 2 else 8

'true' if True else 'false'

result = x if not (a > b) else y

print(a,"is greater") if (a > b) else print(b,"is Greater")
1 change: 0 additions & 1 deletion tests/reference/asr-test_print1-f1f36f1.stdout

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"basename": "ast_new-statements2-c4cdc5f",
"basename": "ast_new-boolOp1-478328f",
"cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}",
"infile": "tests/parser/statements2.py",
"infile": "tests/parser/boolOp1.py",
"infile_hash": "a20fee19d7b8e6f8689f6badc2726fd618524af0aba84a7d0d0e5af5",
"outfile": null,
"outfile_hash": null,
"stdout": "ast_new-statements2-c4cdc5f.stdout",
"stdout": "ast_new-boolOp1-478328f.stdout",
"stdout_hash": "8b8d1514ec03d6081c0e716170ff41615cb00f9745a71e153f25179c",
"stderr": null,
"stderr_hash": null,
Expand Down
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": "28749607f6d0963094ffca1a9f62cac0f5292451d4f6a57df0a6edf2",
"infile_hash": "b2058720de71949a22db1eb2bc8655c48dc559ada7f8ac4940c1e9a3",
"outfile": null,
"outfile_hash": null,
"stdout": "ast_new-comprehension1-69cf2af.stdout",
"stdout_hash": "82857717cc1bc07fb8b46095b37c75b69f1058abfec0899323f19b78",
"stdout_hash": "c1e396528b27d1040afcc98be5692edb79e733cb5934080408913069",
"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 Load) (Call (Name range Load) [(ConstantInt 10 ())] []) [] 0)]) ()) (Assign [(Name another_ten_elements Store)] (ListComp (Name i Load) [((Name i Load) (Call (Name range Load) [(ConstantInt 10 ())] []) [] 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 Load) (Call (Name range Load) [(ConstantInt 10 ())] []) [] 0)]) ()) (Assign [(Name another_ten_elements Store)] (ListComp (Name i Load) [((Name i Load) (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)]) ())] [])
13 changes: 13 additions & 0 deletions tests/reference/ast_new-for2-af08901.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "ast_new-for2-af08901",
"cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}",
"infile": "tests/parser/for2.py",
"infile_hash": "616253e2fd47c83340ea3676a4ea26dfa7c5ee87fdbb078da17e211c",
"outfile": null,
"outfile_hash": null,
"stdout": "ast_new-for2-af08901.stdout",
"stdout_hash": "9fd9f42e5a4baf4fdc6eaf5d3de80b209eba47dbce388f434b24fa3f",
"stderr": null,
"stderr_hash": null,
"returncode": 0
}
1 change: 1 addition & 0 deletions tests/reference/ast_new-for2-af08901.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +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)] [])] [])
13 changes: 13 additions & 0 deletions tests/reference/ast_new-if2-c3b6022.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "ast_new-if2-c3b6022",
"cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}",
"infile": "tests/parser/if2.py",
"infile_hash": "9ee68bb91c6a02de890b0ec3d50f2e84fff0a2e1d464d28b01cc42c1",
"outfile": null,
"outfile_hash": null,
"stdout": "ast_new-if2-c3b6022.stdout",
"stdout_hash": "7f83bcd67bc168b35686f4218e6dc8c9ac4ee8fdb1ae3c1ca6da137d",
"stderr": null,
"stderr_hash": null,
"returncode": 0
}
1 change: 1 addition & 0 deletions tests/reference/ast_new-if2-c3b6022.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(Module [(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)] []) (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" ())] [])))] [])
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": "57c83f799b0bb53eaba09687c23c0285a45a466c493dc3269105b66b",
"infile_hash": "00b7157f02a5a98bdac6ca52297ba0fd1175c648df82c543d0a8d232",
"outfile": null,
"outfile_hash": null,
"stdout": "ast_new-statements1-e081093.stdout",
"stdout_hash": "efb43978a8a9367cb0f8a127bcf0211f21226179fd5923c4ab3a490a",
"stdout_hash": "a6635960221bc739fbd0dfb6204cf929f7242dddbfc54eb7254f8943",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
Loading

0 comments on commit 14c789e

Please sign in to comment.