]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass-fulldeps/quote-tokens.rs
Rolling up PRs in the queue
[rust.git] / src / test / run-pass-fulldeps / quote-tokens.rs
1 // Copyright 2012-2014 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-android
12 // ignore-pretty: does not work well with `--test`
13
14 #![feature(quote)]
15 #![feature(managed_boxes)]
16
17 extern crate syntax;
18
19 use syntax::ext::base::ExtCtxt;
20
21 fn syntax_extension(cx: &ExtCtxt) {
22     let e_toks : Vec<syntax::ast::TokenTree> = quote_tokens!(cx, 1 + 2);
23     let p_toks : Vec<syntax::ast::TokenTree> = quote_tokens!(cx, (x, 1 .. 4, *));
24
25     let a: @syntax::ast::Expr = quote_expr!(cx, 1 + 2);
26     let _b: Option<@syntax::ast::Item> = quote_item!(cx, static foo : int = $e_toks; );
27     let _c: @syntax::ast::Pat = quote_pat!(cx, (x, 1 .. 4, *) );
28     let _d: @syntax::ast::Stmt = quote_stmt!(cx, let x = $a; );
29     let _e: @syntax::ast::Expr = quote_expr!(cx, match foo { $p_toks => 10 } );
30
31     let _f: @syntax::ast::Expr = quote_expr!(cx, ());
32     let _g: @syntax::ast::Expr = quote_expr!(cx, true);
33     let _h: @syntax::ast::Expr = quote_expr!(cx, 'a');
34
35     let i: Option<@syntax::ast::Item> = quote_item!(cx, #[deriving(Eq)] struct Foo; );
36     assert!(i.is_some());
37 }
38
39 fn main() {
40 }