2012-02-01 14:41:01 -06:00
|
|
|
// xfail-pretty
|
|
|
|
|
|
|
|
use std;
|
|
|
|
use rustc;
|
|
|
|
|
|
|
|
import rustc::*;
|
2012-03-12 22:04:27 -05:00
|
|
|
import io::*;
|
2012-02-01 14:41:01 -06:00
|
|
|
|
|
|
|
import rustc::driver::diagnostic;
|
|
|
|
import rustc::syntax::ast;
|
|
|
|
import rustc::syntax::codemap;
|
|
|
|
import rustc::syntax::parse::parser;
|
|
|
|
import rustc::syntax::print::*;
|
|
|
|
|
|
|
|
fn new_parse_sess() -> parser::parse_sess {
|
|
|
|
let cm = codemap::new_codemap();
|
|
|
|
let handler = diagnostic::mk_handler(option::none);
|
|
|
|
let sess = @{
|
|
|
|
cm: cm,
|
2012-03-26 20:35:18 -05:00
|
|
|
mut next_id: 1,
|
2012-02-01 14:41:01 -06:00
|
|
|
span_diagnostic: diagnostic::mk_span_handler(handler, cm),
|
2012-03-26 20:35:18 -05:00
|
|
|
mut chpos: 0u,
|
|
|
|
mut byte_pos: 0u
|
2012-02-01 14:41:01 -06:00
|
|
|
};
|
|
|
|
ret sess;
|
|
|
|
}
|
|
|
|
|
|
|
|
iface fake_ext_ctxt {
|
2012-03-22 20:53:30 -05:00
|
|
|
fn cfg() -> ast::crate_cfg;
|
|
|
|
fn parse_sess() -> parser::parse_sess;
|
2012-02-01 14:41:01 -06:00
|
|
|
}
|
|
|
|
|
2012-03-22 20:53:30 -05:00
|
|
|
type fake_session = ();
|
2012-02-01 14:41:01 -06:00
|
|
|
|
|
|
|
impl of fake_ext_ctxt for fake_session {
|
2012-03-22 20:53:30 -05:00
|
|
|
fn cfg() -> ast::crate_cfg { [] }
|
|
|
|
fn parse_sess() -> parser::parse_sess { new_parse_sess() }
|
2012-02-01 14:41:01 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn mk_ctxt() -> fake_ext_ctxt {
|
2012-03-22 20:53:30 -05:00
|
|
|
() as fake_ext_ctxt
|
2012-02-01 14:41:01 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let ext_cx = mk_ctxt();
|
|
|
|
|
|
|
|
let abc = #ast{23};
|
|
|
|
check_pp(abc, pprust::print_expr, "23");
|
|
|
|
|
|
|
|
let expr3 = #ast{2 - $(abc) + 7};
|
|
|
|
check_pp(expr3, pprust::print_expr, "2 - 23 + 7");
|
|
|
|
|
2012-02-04 16:42:12 -06:00
|
|
|
let expr4 = #ast{2 - $(#ast{3}) + 9};
|
2012-02-01 14:41:01 -06:00
|
|
|
check_pp(expr4, pprust::print_expr, "2 - 3 + 9");
|
|
|
|
|
2012-02-01 23:06:36 -06:00
|
|
|
let ty = #ast(ty){int};
|
|
|
|
check_pp(ty, pprust::print_type, "int");
|
|
|
|
|
|
|
|
let ty2 = #ast(ty){option<$(ty)>};
|
|
|
|
check_pp(ty2, pprust::print_type, "option<int>");
|
2012-02-01 14:41:01 -06:00
|
|
|
|
|
|
|
let item = #ast(item){const x : int = 10;};
|
|
|
|
check_pp(item, pprust::print_item, "const x: int = 10;");
|
|
|
|
|
2012-02-01 18:20:56 -06:00
|
|
|
let item2: @ast::item = #ast(item){const x : int = $(abc);};
|
|
|
|
check_pp(item2, pprust::print_item, "const x: int = 23;");
|
2012-02-01 17:19:45 -06:00
|
|
|
|
2012-02-01 14:41:01 -06:00
|
|
|
let stmt = #ast(stmt){let x = 20;};
|
|
|
|
check_pp(*stmt, pprust::print_stmt, "let x = 20;");
|
|
|
|
|
2012-02-01 23:06:36 -06:00
|
|
|
let stmt2 = #ast(stmt){let x : $(ty) = $(abc);};
|
|
|
|
check_pp(*stmt2, pprust::print_stmt, "let x: int = 23;");
|
2012-02-01 18:28:49 -06:00
|
|
|
|
2012-02-01 14:41:01 -06:00
|
|
|
let pat = #ast(pat){some(_)};
|
|
|
|
check_pp(pat, pprust::print_pat, "some(_)");
|
2012-02-08 18:45:02 -06:00
|
|
|
|
|
|
|
// issue #1785
|
|
|
|
let x = #ast{1};
|
|
|
|
let test1 = #ast{1+$(x)};
|
|
|
|
check_pp(test1, pprust::print_expr, "1 + 1");
|
2012-02-10 18:27:35 -06:00
|
|
|
|
|
|
|
let test2 = #ast{$(x)+1};
|
|
|
|
check_pp(test2, pprust::print_expr, "1 + 1");
|
|
|
|
|
|
|
|
let y = #ast{2};
|
|
|
|
let test3 = #ast{$(x) + $(y)};
|
|
|
|
check_pp(test3, pprust::print_expr, "1 + 2");
|
2012-02-21 17:34:26 -06:00
|
|
|
|
|
|
|
let crate = #ast(crate) { fn a() { } };
|
|
|
|
check_pp(crate, pprust::print_crate_, "fn a() { }\n");
|
2012-03-06 19:07:10 -06:00
|
|
|
|
|
|
|
// issue #1926
|
|
|
|
let s = #ast(expr){__s};
|
|
|
|
let e = #ast(expr){__e};
|
|
|
|
let call = #ast(expr){$(s).foo {|__e| $(e)}};
|
|
|
|
check_pp(call, pprust::print_expr, "__s.foo {|__e| __e }")
|
2012-02-01 14:41:01 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn check_pp<T>(expr: T, f: fn(pprust::ps, T), expect: str) {
|
2012-03-13 09:55:45 -05:00
|
|
|
let buf = mem_buffer();
|
2012-03-12 22:04:27 -05:00
|
|
|
let pp = pprust::rust_printer(buf as io::writer);
|
2012-02-01 14:41:01 -06:00
|
|
|
f(pp, expr);
|
|
|
|
pp::eof(pp.s);
|
|
|
|
let str = mem_buffer_str(buf);
|
|
|
|
stdout().write_line(str);
|
2012-02-03 19:39:39 -06:00
|
|
|
if expect != "" {
|
|
|
|
#error("expect: '%s', got: '%s'", expect, str);
|
|
|
|
assert str == expect;
|
|
|
|
}
|
2012-02-01 14:41:01 -06:00
|
|
|
}
|
|
|
|
|