mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
Test (but don't pretty-print) the new macro system.
This commit is contained in:
parent
c0abd6a2eb
commit
650009f80c
@ -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)
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user