Test (but don't pretty-print) the new macro system.

This commit is contained in:
Paul Stansifer 2012-07-11 10:42:59 -07:00
parent c0abd6a2eb
commit 650009f80c
4 changed files with 37 additions and 2 deletions

View File

@ -1,9 +1,20 @@
// xfail-pretty - token trees can't pretty print
fn main() {
#macro[[#mylambda[x, body],
{
fn f(x: int) -> int { ret body }
fn f(x: int) -> int { ret body; }
f
}]];
assert (#mylambda[y, y * 2](8) == 16);
macro_rules! mylambda_tt{
{$x:ident, $body:expr} => {
fn f($x: int) -> int { ret $body; };
f
}
}
assert(mylambda_tt!{y, y * 2}(8) == 16)
}

View File

@ -1,5 +1,12 @@
// xfail-pretty - token trees can't pretty print
fn main() {
#macro[[#trivial[], 1 * 2 * 4 * 2 * 1]];
assert (#trivial[] == 16);
macro_rules! trivial_tt{
{} => {1*2*4*2*1}
}
assert(trivial_tt!{} == 16);
}

View File

@ -1,7 +1,14 @@
// xfail-pretty - token trees can't pretty print
fn main() {
#macro[[#apply[f, [x, ...]], f(x, ...)]];
macro_rules! apply_tt{
{$f:expr, ($($x:expr),*)} => {$f($($x),*)}
}
fn add(a: int, b: int) -> int { ret a + b; }
assert (#apply[add, [1, 15]] == 16);
assert(apply_tt!{add, (1, 15)} == 16);
}

View File

@ -1 +1,11 @@
fn main() { #macro[[#m1[a], a * 4]]; assert (#m1[2] == 8); }
// xfail-pretty - token trees can't pretty print
fn main() {
#macro[[#m1[a], a * 4]];
assert (#m1[2] == 8);
macro_rules! m1tt {
{$a:expr} => {$a*4}
};
assert(m1tt!{2} == 8);
}