]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass-fulldeps/qquote.rs
Imported Upstream version 1.2.0+dfsg1
[rustc.git] / src / test / run-pass-fulldeps / qquote.rs
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.
4 //
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.
10
11 // ignore-cross-compile
12
13 #![feature(quote, rustc_private)]
14
15 extern crate syntax;
16
17 use syntax::codemap::DUMMY_SP;
18 use syntax::print::pprust::*;
19
20 fn main() {
21 let ps = syntax::parse::ParseSess::new();
22 let mut cx = syntax::ext::base::ExtCtxt::new(
23 &ps, vec![],
24 syntax::ext::expand::ExpansionConfig::default("qquote".to_string()));
25 cx.bt_push(syntax::codemap::ExpnInfo {
26 call_site: DUMMY_SP,
27 callee: syntax::codemap::NameAndSpan {
28 name: "".to_string(),
29 format: syntax::codemap::MacroBang,
30 allow_internal_unstable: false,
31 span: None,
32 }
33 });
34 let cx = &mut cx;
35
36 macro_rules! check {
37 ($f: ident, $($e: expr),+; $expect: expr) => ({
38 $(assert_eq!($f(&$e), $expect);)+
39 });
40 }
41
42 let abc = quote_expr!(cx, 23);
43 check!(expr_to_string, abc, *quote_expr!(cx, $abc); "23");
44
45 let ty = quote_ty!(cx, isize);
46 check!(ty_to_string, ty, *quote_ty!(cx, $ty); "isize");
47
48 let item = quote_item!(cx, static x: $ty = 10;).unwrap();
49 check!(item_to_string, item, quote_item!(cx, $item).unwrap(); "static x: isize = 10;");
50
51 let twenty: u16 = 20;
52 let stmt = quote_stmt!(cx, let x = $twenty;).unwrap();
53 check!(stmt_to_string, stmt, *quote_stmt!(cx, $stmt).unwrap(); "let x = 20u16;");
54
55 let pat = quote_pat!(cx, Some(_));
56 check!(pat_to_string, pat, *quote_pat!(cx, $pat); "Some(_)");
57
58 let expr = quote_expr!(cx, (x, y));
59 let arm = quote_arm!(cx, (ref x, ref y) => $expr,);
60 check!(arm_to_string, arm, quote_arm!(cx, $arm); " (ref x, ref y) => (x, y),");
61
62 let attr = quote_attr!(cx, #![cfg(foo = "bar")]);
63 check!(attribute_to_string, attr, quote_attr!(cx, $attr); r#"#![cfg(foo = "bar")]"#);
64 }