Skip to content

Commit 1c97f24

Browse files
committed
---
yaml --- r: 8047 b: refs/heads/snap-stage3 c: f7fab77 h: refs/heads/master i: 8045: 108f33e 8043: 2b98e5a 8039: 9ce9533 8031: 48e8077 v: v3
1 parent 53d8c4c commit 1c97f24

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 2898dcc5d97da9427ac367542382b6239d9c0bbf
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 6dcd12dc22eb891c726dbf5c1c4177d4e72874d8
4+
refs/heads/snap-stage3: f7fab77102057b55202992c7e73d62d7123f6356
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// xfail-pretty
2+
3+
use std;
4+
use rustc;
5+
6+
import rustc::*;
7+
import std::io::*;
8+
9+
import rustc::driver::diagnostic;
10+
import rustc::syntax::ast;
11+
import rustc::syntax::codemap;
12+
import rustc::syntax::parse::parser;
13+
import rustc::syntax::print::*;
14+
15+
fn new_parse_sess() -> parser::parse_sess {
16+
let cm = codemap::new_codemap();
17+
let handler = diagnostic::mk_handler(option::none);
18+
let sess = @{
19+
cm: cm,
20+
mutable next_id: 1,
21+
span_diagnostic: diagnostic::mk_span_handler(handler, cm),
22+
mutable chpos: 0u,
23+
mutable byte_pos: 0u
24+
};
25+
ret sess;
26+
}
27+
28+
iface fake_ext_ctxt {
29+
fn session() -> fake_session;
30+
}
31+
32+
type fake_options = {cfg: ast::crate_cfg};
33+
34+
type fake_session = {opts: @fake_options,
35+
parse_sess: parser::parse_sess};
36+
37+
impl of fake_ext_ctxt for fake_session {
38+
fn session() -> fake_session {self}
39+
}
40+
41+
fn mk_ctxt() -> fake_ext_ctxt {
42+
let opts : fake_options = {cfg: []};
43+
{opts: @opts, parse_sess: new_parse_sess()} as fake_ext_ctxt
44+
}
45+
46+
47+
fn main() {
48+
let ext_cx = mk_ctxt();
49+
50+
let abc = #ast{23};
51+
check_pp(abc, pprust::print_expr, "23");
52+
53+
let expr = #ast{1 - $0 + 8};
54+
check_pp(expr, pprust::print_expr, "1 - $0 + 8");
55+
56+
let expr2 = rustc::syntax::ext::qquote::replace(expr, [abc]);
57+
check_pp(expr2, pprust::print_expr, "1 - 23 + 8");
58+
59+
let expr3 = #ast{2 - $(abc) + 7};
60+
check_pp(expr3, pprust::print_expr, "2 - 23 + 7");
61+
62+
let expr4 = #ast{2 - $(#(3)) + 9};
63+
check_pp(expr4, pprust::print_expr, "2 - 3 + 9");
64+
65+
let ty = #ast(ty){option<int>};
66+
check_pp(ty, pprust::print_type, "option<int>");
67+
68+
let item = #ast(item){const x : int = 10;};
69+
check_pp(item, pprust::print_item, "const x: int = 10;");
70+
71+
let stmt = #ast(stmt){let x = 20;};
72+
check_pp(*stmt, pprust::print_stmt, "let x = 20;");
73+
74+
let pat = #ast(pat){some(_)};
75+
check_pp(pat, pprust::print_pat, "some(_)");
76+
}
77+
78+
fn check_pp<T>(expr: T, f: fn(pprust::ps, T), expect: str) {
79+
let buf = mk_mem_buffer();
80+
let pp = pprust::rust_printer(buf as std::io::writer);
81+
f(pp, expr);
82+
pp::eof(pp.s);
83+
let str = mem_buffer_str(buf);
84+
stdout().write_line(str);
85+
if expect != "" {assert str == expect;}
86+
}
87+

0 commit comments

Comments
 (0)