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)]
17 use syntax
::ext
::base
::{ExtCtxt, DummyResolver}
;
18 use syntax
::ext
::expand
::ExpansionConfig
;
19 use syntax
::parse
::ParseSess
;
20 use syntax
::codemap
::{FilePathMapping, dummy_spanned}
;
21 use syntax
::print
::pprust
::expr_to_string
;
22 use syntax
::ast
::{Expr, ExprKind, LitKind, StrStyle, RangeLimits}
;
23 use syntax
::symbol
::Symbol
;
29 let parse_sess
= ParseSess
::new(FilePathMapping
::empty());
30 let exp_cfg
= ExpansionConfig
::default("issue_35829".to_owned());
31 let mut resolver
= DummyResolver
;
32 let cx
= ExtCtxt
::new(&parse_sess
, exp_cfg
, &mut resolver
);
35 let byte_string
= quote_expr
!(&cx
, b
"one");
36 let byte_string_lit_kind
= LitKind
::ByteStr(Rc
::new(b
"one".to_vec()));
37 assert_eq
!(byte_string
.node
, ExprKind
::Lit(P(dummy_spanned(byte_string_lit_kind
))));
39 // check raw byte string
40 let raw_byte_string
= quote_expr
!(&cx
, br
###"#"two"#"###);
41 let raw_byte_string_lit_kind
= LitKind
::ByteStr(Rc
::new(b
"#\"two\"#".to_vec()));
42 assert_eq
!(raw_byte_string
.node
, ExprKind
::Lit(P(dummy_spanned(raw_byte_string_lit_kind
))));
45 let closed_range
= quote_expr
!(&cx
, 0 ..= 1);
46 assert_eq
!(closed_range
.node
, ExprKind
::Range(
47 Some(quote_expr
!(&cx
, 0)),
48 Some(quote_expr
!(&cx
, 1)),
52 // test case from 35829
53 let expr_35829
= quote_expr
!(&cx
, std
::io
::stdout().write(b
"one"));
54 assert_eq
!(expr_to_string(&expr_35829
), r
#"std::io::stdout().write(b"one")"#);