Skip to content

Commit fa07a84

Browse files
jabittegernedbr
andauthored
test: add some testcases (#39)
Co-authored-by: dbr <db@mausbrand.de>
1 parent 3e868d8 commit fa07a84

File tree

14 files changed

+882
-60
lines changed

14 files changed

+882
-60
lines changed

logics-py/logics/logics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def __init__(self, src: str, debug: bool = False):
5252
"round": lambda value, digits=0: round(float(value), int(digits)),
5353
"rstrip": lambda value, chars=" \t\r\n": str(value).rstrip(str(chars)),
5454
"split": lambda value, delimiter=" ": str(value).split(str(delimiter)),
55-
"str": str,
55+
"str": lambda val: Value(str(val), optimize=False),
5656
"strip": lambda s, c=" \t\r\n": str(s).strip(str(c)),
5757
"sum": lambda value: sum([Value.align(item, allow=(bool, int, float), default=0) for item in value]),
5858
"upper": lambda value: str(value).upper(),

tests/advanced_elem.lgx

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
1 if True else 0
2+
#expect:1
3+
4+
1 if False else 0
5+
#expect:0
6+
7+
"a" if True else "b"
8+
#expect:"a"
9+
10+
"a" if False else "b"
11+
#expect:"b"
12+
13+
##################################
14+
15+
[x for x in range(5)]
16+
#expect:[0, 1, 2, 3, 4]
17+
18+
[x for x in range(5) if x % 2 == 0]
19+
#expect:[0, 2, 4]
20+
21+
[x*2 for x in range(3)]
22+
#expect:[0, 2, 4]
23+
24+
[x for x in [1, 2, 3] if x > 1]
25+
#expect:[2, 3]
26+
27+
#bug: AssertionError
28+
#[x for x in "abc"]
29+
##expect:["a", "b", "c"]
30+
31+
#bug: LogicsParseException
32+
#[x.upper() for x in "abc"]
33+
##expect:["A", "B", "C"]
34+
35+
##################################
36+
37+
#bug: AssertionError: assert '2' == '[1, 2]'
38+
#[1, 2, 3, 4][:2]
39+
##expect:[1, 2]
40+
41+
#bug: AssertionError: assert '3' == '[2, 3]'
42+
#[1, 2, 3, 4][1:3]
43+
##expect:[2, 3]
44+
45+
#bug: AssertionError
46+
#"abcdef"[:3]
47+
##expect:"abc"
48+
49+
#bug: AssertionError
50+
#'abcdef'[2:]
51+
##expect:'cdef'
52+
53+
#bug: AssertionError
54+
#'abcdef'[::2]
55+
##expect:'ace'
56+
57+
#bug: AssertionError
58+
#[1, 2, 3, 4][::-1]
59+
##expect:[4, 3, 2, 1]
60+
61+
##################################
62+
63+
[1, 2, 3][1]
64+
#expect:2
65+
66+
"abc"[1]
67+
#expect:"b"
68+
69+
(1, 2, 3)[2]
70+
#expect:3
71+
72+
#bug: logics.parser.LogicsParseException: Line 1, column 1: Parse error, expecting 'Identifier', 'Number', 'String', 'not', '+', '-', '~', '(', '[', 'True', 'False', 'None', '$'
73+
#{"a": 1, "b": 2}["b"]
74+
##expect:2
75+
76+
#bug: logics.parser.LogicsParseException: Line 1, column 2: Parse error, expecting 'Identifier', 'Number', 'String', 'not', '+', '-', '~', '(', '[', 'True', 'False', 'None', '$'
77+
#[{"a": 1}, {"b": 2}][1]["b"]
78+
##expect:2
79+
80+
#bug: logics.parser.LogicsParseException
81+
#{'key': 'value'}['key']
82+
##expect:'value'
83+
84+
##################################
85+
86+
#bug: AssertionError: assert '2' == '[1, 2]'
87+
#[1, 2, 3, 4][:2]
88+
##expect:[1, 2]
89+
90+
#bug: AssertionError...
91+
#[1, 2, 3, 4][1:3]
92+
##expect:[2, 3]
93+
94+
#bug: AssertionError...
95+
#'abcdef'[:3]
96+
##expect:'abc'
97+
98+
#bug: AssertionError...
99+
#'abcdef'[2:]
100+
##expect:'cdef'
101+
102+
#bug: AssertionError...
103+
#'abcdef'[::2]
104+
##expect:'ace'
105+
106+
#bug: AssertionError...
107+
#[1, 2, 3, 4][::-1]
108+
##expect:[4, 3, 2, 1]

tests/arithmetic_op.lgx

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
5 + 3
2+
#expect:8
3+
4+
"a" + "b"
5+
#expect:"ab"
6+
7+
1 + "b"
8+
#expect:"1b"
9+
10+
1 + 2 + 3 + 4
11+
#expect:10
12+
13+
5 + 0
14+
#expect:5
15+
16+
0 + 0
17+
#expect:0
18+
19+
##################################
20+
21+
5 - 3
22+
#expect:2
23+
24+
5 - 0
25+
#expect:5
26+
27+
0 - 5
28+
#expect:-5
29+
30+
-5 - 5
31+
#expect:-10
32+
33+
0 - 0
34+
#expect:0
35+
36+
"ab" - "b"
37+
#expect:0
38+
39+
##################################
40+
41+
5 * 3
42+
#expect:15
43+
44+
5 * 0
45+
#expect:0
46+
47+
0 * 0
48+
#expect:0
49+
50+
3 * "HelloWorld"
51+
#EXPECT:"HelloWorldHelloWorldHelloWorld"
52+
53+
#bug: TypeError: int() argument must be a string, a bytes-like object or a real number, not 'list'
54+
#[1, 2] * 2
55+
##expect:[1, 2, 1, 2]
56+
57+
##################################
58+
59+
6 / 3
60+
#expect:2
61+
62+
5 / 2
63+
#expect:2.5
64+
65+
5 / 1
66+
#expect:5
67+
68+
0 / 5
69+
#expect:0
70+
71+
5 / 0
72+
#expect:"#ERR:division by zero"
73+
74+
##################################
75+
76+
6 // 3
77+
#expect:2
78+
79+
5 // 2
80+
#expect:2
81+
82+
5 // 1
83+
#expect:5
84+
85+
0 // 5
86+
#expect:0
87+
88+
5 // 0
89+
#expect:"#ERR:division by zero"
90+
91+
##################################
92+
93+
5 % 3
94+
#expect:2
95+
96+
5 % 2
97+
#expect:1
98+
99+
5 % 1
100+
#expect:0
101+
102+
0 % 5
103+
#expect:0
104+
105+
5 % 0
106+
#expect:"#ERR:modulo by zero"
107+
108+
##################################
109+
110+
2 ** 3
111+
#expect:8
112+
113+
5 ** 2
114+
#expect:25
115+
116+
5 ** 1
117+
#expect:5
118+
119+
5 ** 0
120+
#expect:1
121+
122+
0 ** 5
123+
#expect:0

tests/data_types.lgx

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
int("5")
2+
#expect:5
3+
4+
int(5.5)
5+
#expect:5
6+
7+
int("0")
8+
#expect:0
9+
10+
int(False)
11+
#expect:0
12+
13+
#bug: AssertionError
14+
#int("10", 2)
15+
##expect:2
16+
17+
#bug: AssertionError
18+
#int(True)
19+
##expect:1
20+
21+
#set:numbers:(1,2,3, 53.2)
22+
23+
3 in numbers
24+
#expect:True
25+
26+
4 in numbers
27+
#expect:False
28+
29+
4 not in numbers
30+
#expect:True
31+
32+
"a" in numbers
33+
#expect:False
34+
35+
##################################
36+
37+
float("5.5")
38+
#expect:5.5
39+
40+
#bug: AssertionError
41+
#float(5)
42+
##expect:5.0
43+
44+
#bug: AssertionError
45+
#float("0")
46+
##expect:0.0
47+
48+
#bug: AssertionError
49+
#float(True)
50+
##expect:1.0
51+
52+
#bug: AssertionError
53+
#float(False)
54+
##expect:0.0
55+
56+
#bug: AssertionError
57+
#float("nan")
58+
##expect:float("nan")
59+
60+
##################################
61+
62+
str(True)
63+
#expect:"True"
64+
65+
str(False)
66+
#expect:"False"
67+
68+
str(None)
69+
#expect:"None"
70+
71+
str([1, 2, 3])
72+
#expect:"[1, 2, 3]"
73+
74+
#bug: AssertionError
75+
#str(5)
76+
##expect:5
77+
78+
str(5)
79+
#expect:"5"
80+
81+
str(5.5)
82+
#expect:"5.5"
83+
84+
#set:strings:("a","b","c")
85+
86+
"a" in strings
87+
#expect:True
88+
89+
"aa" in strings
90+
#expect:False
91+
92+
"x" not in strings
93+
#expect:True
94+
95+
#set:string:"Hello World"
96+
97+
"World" in string
98+
#expect:True
99+
100+
"Earth" in string
101+
#expect:False
102+
103+
"Earth" not in string
104+
#expect:True

tests/expressions.lgx

Lines changed: 0 additions & 8 deletions
This file was deleted.

tests/function_calls.lgx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
foo()
2-
#EXPECT:"#ERR:Call to unknown function foo()"
2+
#expect:"#ERR:Call to unknown function foo()"
33

44
upper()
5-
#EXPECT:"#ERR:Invalid call to upper()"
5+
#expect:"#ERR:Invalid call to upper()"

tests/if.lgx

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/if_else_con.lgx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"yes" if 2 + 3 == 5 else "no"
2+
#expect:"yes"
3+
4+
"yes" if False else "no"
5+
#expect:"no"
6+
7+
1 if True else 0
8+
#expect:1
9+
10+
1 if False else 0
11+
#expect:0
12+
13+
1 if 1 else 0
14+
#expect:1
15+
16+
1 if 0 else 0
17+
#expect:0
18+
19+
1 if None else 0
20+
#expect:0
21+
22+
1 if not None else 0
23+
#expect:1
24+
25+
##################################

0 commit comments

Comments
 (0)