Skip to content

Commit

Permalink
more tests, incl. runtime errors
Browse files Browse the repository at this point in the history
  • Loading branch information
wkhere committed Apr 28, 2024
1 parent 7c21736 commit 1e9b01e
Show file tree
Hide file tree
Showing 2 changed files with 520 additions and 0 deletions.
267 changes: 267 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,273 @@
[64, 'eval a=42', '', "err: at '=': invalid assignment target"],
[65, 'var a; var a', '', "err: at 'a': variable with this name already present"],
[66, 'eval a', '', "err: at 'a': undefined variable"],

[67.1, 'print -1', "-1"],
[67.2, 'print -1.2', "-1.2"],
[67.3, 'print -(1)', "-1"],
[67.4, 'print -(1.2)', "-1.2"],
[67.5, 'var a=1; print -a', "-1"],
[67.6, 'var a=1.2; print -a', "-1.2"],
[67.7, 'print -true', '', "err: NEG: invalid type: bool, expected number"],
[67.8, 'print -"abc"', '', "err: NEG: invalid type: string, expected number"],
[67.9, 'print -nil', '', "err: NEG: invalid type: nil, expected number"],

[68.1, 'print +1', "1"],
[68.2, 'print +1.2', "1.2"],
[68.3, 'print +(1)', "1"],
[68.4, 'print +(1.2)', "1.2"],
[67.5, 'var a=1; print +a', "1"],
[67.6, 'var a=1.2; print +a', "1.2"],
[68.7, 'print +true', '', "err: UNPLUS: invalid type: bool, expected number"],
[68.8, 'print +"abcd"', '', "err: UNPLUS: invalid type: string, expected number"],
[68.9, 'print +nil', '', "err: UNPLUS: invalid type: nil, expected number"],

[69, 'print *1', '', "err: at '*': expected expression"],
[70, 'print /1', '', "err: at '/': expected expression"],

[71.1, 'print 1+2', '3'],
[71.2, 'print 1+2.5', '3.5'],
[71.3, 'print 1+true', '', "err: ADD: invalid types: int, bool"],
[71.4, 'print 1+"ab"', '', "err: ADD: invalid types: int, string"],
[71.5, 'print 1+nil', '', "err: ADD: invalid types: int, nil"],
[72.1, 'print 1.2+5', '6.2'],
[72.2, 'print 1.2+3.5', '4.7'],
[72.3, 'print 1.2+true', '', "err: ADD: invalid types: float, bool"],
[72.4, 'print 1.2+"ab"', '', "err: ADD: invalid types: float, string"],
[72.5, 'print 1.2+nil', '', "err: ADD: invalid types: float, nil"],
[73.1, 'print true+1', '', "err: ADD: invalid types: bool, int"],
[73.2, 'print true+1.2', '', "err: ADD: invalid types: bool, float"],
[73.3, 'print true+true', '', "err: ADD: invalid types: bool, bool"],
[73.4, 'print true+"ab"', '', "err: ADD: invalid types: bool, string"],
[73.5, 'print true+nil', '', "err: ADD: invalid types: bool, nil"],
[74.1, 'print "ab"+1', 'ab1'],
[74.2, 'print "ab"+1.2', 'ab1.2'],
[74.3, 'print "ab"+true', '', "err: ADD: invalid types: string, bool"],
[74.4, 'print "ab"+"cd"', 'abcd'],
[74.5, 'print "ab"+nil', 'ab'],
[75.1, 'print nil+1', '', "err: ADD: invalid types: nil, int"],
[75.2, 'print nil+1.2', '', "err: ADD: invalid types: nil, float"],
[75.3, 'print nil+true', '', "err: ADD: invalid types: nil, bool"],
[75.4, 'print nil+"ab"', '', "err: ADD: invalid types: nil, string"],
[75.5, 'print nil+nil', '', "err: ADD: invalid types: nil, nil"],

