Skip to content

Commit 619b11d

Browse files
committed
WAT preprocessor: add tests
1 parent 63063ad commit 619b11d

File tree

4 files changed

+292
-0
lines changed

4 files changed

+292
-0
lines changed
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
Too many parentheses
2+
3+
$ echo '())' | wasmoo_util pp
4+
File "-", line 1, characters 2-3:
5+
Unexpected closing parenthesis.
6+
[1]
7+
8+
$ echo '();)' | wasmoo_util pp
9+
File "-", line 1, characters 2-4:
10+
Unmatched closing comment.
11+
[1]
12+
13+
Missing parenthesis
14+
15+
$ echo '(()' | wasmoo_util pp
16+
File "-", line 1, characters 0-1:
17+
Unclosed parenthesis.
18+
[1]
19+
20+
$ echo '(; ()' | wasmoo_util pp
21+
File "-", line 1, characters 0-2:
22+
Unclosed comment.
23+
[1]
24+
25+
$ echo '(; (; ()' | wasmoo_util pp
26+
File "-", line 1, characters 3-5:
27+
Unclosed comment.
28+
[1]
29+
30+
Unterminated string (we point at the newline)
31+
32+
$ echo '"abcd' | wasmoo_util pp
33+
File "-", line 1, characters 5-5:
34+
Malformed string.
35+
[1]
36+
37+
Bad conditional
38+
39+
$ echo '(@if)' | wasmoo_util pp
40+
File "-", line 1, characters 4-5:
41+
Expecting condition.
42+
[1]
43+
44+
$ echo '(@if a)' | wasmoo_util pp
45+
File "-", line 1, characters 6-7:
46+
Expecting @then clause.
47+
[1]
48+
49+
$ echo '(@if a xxx)' | wasmoo_util pp
50+
File "-", line 1, characters 7-10:
51+
Expecting @then clause.
52+
[1]
53+
54+
$ echo '(@if a (@then) xx)' | wasmoo_util pp
55+
File "-", line 1, characters 15-17:
56+
Expecting @else clause or closing parenthesis.
57+
[1]
58+
59+
$ echo '(@if a (@then) (@else) xx)' | wasmoo_util pp
60+
File "-", line 1, characters 23-25:
61+
Expecting closing parenthesis.
62+
[1]
63+
64+
Syntax error in condition
65+
66+
$ echo '(@if () (@then))' | wasmoo_util pp
67+
File "-", line 1, characters 5-7:
68+
Syntax error.
69+
[1]
70+
71+
$ echo '(@if (not) (@then))' | wasmoo_util pp
72+
File "-", line 1, characters 5-10:
73+
Syntax error.
74+
[1]
75+
76+
$ echo '(@if (not (and) (or)) (@then))' | wasmoo_util pp
77+
File "-", line 1, characters 5-21:
78+
Syntax error.
79+
[1]
80+
81+
$ echo '(@if (= "a") (@then))' | wasmoo_util pp
82+
File "-", line 1, characters 5-12:
83+
Syntax error.
84+
[1]
85+
86+
$ echo '(@if (= "a" "b" "c") (@then))' | wasmoo_util pp
87+
File "-", line 1, characters 5-20:
88+
Syntax error.
89+
[1]
90+
91+
Unicode escape sequences are not supported
92+
93+
$ echo '(@if (= "\u{1F600}" "b") (@then))' | wasmoo_util pp
94+
File "-", line 1, characters 8-19:
95+
Unicode escape sequences are not supported.
96+
[1]
97+
98+
Lonely @then or @else
99+
100+
$ echo '(@then)' | wasmoo_util pp
101+
File "-", line 1, characters 1-6:
102+
Unexpected @then clause. Maybe you forgot a parenthesis.
103+
[1]
104+
105+
$ echo '(@else)' | wasmoo_util pp
106+
File "-", line 1, characters 1-6:
107+
Unexpected @else clause. Maybe you forgot a parenthesis.
108+
[1]
109+
110+
$ echo '(@if (and) (@then (@else)))' | wasmoo_util pp
111+
File "-", line 1, characters 19-24:
112+
Unexpected @else clause. Maybe you forgot a parenthesis.
113+
[1]
114+
115+
Undefined variable
116+
117+
$ echo '(@if a (@then))' | wasmoo_util pp
118+
File "-", line 1, characters 5-6:
119+
Unknown variable 'a'.
120+
[1]
121+
122+
Wrong type
123+
$ echo '(@if "" (@then))' | wasmoo_util pp
124+
File "-", line 1, characters 5-7:
125+
Expected a boolean but this is a string.
126+
[1]
127+
128+
$ echo '(@if (not "") (@then))' | wasmoo_util pp
129+
File "-", line 1, characters 10-12:
130+
Expected a boolean but this is a string.
131+
[1]
132+
133+
$ echo '(@if (and "") (@then))' | wasmoo_util pp
134+
File "-", line 1, characters 10-12:
135+
Expected a boolean but this is a string.
136+
[1]
137+
138+
$ echo '(@if (or "") (@then))' | wasmoo_util pp
139+
File "-", line 1, characters 9-11:
140+
Expected a boolean but this is a string.
141+
[1]
142+
143+
$ echo '(@if (= (and) "") (@then))' | wasmoo_util pp
144+
File "-", line 1, characters 14-16:
145+
Expected a boolean but this is a string.
146+
[1]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
(rule
2+
(with-stdout-to
3+
tests.output
4+
(run wasmoo_util pp --enable a --disable b --set c=1 %{dep:tests.txt})))
5+
6+
(rule
7+
(alias runtest)
8+
(action
9+
(diff tests.expected tests.output)))
10+
11+
(cram
12+
(deps %{bin:wasmoo_util}))
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
;; conditional
2+
a is true
3+
b is false
4+
a is true
5+
6+
7+
;; nested conditionals
8+
a is true and b is false
9+
10+
11+
;; not
12+
13+
b is false
14+
15+
;; and
16+
true
17+
a is true
18+
19+
20+
a is true and b is false
21+
22+
23+
24+
;; or
25+
26+
a is true
27+
28+
a or b is true
29+
a is true or b is false
30+
31+
a or b is false
32+
33+
;; strings
34+
newline
35+
quote
36+
37+
;; string comparisons
38+
c is 1
39+
40+
41+
c is not 2
42+
43+
;; version comparisons
44+
45+
(4 1 1) = (4 1 1)
46+
47+
(4 1 1) <> (4 1 0)
48+
49+
(4 1 1) <> (4 1 2)
50+
51+
(4 1 1) <= (4 1 1)
52+
(4 1 1) <= (4 1 2)
53+
(4 1 1) >= (4 1 0)
54+
(4 1 1) >= (4 1 1)
55+
56+
(4 1 1) > (4 1 0)
57+
58+
59+
60+
;; version comparisons: lexicographic order
61+
62+
63+
(4 1 1) < (4 1 2)
64+
65+
(4 1 1) < (4 2 0)
66+
(4 1 1) < (5 0 1)
67+
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
;; conditional
2+
(@if a (@then a is true) (@else a is false))
3+
(@if b (@then b is true) (@else b is false))
4+
(@if a (@then a is true))
5+
(@if b (@then b is true))
6+
7+
;; nested conditionals
8+
(@if a (@then (@if b (@then a and b are true) (@else a is true and b is false)))
9+
(@else (@if b (@then a is false and b is true) (@else a and b are false))))
10+
11+
;; not
12+
(@if (not a) (@then a is false))
13+
(@if (not b) (@then b is false))
14+
15+
;; and
16+
(@if (and) (@then true))
17+
(@if (and a) (@then a is true))
18+
(@if (and b) (@then b is true))
19+
(@if (and a b) (@then a and b are true))
20+
(@if (and a (not b)) (@then a is true and b is false))
21+
(@if (and (not a) b) (@then a is false and b is true))
22+
(@if (and (not a) (not b)) (@then a and b are false))
23+
24+
;; or
25+
(@if (or) (@then false))
26+
(@if (or a) (@then a is true))
27+
(@if (or b) (@then b is true))
28+
(@if (or a b) (@then a or b is true))
29+
(@if (or a (not b)) (@then a is true or b is false))
30+
(@if (or (not a) b) (@then a is false or b is true))
31+
(@if (or (not a) (not b)) (@then a or b is false))
32+
33+
;; strings
34+
(@if (= "\n" "\0a") (@then newline))
35+
(@if (= "\'" "'") (@then quote))
36+
37+
;; string comparisons
38+
(@if (= c "1") (@then c is 1))
39+
(@if (= c "2") (@then c is 2))
40+
(@if (<> c "1") (@then c is not 1))
41+
(@if (<> c "2") (@then c is not 2))
42+
43+
;; version comparisons
44+
(@if (= (4 1 1) (4 1 0)) (@then (4 1 1) = (4 1 0)))
45+
(@if (= (4 1 1) (4 1 1)) (@then (4 1 1) = (4 1 1)))
46+
(@if (= (4 1 1) (4 1 2)) (@then (4 1 1) = (4 1 2)))
47+
(@if (<> (4 1 1) (4 1 0)) (@then (4 1 1) <> (4 1 0)))
48+
(@if (<> (4 1 1) (4 1 1)) (@then (4 1 1) <> (4 1 1)))
49+
(@if (<> (4 1 1) (4 1 2)) (@then (4 1 1) <> (4 1 2)))
50+
(@if (<= (4 1 1) (4 1 0)) (@then (4 1 1) <= (4 1 0)))
51+
(@if (<= (4 1 1) (4 1 1)) (@then (4 1 1) <= (4 1 1)))
52+
(@if (<= (4 1 1) (4 1 2)) (@then (4 1 1) <= (4 1 2)))
53+
(@if (>= (4 1 1) (4 1 0)) (@then (4 1 1) >= (4 1 0)))
54+
(@if (>= (4 1 1) (4 1 1)) (@then (4 1 1) >= (4 1 1)))
55+
(@if (>= (4 1 1) (4 1 2)) (@then (4 1 1) >= (4 1 2)))
56+
(@if (> (4 1 1) (4 1 0)) (@then (4 1 1) > (4 1 0)))
57+
(@if (> (4 1 1) (4 1 1)) (@then (4 1 1) > (4 1 1)))
58+
(@if (> (4 1 1) (4 1 2)) (@then (4 1 1) > (4 1 2)))
59+
60+
;; version comparisons: lexicographic order
61+
(@if (< (4 1 1) (4 1 0)) (@then (4 1 1) < (4 1 0)))
62+
(@if (< (4 1 1) (4 1 1)) (@then (4 1 1) < (4 1 1)))
63+
(@if (< (4 1 1) (4 1 2)) (@then (4 1 1) < (4 1 2)))
64+
(@if (< (4 1 1) (4 0 2)) (@then (4 1 1) < (4 0 2)))
65+
(@if (< (4 1 1) (4 2 0)) (@then (4 1 1) < (4 2 0)))
66+
(@if (< (4 1 1) (5 0 1)) (@then (4 1 1) < (5 0 1)))
67+
(@if (< (4 1 1) (3 2 1)) (@then (4 1 1) < (3 2 1)))

0 commit comments

Comments
 (0)