]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass-fulldeps/issue-35829.rs
f17a0494a69c48d9e4d8b6acf39cc3df6086962f
[rustc.git] / src / test / run-pass-fulldeps / issue-35829.rs
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.
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-stage1
12 // ignore-cross-compile
13 #![feature(quote, rustc_private)]
14
15 extern crate syntax;
16
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;
24 use syntax::ptr::P;
25
26 use std::rc::Rc;
27
28 fn main() {
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);
33
34 // check byte string
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))));
38
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))));
43
44 // check dotdoteq
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)),
49 RangeLimits::Closed
50 ));
51
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")"#);
55 }