1 // Copyright 2017 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.
12 // ignore-cross-compile
13 #![feature(quote, rustc_private)]
16 extern crate rustc_data_structures;
18 use syntax::ext::base::{ExtCtxt, DummyResolver};
19 use syntax::ext::expand::ExpansionConfig;
20 use syntax::parse::ParseSess;
21 use syntax::codemap::{FilePathMapping, dummy_spanned};
22 use syntax::print::pprust::expr_to_string;
23 use syntax::ast::{Expr, ExprKind, LitKind, StrStyle, RangeLimits};
24 use syntax::symbol::Symbol;
27 use rustc_data_structures::sync::Lrc;
30 let parse_sess = ParseSess::new(FilePathMapping::empty());
31 let exp_cfg = ExpansionConfig::default("issue_35829".to_owned());
32 let mut resolver = DummyResolver;
33 let cx = ExtCtxt::new(&parse_sess, exp_cfg, &mut resolver);
36 let byte_string = quote_expr!(&cx, b"one");
37 let byte_string_lit_kind = LitKind::ByteStr(Lrc::new(b"one".to_vec()));
38 assert_eq!(byte_string.node, ExprKind::Lit(P(dummy_spanned(byte_string_lit_kind))));
40 // check raw byte string
41 let raw_byte_string = quote_expr!(&cx, br###"#"two"#"###);
42 let raw_byte_string_lit_kind = LitKind::ByteStr(Lrc::new(b"#\"two\"#".to_vec()));
43 assert_eq!(raw_byte_string.node, ExprKind::Lit(P(dummy_spanned(raw_byte_string_lit_kind))));
46 let closed_range = quote_expr!(&cx, 0 ..= 1);
47 assert_eq!(closed_range.node, ExprKind::Range(
48 Some(quote_expr!(&cx, 0)),
49 Some(quote_expr!(&cx, 1)),
53 // test case from 35829
54 let expr_35829 = quote_expr!(&cx, std::io::stdout().write(b"one"));
55 assert_eq!(expr_to_string(&expr_35829), r#"std::io::stdout().write(b"one")"#);