[76.1, 'print 1-2', '-1'],
[76.2, 'print 1-2.5', '-1.5'],
[76.3, 'print 1-true', '', "err: SUB: invalid types: int, bool"],
[76.4, 'print 1-"ab"', '', "err: SUB: invalid types: int, string"],
[76.5, 'print 1-nil', '', "err: SUB: invalid types: int, nil"],
[77.1, 'print 1.5-2', '-0.5'],
[77.2, 'print 1.0-2.5', '-1.5'],
[77.3, 'print 1.2-true', '', "err: SUB: invalid types: float, bool"],
[77.4, 'print 1.2-"ab"', '', "err: SUB: invalid types: float, string"],
[77.5, 'print 1.2-nil', '', "err: SUB: invalid types: float, nil"],
[78.1, 'print true-1', '', "err: SUB: invalid types: bool, int"],
[78.2, 'print true-1.2', '', "err: SUB: invalid types: bool, float"],
[78.3, 'print true-true', '', "err: SUB: invalid types: bool, bool"],
[78.4, 'print true-"ab"', '', "err: SUB: invalid types: bool, string"],
[78.5, 'print true-nil', '', "err: SUB: invalid types: bool, nil"],
[79.1, 'print "ab"-1', '', "err: SUB: invalid types: string, int"],
[79.2, 'print "ab"-1.2', '', "err: SUB: invalid types: string, float"],
[79.3, 'print "ab"-true', '', "err: SUB: invalid types: string, bool"],
[79.4, 'print "ab"-"cd"', '', "err: SUB: invalid types: string, string"],
[79.5, 'print "ab"-nil', '', "err: SUB: invalid types: string, nil"],
[80.1, 'print nil-1', '', "err: SUB: invalid types: nil, int"],
[80.2, 'print nil-1.2', '', "err: SUB: invalid types: nil, float"],
[80.3, 'print nil-true', '', "err: SUB: invalid types: nil, bool"],
[80.4, 'print nil-"ab"', '', "err: SUB: invalid types: nil, string"],
[80.5, 'print nil-nil', '', "err: SUB: invalid types: nil, nil"],

[81.1, 'print 1*2', '2'],
[81.2, 'print 1*2.5', '2.5'],
[81.3, 'print 1*true', '', "err: MUL: invalid types: int, bool"],
[81.4, 'print 1*"ab"', '', "err: MUL: invalid types: int, string"],
[81.5, 'print 1*nil', '', "err: MUL: invalid types: int, nil"],
[82.1, 'print 1.4*2', '2.8'],
[82.2, 'print 1.0*2.5', '2.5'],
[82.3, 'print 1.2*true', '', "err: MUL: invalid types: float, bool"],
[82.4, 'print 1.2*"ab"', '', "err: MUL: invalid types: float, string"],
[82.5, 'print 1.2*nil', '', "err: MUL: invalid types: float, nil"],
[83.1, 'print true*1', '', "err: MUL: invalid types: bool, int"],
[83.2, 'print true*1.2', '', "err: MUL: invalid types: bool, float"],
[83.3, 'print true*true', '', "err: MUL: invalid types: bool, bool"],
[83.4, 'print true*"ab"', '', "err: MUL: invalid types: bool, string"],
[83.5, 'print true*nil', '', "err: MUL: invalid types: bool, nil"],
[84.1, 'print "ab"*2', 'abab'],
[84.2, 'print "ab"*1.2', '', "err: MUL: invalid types: string, float"],
[84.3, 'print "ab"*true', '', "err: MUL: invalid types: string, bool"],
[84.4, 'print "ab"*"cd"', '', "err: MUL: invalid types: string, string"],
[84.5, 'print "ab"*nil', '', "err: MUL: invalid types: string, nil"],
[85.1, 'print nil*1', '', "err: MUL: invalid types: nil, int"],
[85.2, 'print nil*1.2', '', "err: MUL: invalid types: nil, float"],
[85.3, 'print nil*true', '', "err: MUL: invalid types: nil, bool"],
[85.4, 'print nil*"ab"', '', "err: MUL: invalid types: nil, string"],
[85.5, 'print nil*nil', '', "err: MUL: invalid types: nil, nil"],

[86.1, 'print 1/2', '0'],
[86.2, 'print 1/2.0', '0.5'],
[86.3, 'print 1/true', '', "err: DIV: invalid types: int, bool"],
[86.4, 'print 1/"ab"', '', "err: DIV: invalid types: int, string"],
[86.5, 'print 1/nil', '', "err: DIV: invalid types: int, nil"],
[87.1, 'print 1.0/2', '0.5'],
[87.2, 'print 1.0/2.0', '0.5'],
[87.3, 'print 1.2/true', '', "err: DIV: invalid types: float, bool"],
[87.4, 'print 1.2/"ab"', '', "err: DIV: invalid types: float, string"],
[87.5, 'print 1.2/nil', '', "err: DIV: invalid types: float, nil"],
[88.1, 'print true/1', '', "err: DIV: invalid types: bool, int"],
[88.2, 'print true/1.2', '', "err: DIV: invalid types: bool, float"],
[88.3, 'print true/true', '', "err: DIV: invalid types: bool, bool"],
[88.4, 'print true/"ab"', '', "err: DIV: invalid types: bool, string"],
[88.5, 'print true/nil', '', "err: DIV: invalid types: bool, nil"],
[89.1, 'print "ab"/2', '', "err: DIV: invalid types: string, int"],
[89.2, 'print "ab"/1.2', '', "err: DIV: invalid types: string, float"],
[89.3, 'print "ab"/true', '', "err: DIV: invalid types: string, bool"],
[89.4, 'print "ab"/"cd"', '', "err: DIV: invalid types: string, string"],
[89.5, 'print "ab"/nil', '', "err: DIV: invalid types: string, nil"],
[90.1, 'print nil/1', '', "err: DIV: invalid types: nil, int"],
[90.2, 'print nil/1.2', '', "err: DIV: invalid types: nil, float"],
[90.3, 'print nil/true', '', "err: DIV: invalid types: nil, bool"],
[90.4, 'print nil/"ab"', '', "err: DIV: invalid types: nil, string"],
[90.5, 'print nil/nil', '', "err: DIV: invalid types: nil, nil"],

