Skip to content

Commit ec592a9

Browse files
committed
Unrot and re-enable run-pass-fulldeps/qquote.rs
1 parent 9d439b4 commit ec592a9

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
@@ -10,86 +10,68 @@
1010

1111
// ignore-cross-compile
1212
// ignore-pretty
13-
// ignore-test
1413

15-
#![feature(quote)]
14+
#![feature(quote, rustc_private)]
1615

1716
extern crate syntax;
1817

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

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

5749
fn main() {
58-
let cx = mk_ctxt();
59-
60-
let abc = quote_expr!(cx, 23);
61-
check_pp(ext_cx, abc, pprust::print_expr, "23".to_string());
50+
let cx = parse::new_parse_sess();
6251

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)