1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 // ignore-cross-compile
13 #![feature(quote, rustc_private)]
17 use syntax::codemap::DUMMY_SP;
18 use syntax::print::pprust::*;
19 use syntax::parse::token::intern;
22 let ps = syntax::parse::ParseSess::new();
23 let mut feature_gated_cfgs = vec![];
24 let mut cx = syntax::ext::base::ExtCtxt::new(
26 syntax::ext::expand::ExpansionConfig::default("qquote".to_string()),
27 &mut feature_gated_cfgs);
28 cx.bt_push(syntax::codemap::ExpnInfo {
30 callee: syntax::codemap::NameAndSpan {
31 format: syntax::codemap::MacroBang(intern("")),
32 allow_internal_unstable: false,
39 ($f: ident, $($e: expr),+; $expect: expr) => ({
40 $(assert_eq!($f(&$e), $expect);)+
44 let abc = quote_expr!(cx, 23);
45 check!(expr_to_string, abc, *quote_expr!(cx, $abc); "23");
47 let ty = quote_ty!(cx, isize);
48 check!(ty_to_string, ty, *quote_ty!(cx, $ty); "isize");
50 let item = quote_item!(cx, static x: $ty = 10;).unwrap();
51 check!(item_to_string, item, quote_item!(cx, $item).unwrap(); "static x: isize = 10;");
54 let stmt = quote_stmt!(cx, let x = $twenty;).unwrap();
55 check!(stmt_to_string, stmt, *quote_stmt!(cx, $stmt).unwrap(); "let x = 20u16;");
57 let pat = quote_pat!(cx, Some(_));
58 check!(pat_to_string, pat, *quote_pat!(cx, $pat); "Some(_)");
60 let expr = quote_expr!(cx, (x, y));
61 let arm = quote_arm!(cx, (ref x, ref y) => $expr,);
62 check!(arm_to_string, arm, quote_arm!(cx, $arm); " (ref x, ref y) => (x, y),");
64 let attr = quote_attr!(cx, #![cfg(foo = "bar")]);
65 check!(attribute_to_string, attr, quote_attr!(cx, $attr); r#"#![cfg(foo = "bar")]"#);