Skip to content

Add more tests for subscript #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/reference/asr-subscript1-1acfc19.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"basename": "asr-subscript1-1acfc19",
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
"infile": "tests/subscript1.py",
"infile_hash": "24efc3980ad13e8772a093253b380c91ce3b38071d69200e5af33d36",
"infile_hash": "5d229893d3e13ea4463e8ed47eb3798be0b8c28f5ef6b6c773e87b80",
"outfile": null,
"outfile_hash": null,
"stdout": "asr-subscript1-1acfc19.stdout",
"stdout_hash": "f7bf6b29c18149b3c536af48eb59a1133156ac03fba83603a083d0fb",
"stdout_hash": "bb7b8b7478d50742985082735dfa0d2cf059f67e66a730c1c14915e2",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
2 changes: 1 addition & 1 deletion tests/reference/asr-subscript1-1acfc19.stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(TranslationUnit (SymbolTable 1 {main_program: (Program (SymbolTable 3 {}) main_program [] []), test_subscript: (Subroutine (SymbolTable 2 {A: (Variable 2 A Local () () Default (Integer 4 [((ConstantInteger 1 (Integer 4 [])) (ConstantInteger 5 (Integer 4 [])))]) Source Public Required .false.), B: (Variable 2 B Local () () Default (Integer 4 [((ConstantInteger 1 (Integer 4 [])) (ConstantInteger 2 (Integer 4 [])))]) Source Public Required .false.), i: (Variable 2 i Local () () Default (Integer 4 []) Source Public Required .false.), s: (Variable 2 s Local () () Default (Character 1 -2 () []) Source Public Required .false.)}) test_subscript [] [(= (Var 2 s) (ConstantString "abc" (Character 1 3 () [])) ()) (= (Var 2 s) (ArrayRef 2 s [(() (ConstantInteger 0 (Integer 4 [])) ())] (Character 1 -2 () []) ()) ()) (= (Var 2 s) (ArrayRef 2 s [((ConstantInteger 1 (Integer 4 [])) (ConstantInteger 2 (Integer 4 [])) ())] (Character 1 -2 () []) ()) ()) (= (Var 2 i) (ArrayRef 2 A [(() (ConstantInteger 0 (Integer 4 [])) ())] (Integer 4 [((ConstantInteger 1 (Integer 4 [])) (ConstantInteger 5 (Integer 4 [])))]) ()) ()) (= (Var 2 B) (ArrayRef 2 A [((ConstantInteger 1 (Integer 4 [])) (ConstantInteger 3 (Integer 4 [])) ())] (Integer 4 [((ConstantInteger 1 (Integer 4 [])) (ConstantInteger 5 (Integer 4 [])))]) ()) ())] Source Public Implementation () .false. .false.)}) [])
(TranslationUnit (SymbolTable 1 {main_program: (Program (SymbolTable 3 {}) main_program [] []), test_subscript: (Subroutine (SymbolTable 2 {A: (Variable 2 A Local () () Default (Integer 4 [((ConstantInteger 1 (Integer 4 [])) (ConstantInteger 5 (Integer 4 [])))]) Source Public Required .false.), B: (Variable 2 B Local () () Default (Integer 4 [((ConstantInteger 1 (Integer 4 [])) (ConstantInteger 2 (Integer 4 [])))]) Source Public Required .false.), i: (Variable 2 i Local () () Default (Integer 4 []) Source Public Required .false.), s: (Variable 2 s Local () () Default (Character 1 -2 () []) Source Public Required .false.)}) test_subscript [] [(= (Var 2 s) (ConstantString "abc" (Character 1 3 () [])) ()) (= (Var 2 s) (ArrayRef 2 s [(() (ConstantInteger 0 (Integer 4 [])) ())] (Character 1 -2 () []) ()) ()) (= (Var 2 s) (ArrayRef 2 s [((ConstantInteger 1 (Integer 4 [])) (ConstantInteger 2 (Integer 4 [])) ())] (Character 1 -2 () []) ()) ()) (= (Var 2 s) (ArrayRef 2 s [(() () ())] (Character 1 -2 () []) ()) ()) (= (Var 2 s) (ArrayRef 2 s [(() () (UnaryOp USub (ConstantInteger 1 (Integer 4 [])) (Integer 4 []) (ConstantInteger -1 (Integer 4 []))))] (Character 1 -2 () []) ()) ()) (= (Var 2 s) (ArrayRef 2 s [(() () (ConstantInteger 2 (Integer 4 [])))] (Character 1 -2 () []) ()) ()) (= (Var 2 s) (ArrayRef 2 s [((ConstantInteger 1 (Integer 4 [])) (ConstantInteger 88 (Integer 4 [])) (ConstantInteger 1 (Integer 4 [])))] (Character 1 -2 () []) ()) ()) (= (Var 2 s) (ArrayRef 2 s [(() (ConstantInteger 1 (Integer 4 [])) (UnaryOp USub (ConstantInteger 4 (Integer 4 [])) (Integer 4 []) (ConstantInteger -4 (Integer 4 []))))] (Character 1 -2 () []) ()) ()) (= (Var 2 s) (ArrayRef 2 s [((UnaryOp USub (ConstantInteger 89 (Integer 4 [])) (Integer 4 []) (ConstantInteger -89 (Integer 4 []))) () (ConstantInteger 4 (Integer 4 [])))] (Character 1 -2 () []) ()) ()) (= (Var 2 s) (ArrayRef 2 s [((UnaryOp USub (ConstantInteger 3 (Integer 4 [])) (Integer 4 []) (ConstantInteger -3 (Integer 4 []))) (UnaryOp USub (ConstantInteger 3 (Integer 4 [])) (Integer 4 []) (ConstantInteger -3 (Integer 4 []))) (UnaryOp USub (ConstantInteger 3 (Integer 4 [])) (Integer 4 []) (ConstantInteger -3 (Integer 4 []))))] (Character 1 -2 () []) ()) ()) (= (Var 2 s) (ArrayRef 2 s [((ConstantInteger 2 (Integer 4 [])) (ConstantInteger 3 (Integer 4 [])) ())] (Character 1 -2 () []) ()) ()) (= (Var 2 i) (ArrayRef 2 A [(() (ConstantInteger 0 (Integer 4 [])) ())] (Integer 4 [((ConstantInteger 1 (Integer 4 [])) (ConstantInteger 5 (Integer 4 [])))]) ()) ()) (= (Var 2 B) (ArrayRef 2 A [((ConstantInteger 1 (Integer 4 [])) (ConstantInteger 3 (Integer 4 [])) ())] (Integer 4 [((ConstantInteger 1 (Integer 4 [])) (ConstantInteger 5 (Integer 4 [])))]) ()) ()) (= (Var 2 B) (ArrayRef 2 A [((ConstantInteger 1 (Integer 4 [])) (ConstantInteger 2 (Integer 4 [])) (ConstantInteger 3 (Integer 4 [])))] (Integer 4 [((ConstantInteger 1 (Integer 4 [])) (ConstantInteger 5 (Integer 4 [])))]) ()) ())] Source Public Implementation () .false. .false.)}) [])
4 changes: 2 additions & 2 deletions tests/reference/ast-subscript1-bd5584b.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"basename": "ast-subscript1-bd5584b",
"cmd": "lpython --show-ast --no-color {infile} -o {outfile}",
"infile": "tests/subscript1.py",
"infile_hash": "24efc3980ad13e8772a093253b380c91ce3b38071d69200e5af33d36",
"infile_hash": "5d229893d3e13ea4463e8ed47eb3798be0b8c28f5ef6b6c773e87b80",
"outfile": null,
"outfile_hash": null,
"stdout": "ast-subscript1-bd5584b.stdout",
"stdout_hash": "a3078483928581b43987ad69903c0319507833a869b1e1fe7d52edb5",
"stdout_hash": "64e0e5bf1c53e455034996484f2449e2e18f526448a00dd79b58fb32",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
2 changes: 1 addition & 1 deletion tests/reference/ast-subscript1-bd5584b.stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(Module [(FunctionDef test_subscript ([] [] [] [] [] [] []) [(AnnAssign (Name s Store) (Name str Load) () 1) (Assign [(Name s Store)] (ConstantStr "abc" ()) ()) (Assign [(Name s Store)] (Subscript (Name s Load) (ConstantInt 0 ()) Load) ()) (Assign [(Name s Store)] (Subscript (Name s Load) (Slice (ConstantInt 1 ()) (ConstantInt 2 ()) ()) Load) ()) (AnnAssign (Name A Store) (Subscript (Name i32 Load) (ConstantInt 5 ()) Load) () 1) (AnnAssign (Name B Store) (Subscript (Name i32 Load) (ConstantInt 2 ()) Load) () 1) (AnnAssign (Name i Store) (Name i32 Load) () 1) (Assign [(Name i Store)] (Subscript (Name A Load) (ConstantInt 0 ()) Load) ()) (Assign [(Name B Store)] (Subscript (Name A Load) (Slice (ConstantInt 1 ()) (ConstantInt 3 ()) ()) Load) ())] [] () ())] [])
(Module [(FunctionDef test_subscript ([] [] [] [] [] [] []) [(AnnAssign (Name s Store) (Name str Load) () 1) (Assign [(Name s Store)] (ConstantStr "abc" ()) ()) (Assign [(Name s Store)] (Subscript (Name s Load) (ConstantInt 0 ()) Load) ()) (Assign [(Name s Store)] (Subscript (Name s Load) (Slice (ConstantInt 1 ()) (ConstantInt 2 ()) ()) Load) ()) (Assign [(Name s Store)] (Subscript (Name s Load) (Slice () () ()) Load) ()) (Assign [(Name s Store)] (Subscript (Name s Load) (Slice () () (UnaryOp USub (ConstantInt 1 ()))) Load) ()) (Assign [(Name s Store)] (Subscript (Name s Load) (Slice () () (ConstantInt 2 ())) Load) ()) (Assign [(Name s Store)] (Subscript (Name s Load) (Slice (ConstantInt 1 ()) (ConstantInt 88 ()) (ConstantInt 1 ())) Load) ()) (Assign [(Name s Store)] (Subscript (Name s Load) (Slice () (ConstantInt 1 ()) (UnaryOp USub (ConstantInt 4 ()))) Load) ()) (Assign [(Name s Store)] (Subscript (Name s Load) (Slice (UnaryOp USub (ConstantInt 89 ())) () (ConstantInt 4 ())) Load) ()) (Assign [(Name s Store)] (Subscript (Name s Load) (Slice (UnaryOp USub (ConstantInt 3 ())) (UnaryOp USub (ConstantInt 3 ())) (UnaryOp USub (ConstantInt 3 ()))) Load) ()) (Assign [(Name s Store)] (Subscript (Name s Load) (Slice (ConstantInt 2 ()) (ConstantInt 3 ()) ()) Load) ()) (AnnAssign (Name A Store) (Subscript (Name i32 Load) (ConstantInt 5 ()) Load) () 1) (AnnAssign (Name B Store) (Subscript (Name i32 Load) (ConstantInt 2 ()) Load) () 1) (AnnAssign (Name i Store) (Name i32 Load) () 1) (Assign [(Name i Store)] (Subscript (Name A Load) (ConstantInt 0 ()) Load) ()) (Assign [(Name B Store)] (Subscript (Name A Load) (Slice (ConstantInt 1 ()) (ConstantInt 3 ()) ()) Load) ()) (Assign [(Name B Store)] (Subscript (Name A Load) (Slice (ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())) Load) ())] [] () ())] [])
10 changes: 10 additions & 0 deletions tests/subscript1.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,19 @@ def test_subscript():
s = 'abc'
s = s[0]
s = s[1:2]
s = s[::]
s = s[::-1]
s = s[::2]
s = s[1:88:1]
s = s[:1:-4]
s = s[-89::4]
s = s[-3:-3:-3]
s = s[2:3:]


A: i32[5]
B: i32[2]
i: i32
i = A[0]
B = A[1:3]
B = A[1:2:3]