Skip to content

Commit 85971df

Browse files
committed
WAT preprocessor: add tests
1 parent b40976e commit 85971df

File tree

4 files changed

+251
-0
lines changed

4 files changed

+251
-0
lines changed

compiler/bin-wasmoo_util/tests/cram.t

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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+
Missing parenthesis
9+
10+
$ echo '(()' | wasmoo_util pp
11+
File "-", line 2, characters 0-0:
12+
Unexpected end of file.
13+
[1]
14+
15+
Bad conditional
16+
17+
$ echo '(@if)' | wasmoo_util pp
18+
File "-", line 1, characters 4-5:
19+
Expecting condition.
20+
[1]
21+
22+
$ echo '(@if a)' | wasmoo_util pp
23+
File "-", line 1, characters 6-7:
24+
Expecting @then clause.
25+
[1]
26+
27+
$ echo '(@if a xxx)' | wasmoo_util pp
28+
File "-", line 1, characters 7-10:
29+
Expecting @then clause.
30+
[1]
31+
32+
$ echo '(@if a (@then) xx)' | wasmoo_util pp
33+
File "-", line 1, characters 15-17:
34+
Expecting @else clause or closing parenthesis.
35+
[1]
36+
37+
$ echo '(@if a (@then) (@else) xx)' | wasmoo_util pp
38+
File "-", line 1, characters 23-25:
39+
Expecting closing parenthesis.
40+
[1]
41+
42+
Syntax error in condition
43+
44+
$ echo '(@if () (@then))' | wasmoo_util pp
45+
File "-", line 1, characters 5-7:
46+
Syntax error.
47+
[1]
48+
49+
$ echo '(@if (not) (@then))' | wasmoo_util pp
50+
File "-", line 1, characters 5-10:
51+
Syntax error.
52+
[1]
53+
54+
$ echo '(@if (not (and) (or)) (@then))' | wasmoo_util pp
55+
File "-", line 1, characters 5-21:
56+
Syntax error.
57+
[1]
58+
59+
$ echo '(@if (= "a") (@then))' | wasmoo_util pp
60+
File "-", line 1, characters 5-12:
61+
Syntax error.
62+
[1]
63+
64+
$ echo '(@if (= "a" "b" "c") (@then))' | wasmoo_util pp
65+
File "-", line 1, characters 5-20:
66+
Syntax error.
67+
[1]
68+
69+
Lonely @then or @else
70+
71+
$ echo '(@then)' | wasmoo_util pp
72+
File "-", line 1, characters 5-20:
73+
Syntax error.
74+
[1]
75+
76+
$ echo '(@else)' | wasmoo_util pp
77+
File "-", line 1, characters 5-20:
78+
Syntax error.
79+
[1]
80+
81+
$ echo '(@if (and) (@then (@else)))' | wasmoo_util pp
82+
File "-", line 1, characters 5-20:
83+
Syntax error.
84+
[1]
85+
86+
Undefined variable
87+
88+
$ echo '(@if a (@then))' | wasmoo_util pp
89+
File "-", line 1, characters 5-6:
90+
Unknown variable 'a'.
91+
[1]
92+
93+
Wrong type
94+
$ echo '(@if "" (@then))' | wasmoo_util pp
95+
File "-", line 1, characters 5-7:
96+
Expected a boolean but this is a string.
97+
[1]
98+
99+
$ echo '(@if (not "") (@then))' | wasmoo_util pp
100+
File "-", line 1, characters 10-12:
101+
Expected a boolean but this is a string.
102+
[1]
103+
104+
$ echo '(@if (and "") (@then))' | wasmoo_util pp
105+
File "-", line 1, characters 10-12:
106+
Expected a boolean but this is a string.
107+
[1]
108+
109+
$ echo '(@if (or "") (@then))' | wasmoo_util pp
110+
File "-", line 1, characters 9-11:
111+
Expected a boolean but this is a string.
112+
[1]
113+
114+
$ echo '(@if (= (and) "") (@then))' | wasmoo_util pp
115+
File "-", line 1, characters 14-16:
116+
Expected a boolean but this is a string.
117+
[1]

