Skip to content

Commit f6a8ffc

Browse files
paulstansifergraydon
authored andcommitted
Test statement macros.
1 parent 15e03e1 commit f6a8ffc

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/test/run-pass/macro-stmt.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// xfail-pretty - token trees can't pretty print
2+
3+
macro_rules! myfn(
4+
( $f:ident, ( $( $x:ident ),* ), $body:block ) => (
5+
fn $f( $( $x : int),* ) -> int $body
6+
)
7+
)
8+
9+
myfn!(add, (a,b), { return a+b; } )
10+
11+
fn main() {
12+
13+
macro_rules! mylet(
14+
($x:ident, $val:expr) => (
15+
let $x = $val;
16+
)
17+
);
18+
19+
mylet!(y, 8*2);
20+
assert(y == 16);
21+
22+
myfn!(mult, (a,b), { a*b } );
23+
24+
assert (mult(2, add(4,4)) == 16);
25+
26+
macro_rules! actually_an_expr_macro (
27+
() => ( 16 )
28+
)
29+
30+
assert { actually_an_expr_macro!() } == 16;
31+
32+
}

0 commit comments

Comments
 (0)