Skip to content

Commit 5c8be0f

Browse files
committed
Add some tests for macros
1 parent 00ae950 commit 5c8be0f

File tree

1 file changed

+57
-1
lines changed

1 file changed

+57
-1
lines changed

tests/macros.rs

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,66 @@ mod common;
22
use common::assert_eval_eq;
33

44
#[test]
5-
fn cond_hygiene() {
5+
fn hygiene() {
66
assert_eval_eq!(
77
"(let ((=> #f))
88
(cond (#t => 'ok)))",
99
"'ok"
1010
);
11+
12+
assert_eval_eq!(
13+
"(define-syntax my-or
14+
(syntax-rules ()
15+
((my-or) #f)
16+
((my-or e) e)
17+
((my-or e1 e2 ...)
18+
(let ((temp e1))
19+
(if temp temp
20+
(my-or e2 ...))))))
21+
(let ((x #f)
22+
(y 7)
23+
(temp 8)
24+
(let odd?)
25+
(if even?))
26+
(my-or x
27+
(let temp)
28+
(if y)
29+
y))",
30+
"7"
31+
);
32+
}
33+
34+
#[test]
35+
fn ellipses() {
36+
assert_eval_eq!(
37+
"(define-syntax foo
38+
(syntax-rules ()
39+
((foo a ...) '(a ...))))
40+
(foo x y z)",
41+
"'(x y z)"
42+
);
43+
44+
assert_eval_eq!(
45+
"(define-syntax foo
46+
(syntax-rules ()
47+
((foo (x ...) (y ...)) '((x y) ...))))
48+
(foo (q w e r) (a s d f))",
49+
"'((q a) (w s) (e d) (r f))"
50+
);
51+
52+
assert_eval_eq!(
53+
"(define-syntax foo
54+
(syntax-rules ()
55+
((foo ((x ...) ...) (y ...)) '((x ... y) ...))))
56+
(foo ((q 0 (q 1)) (w 2 (w 3)) (e (4 e) 5) (r 6 (r 7)) ((t 8) t 9)) (a s d f g))",
57+
"'((q 0 (q 1) a) (w 2 (w 3) s) (e (4 e) 5 d) (r 6 (r 7) f) ((t 8) t 9 g))"
58+
);
59+
60+
assert_eval_eq!(
61+
"(define-syntax foo
62+
(syntax-rules ()
63+
((foo ((a ...) ...) (b ...) c) '(((a ...) b c) ...))))
64+
(foo ((1 a b c) (2 b) (3 c)) (4 5 6) x)",
65+
"'(((1 a b c) 4 x) ((2 b) 5 x) ((3 c) 6 x))"
66+
);
1167
}

0 commit comments

Comments
 (0)