[91.1, 'print 1==1', 'true'],
[91.2, 'print 1==1.0', 'true'],
[91.3, 'print 1==true', 'false'],
[91.4, 'print 1=="ab"', 'false'],
[91.5, 'print 1==nil', 'false'],
[92.1, 'print 1.0==1', 'true'],
[92.2, 'print 1.0==1.0', 'true'],
[92.3, 'print 1.2==true', 'false'],
[92.4, 'print 1.2=="ab"', 'false'],
[92.5, 'print 1.2==nil', 'false'],
[93.1, 'print true==1', 'false'],
[93.2, 'print true==1.2', 'false'],
[93.3, 'print true==true', 'true'],
[93.4, 'print true=="ab"', 'false'],
[93.5, 'print true==nil', 'false'],
[94.1, 'print "ab"==2', 'false'],
[94.2, 'print "ab"==1.2', 'false'],
[94.3, 'print "ab"==true', 'false'],
[94.4, 'print "ab"=="cd"', 'false'],
[94.5, 'print "ab"==nil', 'false'],
[95.1, 'print nil==1', 'false'],
[95.2, 'print nil==1.2', 'false'],
[95.3, 'print nil==true', 'false'],
[95.4, 'print nil=="ab"', 'false'],
[95.5, 'print nil==nil', 'true'],

[96.1, 'print 1<2', 'true'],
[96.2, 'print 1<2.0', 'true'],
[96.3, 'print 1<true', '', "err: LT: invalid types: int, bool"],
[96.4, 'print 1<"ab"', '', "err: LT: invalid types: int, string"],
[96.5, 'print 1<nil', '', "err: LT: invalid types: int, nil"],
[97.1, 'print 1.0<2', 'true'],
[97.2, 'print 1.0<2.0', 'true'],
[97.3, 'print 1.2<true', '', "err: LT: invalid types: float, bool"],
[97.4, 'print 1.2<"ab"', '', "err: LT: invalid types: float, string"],
[97.5, 'print 1.2<nil', '', "err: LT: invalid types: float, nil"],
[98.1, 'print true<1', '', "err: LT: invalid types: bool, int"],
[98.2, 'print true<1.0', '', "err: LT: invalid types: bool, float"],
[98.3, 'print true<true', '', "err: LT: invalid types: bool, bool"],
[98.4, 'print true<"ab"', '', "err: LT: invalid types: bool, string"],
[98.5, 'print true<nil', '', "err: LT: invalid types: bool, nil"],
[99.1, 'print "ab"<2', '', "err: LT: invalid types: string, int"],
[99.2, 'print "ab"<1.2', '', "err: LT: invalid types: string, float"],
[99.3, 'print "ab"<true', '', "err: LT: invalid types: string, bool"],
[99.4, 'print "ab"<"cd"', 'true'],
[99.5, 'print "ab"<nil', '', "err: LT: invalid types: string, nil"],
[100.1, 'print nil<1', '', "err: LT: invalid types: nil, int"],
[100.2, 'print nil<1.2', '', "err: LT: invalid types: nil, float"],
[100.3, 'print nil<true', '', "err: LT: invalid types: nil, bool"],
[100.4, 'print nil<"ab"', '', "err: LT: invalid types: nil, string "],
[100.5, 'print nil<nil', '', "err: LT: invalid types: nil, nil"],