compiler/bin-wasmoo_util/tests/dune

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
(rule
3+
(with-stdout-to 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 (diff tests.expected tests.output)))
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
;; string comparisons
34+
c is 1
35+
36+
37+
c is not 2
38+
39+
;; version comparisons
40+
41+
(4 1 1) = (4 1 1)
42+
43+
(4 1 1) <> (4 1 0)
44+
45+
(4 1 1) <> (4 1 2)
46+
47+
(4 1 1) <= (4 1 1)
48+
(4 1 1) <= (4 1 2)
49+
(4 1 1) >= (4 1 0)
50+
(4 1 1) >= (4 1 1)
51+
52+
(4 1 1) > (4 1 0)
53+
54+
55+
56+
;; version comparisons: lexicographic order
57+
58+
59+
(4 1 1) < (4 1 2)
60+
61+
(4 1 1) < (4 2 0)
62+
(4 1 1) < (5 0 1)
63+
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
;; string comparisons
34+
(@if (= c "1") (@then c is 1))
35+
(@if (= c "2") (@then c is 2))
36+
(@if (<> c "1") (@then c is not 1))
37+
(@if (<> c "2") (@then c is not 2))
38+
39+
;; version comparisons
40+
(@if (= (4 1 1) (4 1 0)) (@then (4 1 1) = (4 1 0)))
41+
(@if (= (4 1 1) (4 1 1)) (@then (4 1 1) = (4 1 1)))
42+
(@if (= (4 1 1) (4 1 2)) (@then (4 1 1) = (4 1 2)))
43+
(@if (<> (4 1 1) (4 1 0)) (@then (4 1 1) <> (4 1 0)))
44+
(@if (<> (4 1 1) (4 1 1)) (@then (4 1 1) <> (4 1 1)))
45+
(@if (<> (4 1 1) (4 1 2)) (@then (4 1 1) <> (4 1 2)))
46+
(@if (<= (4 1 1) (4 1 0)) (@then (4 1 1) <= (4 1 0)))
47+
(@if (<= (4 1 1) (4 1 1)) (@then (4 1 1) <= (4 1 1)))
48+
(@if (<= (4 1 1) (4 1 2)) (@then (4 1 1) <= (4 1 2)))
49+
(@if (>= (4 1 1) (4 1 0)) (@then (4 1 1) >= (4 1 0)))
50+
(@if (>= (4 1 1) (4 1 1)) (@then (4 1 1) >= (4 1 1)))
51+
(@if (>= (4 1 1) (4 1 2)) (@then (4 1 1) >= (4 1 2)))
52+
(@if (> (4 1 1) (4 1 0)) (@then (4 1 1) > (4 1 0)))
53+
(@if (> (4 1 1) (4 1 1)) (@then (4 1 1) > (4 1 1)))
54+
(@if (> (4 1 1) (4 1 2)) (@then (4 1 1) > (4 1 2)))
55+
56+
;; version comparisons: lexicographic order
57+
(@if (< (4 1 1) (4 1 0)) (@then (4 1 1) < (4 1 0)))
58+
(@if (< (4 1 1) (4 1 1)) (@then (4 1 1) < (4 1 1)))
59+
(@if (< (4 1 1) (4 1 2)) (@then (4 1 1) < (4 1 2)))
60+
(@if (< (4 1 1) (4 0 2)) (@then (4 1 1) < (4 0 2)))
61+
(@if (< (4 1 1) (4 2 0)) (@then (4 1 1) < (4 2 0)))
62+
(@if (< (4 1 1) (5 0 1)) (@then (4 1 1) < (5 0 1)))
63+
(@if (< (4 1 1) (3 2 1)) (@then (4 1 1) < (3 2 1)))

0 commit comments

Comments
 (0)