Skip to content

Commit

Permalink
Add tests and update the references
Browse files Browse the repository at this point in the history
  • Loading branch information
Thirumalai-Shaktivel committed Jul 18, 2022
1 parent daa524c commit 4a0c910
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 11 deletions.
9 changes: 4 additions & 5 deletions tests/parser/function_def1.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ def check():

check()

# TODO:
# def print_args(*args):
# print(args)
def print_args(*args):
print(args)

# def print_kwargs(**kwargs):
# print(kwargs)
def print_kwargs(**kwargs):
print(kwargs)
33 changes: 33 additions & 0 deletions tests/parser/function_def2.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,39 @@ def test_12(x, **args):
def test_14(x, *y, z, **args: i32) -> i32:
pass

def test_15(a, /):
pass

def test_16(a, /, b, c):
pass

def test_17(a, /, *b):
pass

def test_18(a:i32, /, *b: i64, c: i32, d: i32):
pass

def test_19(a, /, *b, c, **d):
pass

def test_20(a, /, **b):
pass

def test_21(a, /, *b, **c):
pass

def test_22(a, /, b, c, *d):
pass

def test_23(a, /, b, c, **d):
pass

def test_24(a, /, b, c, *d, **e):
pass

def test_25(a, /, b, c, *d, e, **f):
pass

