2012-02-01 13:41:01 -07:00
|
|
|
// xfail-pretty
|
|
|
|
|
2012-09-18 15:52:21 -07:00
|
|
|
#[legacy_modes];
|
|
|
|
|
2012-09-11 17:46:20 -07:00
|
|
|
extern mod std;
|
|
|
|
extern mod syntax;
|
2012-02-01 13:41:01 -07:00
|
|
|
|
2012-09-05 12:32:05 -07:00
|
|
|
use io::*;
|
2012-02-01 13:41:01 -07:00
|
|
|
|
2012-09-05 12:32:05 -07:00
|
|
|
use syntax::diagnostic;
|
|
|
|
use syntax::ast;
|
|
|
|
use syntax::codemap;
|
|
|
|
use syntax::parse;
|
|
|
|
use syntax::print::*;
|
2012-02-01 13:41:01 -07:00
|
|
|
|
2012-07-31 10:27:51 -07:00
|
|
|
trait fake_ext_ctxt {
|
2012-03-22 18:53:30 -07:00
|
|
|
fn cfg() -> ast::crate_cfg;
|
2012-04-17 23:34:48 -07:00
|
|
|
fn parse_sess() -> parse::parse_sess;
|
2012-02-01 13:41:01 -07:00
|
|
|
}
|
|
|
|
|
2012-07-18 16:18:02 -07:00
|
|
|
type fake_session = parse::parse_sess;
|
2012-02-01 13:41:01 -07:00
|
|
|
|
2012-08-07 18:10:06 -07:00
|
|
|
impl fake_session: fake_ext_ctxt {
|
2012-06-29 16:26:56 -07:00
|
|
|
fn cfg() -> ast::crate_cfg { ~[] }
|
2012-07-18 16:18:02 -07:00
|
|
|
fn parse_sess() -> parse::parse_sess { self }
|
2012-02-01 13:41:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fn mk_ctxt() -> fake_ext_ctxt {
|
2012-08-20 12:23:37 -07:00
|
|
|
parse::new_parse_sess(None) as fake_ext_ctxt
|
2012-02-01 13:41:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let ext_cx = mk_ctxt();
|
|
|
|
|
|
|
|
let abc = #ast{23};
|
2012-07-18 16:18:02 -07:00
|
|
|
check_pp(ext_cx, abc, pprust::print_expr, ~"23");
|
2012-02-01 13:41:01 -07:00
|
|
|
|
|
|
|
let expr3 = #ast{2 - $(abc) + 7};
|
2012-07-18 16:18:02 -07:00
|
|
|
check_pp(ext_cx, expr3, pprust::print_expr, ~"2 - 23 + 7");
|
2012-02-01 13:41:01 -07:00
|
|
|
|
2012-02-04 15:42:12 -07:00
|
|
|
let expr4 = #ast{2 - $(#ast{3}) + 9};
|
2012-07-18 16:18:02 -07:00
|
|
|
check_pp(ext_cx, expr4, pprust::print_expr, ~"2 - 3 + 9");
|
2012-02-01 13:41:01 -07:00
|
|
|
|
2012-07-30 16:01:07 -07:00
|
|
|
let ty = #ast[ty]{int};
|
2012-07-18 16:18:02 -07:00
|
|
|
check_pp(ext_cx, ty, pprust::print_type, ~"int");
|
2012-02-01 22:06:36 -07:00
|
|
|
|
2012-07-30 16:01:07 -07:00
|
|
|
let ty2 = #ast[ty]{option<$(ty)>};
|
2012-07-18 16:18:02 -07:00
|
|
|
check_pp(ext_cx, ty2, pprust::print_type, ~"option<int>");
|
2012-02-01 13:41:01 -07:00
|
|
|
|
2012-07-30 16:01:07 -07:00
|
|
|
let item = #ast[item]{const x : int = 10;};
|
2012-07-18 16:18:02 -07:00
|
|
|
check_pp(ext_cx, item, pprust::print_item, ~"const x: int = 10;");
|
2012-02-01 13:41:01 -07:00
|
|
|
|
2012-07-30 16:01:07 -07:00
|
|
|
let item2: @ast::item = #ast[item]{const x : int = $(abc);};
|
2012-07-18 16:18:02 -07:00
|
|
|
check_pp(ext_cx, item2, pprust::print_item, ~"const x: int = 23;");
|
2012-02-01 16:19:45 -07:00
|
|
|
|
2012-07-30 16:01:07 -07:00
|
|
|
let stmt = #ast[stmt]{let x = 20;};
|
2012-07-18 16:18:02 -07:00
|
|
|
check_pp(ext_cx, *stmt, pprust::print_stmt, ~"let x = 20;");
|
2012-02-01 13:41:01 -07:00
|
|
|
|
2012-07-30 16:01:07 -07:00
|
|
|
let stmt2 = #ast[stmt]{let x : $(ty) = $(abc);};
|
2012-07-18 16:18:02 -07:00
|
|
|
check_pp(ext_cx, *stmt2, pprust::print_stmt, ~"let x: int = 23;");
|
2012-02-01 17:28:49 -07:00
|
|
|
|
2012-07-30 16:01:07 -07:00
|
|
|
let pat = #ast[pat]{some(_)};
|
2012-07-18 16:18:02 -07:00
|
|
|
check_pp(ext_cx, pat, pprust::print_pat, ~"some(_)");
|
2012-02-08 17:45:02 -07:00
|
|
|
|
|
|
|
// issue #1785
|
|
|
|
let x = #ast{1};
|
|
|
|
let test1 = #ast{1+$(x)};
|
2012-07-18 16:18:02 -07:00
|
|
|
check_pp(ext_cx, test1, pprust::print_expr, ~"1 + 1");
|
2012-02-10 17:27:35 -07:00
|
|
|
|
|
|
|
let test2 = #ast{$(x)+1};
|
2012-07-18 16:18:02 -07:00
|
|
|
check_pp(ext_cx, test2, pprust::print_expr, ~"1 + 1");
|
2012-02-10 17:27:35 -07:00
|
|
|
|
|
|
|
let y = #ast{2};
|
|
|
|
let test3 = #ast{$(x) + $(y)};
|
2012-07-18 16:18:02 -07:00
|
|
|
check_pp(ext_cx, test3, pprust::print_expr, ~"1 + 2");
|
2012-02-21 15:34:26 -08:00
|
|
|
|
2012-07-30 16:01:07 -07:00
|
|
|
let crate = #ast[crate] { fn a() { } };
|
2012-07-18 16:18:02 -07:00
|
|
|
check_pp(ext_cx, crate, pprust::print_crate_, ~"fn a() { }\n");
|
2012-03-06 18:07:10 -07:00
|
|
|
|
|
|
|
// issue #1926
|
2012-07-30 16:01:07 -07:00
|
|
|
let s = #ast[expr]{__s};
|
|
|
|
let e = #ast[expr]{__e};
|
|
|
|
let call = #ast[expr]{$(s).foo(|__e| $(e) )};
|
2012-07-18 16:18:02 -07:00
|
|
|
check_pp(ext_cx, call, pprust::print_expr, ~"__s.foo(|__e| __e)")
|
2012-02-01 13:41:01 -07:00
|
|
|
}
|
|
|
|
|
2012-07-18 16:18:02 -07:00
|
|
|
fn check_pp<T>(cx: fake_ext_ctxt,
|
|
|
|
expr: T, f: fn(pprust::ps, T), expect: ~str) {
|
2012-09-14 09:40:28 -07:00
|
|
|
let s = do io::with_str_writer |wr| {
|
|
|
|
let pp = pprust::rust_printer(wr, cx.parse_sess().interner);
|
|
|
|
f(pp, expr);
|
|
|
|
pp::eof(pp.s);
|
|
|
|
};
|
|
|
|
stdout().write_line(s);
|
2012-07-13 22:57:48 -07:00
|
|
|
if expect != ~"" {
|
2012-09-14 09:40:28 -07:00
|
|
|
error!("expect: '%s', got: '%s'", expect, s);
|
2012-09-18 18:46:45 -07:00
|
|
|
assert s == expect;
|
2012-02-03 17:39:39 -08:00
|
|
|
}
|
2012-02-01 13:41:01 -07:00
|
|
|
}
|
|
|
|
|