Skip to content

Commit 1c32a34

Browse files
committed
Unrot and re-enable run-pass-fulldeps/qquote.rs
1 parent 6b29a7d commit 1c32a34

File tree

1 file changed

+39
-57
lines changed

1 file changed

+39
-57
lines changed

src/test/run-pass-fulldeps/qquote.rs

+39-57
Original file line numberDiff line numberDiff line change
@@ -9,86 +9,68 @@
99
// except according to those terms.
1010

1111
// ignore-pretty
12-
// ignore-test
1312

14-
#![feature(quote)]
13+
#![feature(quote, rustc_private)]
1514

1615
extern crate syntax;
1716

18-
use std::io::*;
19-
20-
use syntax::diagnostic;
2117
use syntax::ast;
2218
use syntax::codemap;
23-
use syntax::codemap::span;
2419
use syntax::parse;
25-
use syntax::print::*;
26-
27-
28-
trait fake_ext_ctxt {
29-
fn cfg() -> ast::CrateConfig;
30-
fn parse_sess() -> parse::parse_sess;
31-
fn call_site() -> span;
32-
fn ident_of(st: &str) -> ast::ident;
20+
use syntax::print::pprust;
21+
22+
trait FakeExtCtxt {
23+
fn call_site(&self) -> codemap::Span;
24+
fn cfg(&self) -> ast::CrateConfig;
25+
fn ident_of(&self, st: &str) -> ast::Ident;
26+
fn name_of(&self, st: &str) -> ast::Name;
27+
fn parse_sess(&self) -> &parse::ParseSess;
3328
}
3429

35-
type fake_session = parse::parse_sess;
36-
37-
impl fake_ext_ctxt for fake_session {
38-
fn cfg() -> ast::CrateConfig { Vec::new() }
39-
fn parse_sess() -> parse::parse_sess { self }
40-
fn call_site() -> span {
41-
codemap::span {
30+
impl FakeExtCtxt for parse::ParseSess {
31+
fn call_site(&self) -> codemap::Span {
32+
codemap::Span {
4233
lo: codemap::BytePos(0),
4334
hi: codemap::BytePos(0),
44-
expn_id: codemap::NO_EXPANSION
35+
expn_id: codemap::NO_EXPANSION,
4536
}
4637
}
47-
fn ident_of(st: &str) -> ast::ident {
48-
self.interner.intern(st)
38+
fn cfg(&self) -> ast::CrateConfig { Vec::new() }
39+
fn ident_of(&self, st: &str) -> ast::Ident {
40+
parse::token::str_to_ident(st)
4941
}
50-
}
51-
52-
fn mk_ctxt() -> fake_ext_ctxt {
53-
parse::new_parse_sess(None) as fake_ext_ctxt
42+
fn name_of(&self, st: &str) -> ast::Name {
43+
parse::token::intern(st)
44+
}
45+
fn parse_sess(&self) -> &parse::ParseSess { self }
5446
}
5547

5648
fn main() {
57-
let cx = mk_ctxt();
58-
59-
let abc = quote_expr!(cx, 23);
60-
check_pp(ext_cx, abc, pprust::print_expr, "23".to_string());
49+
let cx = parse::new_parse_sess();
6150

51+
quote_ty!(&cx, isize).and_then(|ty| {
52+
assert_eq!(pprust::ty_to_string(&ty), "isize")
53+
});
6254

63-
let ty = quote_ty!(cx, isize);
64-
check_pp(ext_cx, ty, pprust::print_type, "isize".to_string());
65-
66-
let item = quote_item!(cx, static x : isize = 10;).get();
67-
check_pp(ext_cx, item, pprust::print_item, "static x: isize = 10;".to_string());
55+
quote_pat!(&cx, Some(_)).and_then(|pat| {
56+
assert_eq!(pprust::pat_to_string(&pat), "Some(_)")
57+
});
6858

69-
let stmt = quote_stmt!(cx, let x = 20;);
70-
check_pp(ext_cx, *stmt, pprust::print_stmt, "let x = 20;".to_string());
59+
let arm = quote_arm!(&cx, (ref x, ref y) => (x, y),);
60+
assert_eq!(pprust::arm_to_string(&arm), " (ref x, ref y) => (x, y),");
7161

72-
let pat = quote_pat!(cx, Some(_));
73-
check_pp(ext_cx, pat, pprust::print_pat, "Some(_)".to_string());
62+
quote_expr!(&cx, 23).and_then(|expr| {
63+
assert_eq!(pprust::expr_to_string(&expr), "23")
64+
});
7465

75-
let arm = quote_arm!(cx, (ref x, ref y) => (x, y));
76-
check_pp(ext_cx, arm, pprust::print_stmt, "(ref x, ref y) = (x, y)".to_string());
66+
quote_stmt!(&cx, let x = 20;).unwrap().and_then(|stmt| {
67+
assert_eq!(pprust::stmt_to_string(&stmt), "let x = 20;")
68+
});
7769

78-
let attr = quote_attr!(cx, #![cfg(foo = "bar")]);
79-
check_pp(ext_cx, attr, pprust::print_attribute, "#![cfg(foo = "bar")]".to_string());
80-
}
70+
let attr = quote_attr!(&cx, #![cfg(foo = "bar")]);
71+
assert_eq!(pprust::attr_to_string(&attr), "#![cfg(foo = \"bar\")]");
8172

82-
fn check_pp<T>(cx: fake_ext_ctxt,
83-
expr: T, f: |pprust::ps, T|, expect: String) {
84-
let s = io::with_str_writer(|wr| {
85-
let pp = pprust::rust_printer(wr, cx.parse_sess().interner);
86-
f(pp, expr);
87-
pp::eof(pp.s);
73+
quote_item!(&cx, static x : isize = 10;).unwrap().and_then(|item| {
74+
assert_eq!(pprust::item_to_string(&item), "static x: isize = 10;")
8875
});
89-
stdout().write_line(s);
90-
if expect != "".to_string() {
91-
println!("expect: '%s', got: '%s'", expect, s);
92-
assert_eq!(s, expect);
93-
}
9476
}

0 commit comments

Comments
 (0)