test()
test(x, y)
test(x, y = 1, z = '123')
Expand Down
4 changes: 2 additions & 2 deletions tests/reference/ast_new-function_def1-1a872df.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"basename": "ast_new-function_def1-1a872df",
"cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}",
"infile": "tests/parser/function_def1.py",
"infile_hash": "9dc3cbaa399b8013e99cf165c76d468cf48edde757daafc4069cda40",
"infile_hash": "96c4a34f72e609e55af1688b793dc2d6fb375f82f661d16de0ea6fa9",
"outfile": null,
"outfile_hash": null,
"stdout": "ast_new-function_def1-1a872df.stdout",
"stdout_hash": "62bdf27fa9795b9cad94f2747ac48dfac223ef7401dc9af0b445c5a8",
"stdout_hash": "ad5ea65f2ef1994819a5c48936f936ea955303c08253419d72aa450b",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
2 changes: 1 addition & 1 deletion tests/reference/ast_new-function_def1-1a872df.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
the person passed in as
a parameter
" ())) (Expr (Call (Name print Load) [(BinOp (BinOp (ConstantStr "Hello, " ()) Add (Name name Load)) Add (ConstantStr ". Good morning!" ()))] []))] [] () ()) (FunctionDef absolute_value ([] [(num () ())] [] [] [] [] []) [(Expr (ConstantStr "This function returns the absolute
value of the entered number" ())) (If (Compare (Name num Load) GtE [(ConstantInt 0 ())]) [(Return (Name num Load))] [(Return (UnaryOp USub (Name num Load)))])] [] () ()) (FunctionDef combine ([] [(fname () ()) (lname () ())] [] [] [] [] []) [(Expr (Call (Name print Load) [(BinOp (BinOp (Name fname Load) Add (ConstantStr " " ())) Add (Name lname Load))] []))] [] () ()) (FunctionDef tri_recursion ([] [(k () ())] [] [] [] [] []) [(If (Compare (Name k Load) Gt [(ConstantInt 0 ())]) [(Assign [(Name result Store)] (BinOp (Name k Load) Add (Call (Name tri_recursion Load) [(BinOp (Name k Load) Sub (ConstantInt 1 ()))] [])) ()) (Expr (Call (Name print Load) [(Name result Load)] []))] [(Assign [(Name result Store)] (ConstantInt 0 ()) ())]) (Return (Name result Load))] [] () ()) (FunctionDef test ([] [(a (Name i32 Load) ())] [] [] [] [] []) [(Return (BinOp (Name a Load) Add (ConstantInt 10 ())))] [(Name overload Load)] (Name i32 Load) ()) (FunctionDef test ([] [(a (Name i64 Load) ())] [] [] [] [] []) [(Return (BinOp (Name a Load) Add (ConstantInt 10 ())))] [(Name overload Load)] (Name i64 Load) ()) (FunctionDef test ([] [(a (Name bool Load) ())] [] [] [] [] []) [(If (Name a Load) [(Return (ConstantInt 10 ()))] []) (Return (UnaryOp USub (ConstantInt 10 ())))] [(Name overload Load)] (Name i32 Load) ()) (FunctionDef check ([] [] [] [] [] [] []) [(Expr (Call (Name greet Load) [(ConstantStr "Xyz" ())] [])) (Expr (Call (Name print Load) [(Call (Name absolute_value Load) [(ConstantInt 2 ())] [])] [])) (Expr (Call (Name combine Load) [(ConstantStr "LPython" ()) (ConstantStr "Compiler" ())] [])) (Expr (Call (Name print Load) [(ConstantStr "Recursion Example Results: " ())] [])) (Expr (Call (Name tri_recursion Load) [(ConstantInt 6 ())] [])) (Expr (Call (Name print Load) [(Call (Name test Load) [(ConstantInt 15 ())] [])] [])) (Expr (Call (Name print Load) [(Call (Name test Load) [(ConstantBool .true. ())] [])] []))] [] () ()) (Expr (Call (Name check Load) [] []))] [])
value of the entered number" ())) (If (Compare (Name num Load) GtE [(ConstantInt 0 ())]) [(Return (Name num Load))] [(Return (UnaryOp USub (Name num Load)))])] [] () ()) (FunctionDef combine ([] [(fname () ()) (lname () ())] [] [] [] [] []) [(Expr (Call (Name print Load) [(BinOp (BinOp (Name fname Load) Add (ConstantStr " " ())) Add (Name lname Load))] []))] [] () ()) (FunctionDef tri_recursion ([] [(k () ())] [] [] [] [] []) [(If (Compare (Name k Load) Gt [(ConstantInt 0 ())]) [(Assign [(Name result Store)] (BinOp (Name k Load) Add (Call (Name tri_recursion Load) [(BinOp (Name k Load) Sub (ConstantInt 1 ()))] [])) ()) (Expr (Call (Name print Load) [(Name result Load)] []))] [(Assign [(Name result Store)] (ConstantInt 0 ()) ())]) (Return (Name result Load))] [] () ()) (FunctionDef test ([] [(a (Name i32 Load) ())] [] [] [] [] []) [(Return (BinOp (Name a Load) Add (ConstantInt 10 ())))] [(Name overload Load)] (Name i32 Load) ()) (FunctionDef test ([] [(a (Name i64 Load) ())] [] [] [] [] []) [(Return (BinOp (Name a Load) Add (ConstantInt 10 ())))] [(Name overload Load)] (Name i64 Load) ()) (FunctionDef test ([] [(a (Name bool Load) ())] [] [] [] [] []) [(If (Name a Load) [(Return (ConstantInt 10 ()))] []) (Return (UnaryOp USub (ConstantInt 10 ())))] [(Name overload Load)] (Name i32 Load) ()) (FunctionDef check ([] [] [] [] [] [] []) [(Expr (Call (Name greet Load) [(ConstantStr "Xyz" ())] [])) (Expr (Call (Name print Load) [(Call (Name absolute_value Load) [(ConstantInt 2 ())] [])] [])) (Expr (Call (Name combine Load) [(ConstantStr "LPython" ()) (ConstantStr "Compiler" ())] [])) (Expr (Call (Name print Load) [(ConstantStr "Recursion Example Results: " ())] [])) (Expr (Call (Name tri_recursion Load) [(ConstantInt 6 ())] [])) (Expr (Call (Name print Load) [(Call (Name test Load) [(ConstantInt 15 ())] [])] [])) (Expr (Call (Name print Load) [(Call (Name test Load) [(ConstantBool .true. ())] [])] []))] [] () ()) (Expr (Call (Name check Load) [] [])) (FunctionDef print_args ([] [] [(args () ())] [] [] [] []) [(Expr (Call (Name print Load) [(Name args Load)] []))] [] () ()) (FunctionDef print_kwargs ([] [] [] [] [] [(kwargs () ())] []) [(Expr (Call (Name print Load) [(Name kwargs Load)] []))] [] () ())] [])
4 changes: 2 additions & 2 deletions tests/reference/ast_new-function_def2-52c4587.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"basename": "ast_new-function_def2-52c4587",
"cmd": "lpython --show-ast --new-parser --no-color {infile} -o {outfile}",
"infile": "tests/parser/function_def2.py",
"infile_hash": "44a8d24fcf31af93aea063d957af107d51131ae5eca3762eb0bdbf35",
"infile_hash": "1c1ef66b8a604487d0d72ea97722f252ea0424b9d43beca8ac27d386",
"outfile": null,
"outfile_hash": null,
"stdout": "ast_new-function_def2-52c4587.stdout",
"stdout_hash": "ee51c7c928d4540f2cce026e78ec52910501a82790a7a0cf4ce8e505",
"stdout_hash": "f8afc2e912a93370a4ad5bcb847899a1fabb9785b53d7fe884b5e757",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
2 changes: 1 addition & 1 deletion tests/reference/ast_new-function_def2-52c4587.stdout
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(Module [(FunctionDef test_01 ([] [] [] [] [] [] []) [(Pass)] [] () ()) (FunctionDef test_02 ([] [] [(x (Name i32 Load) ())] [] [] [] []) [(Pass)] [] () ()) (FunctionDef test_03 ([] [] [(x () ())] [(y () ()) (z () ())] [] [] []) [(Pass)] [] () ()) (FunctionDef test_04 ([] [] [(x () ())] [(y () ()) (z () ())] [] [(args () ())] []) [(Pass)] [] () ()) (FunctionDef test_05 ([] [] [(x () ())] [] [] [(args () ())] []) [(Pass)] [] () ()) (FunctionDef test_06 ([] [] [] [] [] [(args () ())] []) [(Pass)] [] () ()) (FunctionDef test_07 ([] [(x (Name i32 Load) ()) (y () ())] [] [] [] [] []) [(Pass)] [] () ()) (FunctionDef test_08 ([] [(x () ())] [(y () ())] [] [] [] []) [(Pass)] [] () ()) (FunctionDef test_09 ([] [(x () ())] [(y () ())] [(z () ())] [] [] []) [(Pass)] [] () ()) (FunctionDef test_10 ([] [(x () ())] [(y () ())] [(z () ())] [] [(args (Name i32 Load) ())] []) [(Pass)] [] () ()) (FunctionDef test_11 ([] [(x () ())] [(y () ())] [] [] [(args () ())] []) [(Pass)] [] () ()) (FunctionDef test_12 ([] [(x () ())] [] [] [] [(args () ())] []) [(Pass)] [] () ()) (Expr (ConstantStr "
TODO: defaults are not stored in AST
" ())) (FunctionDef test_14 ([] [(x () ())] [(y () ())] [(z () ())] [] [(args (Name i32 Load) ())] []) [(Pass)] [] (Name i32 Load) ()) (Expr (Call (Name test Load) [] [])) (Expr (Call (Name test Load) [(Name x Load) (Name y Load)] [])) (Expr (Call (Name test Load) [(Name x Load)] [(y (ConstantInt 1 ())) (z (ConstantStr "123" ()))])) (Expr (Call (Name test Load) [(ConstantInt 100 ())] [(() (Name x Load))])) (Expr (Call (Name test Load) [(Starred (Name x Load) Load)] [(() (Name y Load))])) (Expr (Call (Name test Load) [(Starred (Name x Load) Load) (Name y Load)] [])) (Expr (Call (Name test Load) [(Starred (Name x Load) Load) (Starred (Name y Load) Load)] [])) (Expr (Call (Name test Load) [] [(() (Name x Load)) (() (Name y Load))])) (Expr (Call (Attribute (Name lp Load) test Load) [] [])) (Expr (Call (Attribute (Name lp Load) test Load) [(Name x Load) (Name y Load)] [])) (Expr (Call (Attribute (Name lp Load) test Load) [(Name x Load)] [(y (ConstantInt 1 ())) (z (ConstantStr "123" ()))]))] [])
" ())) (FunctionDef test_14 ([] [(x () ())] [(y () ())] [(z () ())] [] [(args (Name i32 Load) ())] []) [(Pass)] [] (Name i32 Load) ()) (FunctionDef test_15 ([(a () ())] [] [] [] [] [] []) [(Pass)] [] () ()) (FunctionDef test_16 ([(a () ())] [(b () ()) (c () ())] [] [] [] [] []) [(Pass)] [] () ()) (FunctionDef test_17 ([(a () ())] [] [(b () ())] [] [] [] []) [(Pass)] [] () ()) (FunctionDef test_18 ([(a (Name i32 Load) ())] [] [(b (Name i64 Load) ())] [(c (Name i32 Load) ()) (d (Name i32 Load) ())] [] [] []) [(Pass)] [] () ()) (FunctionDef test_19 ([(a () ())] [] [(b () ())] [(c () ())] [] [(d () ())] []) [(Pass)] [] () ()) (FunctionDef test_20 ([(a () ())] [] [] [] [] [(b () ())] []) [(Pass)] [] () ()) (FunctionDef test_21 ([(a () ())] [] [(b () ())] [] [] [(c () ())] []) [(Pass)] [] () ()) (FunctionDef test_22 ([(a () ())] [(b () ()) (c () ())] [(d () ())] [] [] [] []) [(Pass)] [] () ()) (FunctionDef test_23 ([(a () ())] [(b () ()) (c () ())] [] [] [] [(d () ())] []) [(Pass)] [] () ()) (FunctionDef test_24 ([(a () ())] [(b () ()) (c () ())] [(d () ())] [] [] [(e () ())] []) [(Pass)] [] () ()) (FunctionDef test_25 ([(a () ())] [(b () ()) (c () ())] [(d () ())] [(e () ())] [] [(f () ())] []) [(Pass)] [] () ()) (Expr (Call (Name test Load) [] [])) (Expr (Call (Name test Load) [(Name x Load) (Name y Load)] [])) (Expr (Call (Name test Load) [(Name x Load)] [(y (ConstantInt 1 ())) (z (ConstantStr "123" ()))])) (Expr (Call (Name test Load) [(ConstantInt 100 ())] [(() (Name x Load))])) (Expr (Call (Name test Load) [(Starred (Name x Load) Load)] [(() (Name y Load))])) (Expr (Call (Name test Load) [(Starred (Name x Load) Load) (Name y Load)] [])) (Expr (Call (Name test Load) [(Starred (Name x Load) Load) (Starred (Name y Load) Load)] [])) (Expr (Call (Name test Load) [] [(() (Name x Load)) (() (Name y Load))])) (Expr (Call (Attribute (Name lp Load) test Load) [] [])) (Expr (Call (Attribute (Name lp Load) test Load) [(Name x Load) (Name y Load)] [])) (Expr (Call (Attribute (Name lp Load) test Load) [(Name x Load)] [(y (ConstantInt 1 ())) (z (ConstantStr "123" ()))]))] [])

0 comments on commit 4a0c910

Please sign in to comment.