]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass-fulldeps/issue-35829.rs
798c214bc471569468aaaeabba782560d838263a
[rust.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 extern crate rustc_data_structures;
17
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};
24 use syntax::ptr::P;
25
26 use rustc_data_structures::sync::Lrc;
27
28 fn main() {
29     syntax::with_globals(|| run());
30 }
31
32 fn 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);
37
38     // check byte string
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))));
42
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))));
47
48     // check dotdoteq
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)),
53         RangeLimits::Closed
54     ));
55
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")"#);
59 }