[101.1, 'print 1>2', 'false'],
[101.2, 'print 1>2.0', 'false'],
[101.3, 'print 1>true', '', "err: GT: invalid types: int, bool"],
[101.4, 'print 1>"ab"', '', "err: GT: invalid types: int, string"],
[101.5, 'print 1>nil', '', "err: GT: invalid types: int, nil"],
[102.1, 'print 1.0>2', 'false'],
[102.2, 'print 1.0>2.0', 'false'],
[102.3, 'print 1.2>true', '', "err: GT: invalid types: float, bool"],
[102.4, 'print 1.2>"ab"', '', "err: GT: invalid types: float, string"],
[102.5, 'print 1.2>nil', '', "err: GT: invalid types: float, nil"],
[103.1, 'print true>1', '', "err: GT: invalid types: bool, int"],
[103.2, 'print true>1.0', '', "err: GT: invalid types: bool, float"],
[103.3, 'print true>true', '', "err: GT: invalid types: bool, bool"],
[103.4, 'print true>"ab"', '', "err: GT: invalid types: bool, string"],
[103.5, 'print true>nil', '', "err: GT: invalid types: bool, nil"],
[104.1, 'print "ab">2', '', "err: GT: invalid types: string, int"],
[104.2, 'print "ab">1.2', '', "err: GT: invalid types: string, float"],
[104.3, 'print "ab">true', '', "err: GT: invalid types: string, bool"],
[104.4, 'print "ab">"cd"', 'false'],
[104.5, 'print "ab">nil', '', "err: GT: invalid types: string, nil"],
[105.1, 'print nil>1', '', "err: GT: invalid types: nil, int"],
[105.2, 'print nil>1.2', '', "err: GT: invalid types: nil, float"],
[105.3, 'print nil>true', '', "err: GT: invalid types: nil, bool"],
[105.4, 'print nil>"ab"', '', "err: GT: invalid types: nil, string "],
[105.5, 'print nil>nil', '', "err: GT: invalid types: nil, nil"],

[106.1, 'print not 0', 'false'],
[106.2, 'print not 0.0', 'false'],
[106.3, 'print not false', 'true'],
[106.4, 'print not ""', 'true'],
[106.5, 'print not nil', 'true'],

[107.1, 'print 1 or 2', '1'],
[107.2, 'print 1 or 2.0', '1'],
[107.3, 'print 1 or true', '1'],
[107.4, 'print 1 or "ab"', '1'],
[107.5, 'print 1 or nil', '1'],
[108.1, 'print 1.2 or 2', '1.2'],
[108.2, 'print 1.2 or 2.0', '1.2'],
[108.3, 'print 1.2 or true', '1.2'],
[108.4, 'print 1.2 or "ab"', '1.2'],
[108.5, 'print 1.2 or nil', '1.2' ],
[109.1, 'print true or 1', 'true'],
[109.2, 'print true or 1.0', 'true'],
[109.3, 'print true or true', 'true'],
[109.4, 'print true or "ab"', 'true'],
[109.5, 'print true or nil', 'true'],
[110.1, 'print "ab" or 2', 'ab'],
[110.2, 'print "ab" or 1.2', 'ab'],
[110.3, 'print "ab" or true', 'ab'],
[110.4, 'print "ab" or "cd"', 'ab'],
[110.5, 'print "ab" or nil', 'ab'],
[112.1, 'print nil or 1', '1'],
[112.2, 'print nil or 1.2', '1.2'],
[112.3, 'print nil or true', 'true'],
[112.4, 'print nil or "ab"', 'ab'],
[112.5, 'print nil or nil', '<nil>'],

[113.1, 'print 1 and 2', '2'],
[113.2, 'print 1 and 2.5', '2.5'],
[113.3, 'print 1 and true', 'true'],
[113.4, 'print 1 and "ab"', 'ab'],
[113.5, 'print 1 and nil', '<nil>'],
[114.1, 'print 1.2 and 2', '2'],
[114.2, 'print 1.2 and 2.5', '2.5'],
[114.3, 'print 1.2 and true', 'true'],
[114.4, 'print 1.2 and "ab"', 'ab'],
[114.5, 'print 1.2 and nil', '<nil>'],
[115.1, 'print true and 2', '2'],
[115.2, 'print true and 2.5', '2.5'],
[115.3, 'print true and true', 'true'],
[115.4, 'print true and "ab"', 'ab'],
[115.5, 'print true and nil', '<nil>'],
[116.1, 'print "ab" and 2', '2'],
[116.2, 'print "ab" and 2.5', '2.5'],
[116.3, 'print "ab" and true', 'true'],
[116.4, 'print "ab" and "cd"', 'cd'],
[116.5, 'print "ab" and nil', '<nil>'],
[117.1, 'print nil and 2', '<nil>'],
[117.2, 'print nil and 2.5', '<nil>'],
[117.3, 'print nil and true', '<nil>'],
[117.4, 'print nil and "ab"', '<nil>'],
[117.5, 'print nil and nil', '<nil>'],

[120, 'def b{x}', '', "err: 'x' not resolved as var or field"],
[121.1, 'print 1/0', '', "err: division by int zero"],
[121.2, 'print 1/0.0', '+Inf'],
]


Expand Down
Loading

0 comments on commit 1e9b01e

Please sign in to comment.