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::{ExprKind, LitKind, RangeLimits};
26 use rustc_data_structures::sync::Lrc;
29 syntax::with_globals(|| run());
33 let parse_sess = ParseSess::new(FilePathMapping::empty());
34 let exp_cfg = ExpansionConfig::default("issue_35829".to_owned());
35 let mut resolver = DummyResolver;
36 let cx = ExtCtxt::new(&parse_sess, exp_cfg, &mut resolver);
39 let byte_string = quote_expr!(&cx, b"one");
40 let byte_string_lit_kind = LitKind::ByteStr(Lrc::new(b"one".to_vec()));
41 assert_eq!(byte_string.node, ExprKind::Lit(P(dummy_spanned(byte_string_lit_kind))));
43 // check raw byte string
44 let raw_byte_string = quote_expr!(&cx, br###"#"two"#"###);
45 let raw_byte_string_lit_kind = LitKind::ByteStr(Lrc::new(b"#\"two\"#".to_vec()));
46 assert_eq!(raw_byte_string.node, ExprKind::Lit(P(dummy_spanned(raw_byte_string_lit_kind))));
49 let closed_range = quote_expr!(&cx, 0 ..= 1);
50 assert_eq!(closed_range.node, ExprKind::Range(
51 Some(quote_expr!(&cx, 0)),
52 Some(quote_expr!(&cx, 1)),
56 // test case from 35829
57 let expr_35829 = quote_expr!(&cx, std::io::stdout().write(b"one"));
58 assert_eq!(expr_to_string(&expr_35829), r#"std::io::stdout().write(b"one")"#);