Skip to content

Commit e5afca4

Browse files
committed
Unrot and re-enable run-pass-fulldeps/qquote.rs
1 parent 90cc830 commit e5afca4

File tree

1 file changed

+40
-57
lines changed

1 file changed

+40
-57
lines changed

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

Lines changed: 40 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -9,86 +9,69 @@
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;
19+
use syntax::parse::token;
2420
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;
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;
3329
}
3430

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 {
31+
impl FakeExtCtxt for parse::ParseSess {
32+
fn call_site(&self) -> codemap::Span {
33+
codemap::Span {
4234
lo: codemap::BytePos(0),
4335
hi: codemap::BytePos(0),
44-
expn_id: codemap::NO_EXPANSION
36+
expn_id: codemap::NO_EXPANSION,
4537
}
4638
}
47-
fn ident_of(st: &str) -> ast::ident {
48-
self.interner.intern(st)
39+
fn cfg(&self) -> ast::CrateConfig { Vec::new() }
40+
fn ident_of(&self, st: &str) -> ast::Ident {
41+
token::str_to_ident(st)
4942
}
50-
}
51-
52-
fn mk_ctxt() -> fake_ext_ctxt {
53-
parse::new_parse_sess(None) as fake_ext_ctxt
43+
fn name_of(&self, st: &str) -> ast::Name {
44+
token::intern(st)
45+
}
46+
fn parse_sess(&self) -> &parse::ParseSess { self }
5447
}
5548

5649
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());
50+
let cx = parse::new_parse_sess();
6151

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

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());
56+
quote_pat!(&cx, Some(_)).and_then(|pat| {
57+
assert_eq!(pprust::pat_to_string(&pat), "Some(_)")
58+
});
6859

69-
let stmt = quote_stmt!(cx, let x = 20;);
70-
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),");
7162

72-
let pat = quote_pat!(cx, Some(_));
73-
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+
});
7466

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());
67+
quote_stmt!(&cx, let x = 20;).unwrap().and_then(|stmt| {
68+
assert_eq!(pprust::stmt_to_string(&stmt), "let x = 20;")
69+
});
7770

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

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);
74+
quote_item!(&cx, static x : isize = 10;).unwrap().and_then(|item| {
75+
assert_eq!(pprust::item_to_string(&item), "static x: isize = 10;")
8876
});
89-
stdout().write_line(s);
90-
if expect != "".to_string() {
91-
println!("expect: '%s', got: '%s'", expect, s);
92-
assert_eq!(s, expect);
93-
}
9477
}

0 commit comments

Comments
 (0)