2012-12-10 19:32:48 -06:00
|
|
|
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2012-02-01 14:41:01 -06:00
|
|
|
// xfail-pretty
|
|
|
|
|
2012-09-18 17:52:21 -05:00
|
|
|
#[legacy_modes];
|
|
|
|
|
2012-09-11 19:46:20 -05:00
|
|
|
extern mod std;
|
|
|
|
extern mod syntax;
|
2012-02-01 14:41:01 -06:00
|
|
|
|
2012-12-28 20:42:10 -06:00
|
|
|
use core::io::*;
|
2012-02-01 14:41:01 -06:00
|
|
|
|
2012-09-05 14:32:05 -05:00
|
|
|
use syntax::diagnostic;
|
|
|
|
use syntax::ast;
|
|
|
|
use syntax::codemap;
|
2012-12-12 12:44:01 -06:00
|
|
|
use syntax::codemap::span;
|
2012-09-05 14:32:05 -05:00
|
|
|
use syntax::parse;
|
|
|
|
use syntax::print::*;
|
2012-02-01 14:41:01 -06:00
|
|
|
|
2012-12-12 12:44:01 -06:00
|
|
|
|
2012-07-31 12:27:51 -05:00
|
|
|
trait fake_ext_ctxt {
|
2012-03-22 20:53:30 -05:00
|
|
|
fn cfg() -> ast::crate_cfg;
|
2012-04-18 01:34:48 -05:00
|
|
|
fn parse_sess() -> parse::parse_sess;
|
2012-12-12 12:44:01 -06:00
|
|
|
fn call_site() -> span;
|
|
|
|
fn ident_of(st: ~str) -> ast::ident;
|
2012-02-01 14:41:01 -06:00
|
|
|
}
|
|
|
|
|
2012-07-18 18:18:02 -05:00
|
|
|
type fake_session = parse::parse_sess;
|
2012-02-01 14:41:01 -06:00
|
|
|
|
2012-08-07 20:10:06 -05:00
|
|
|
impl fake_session: fake_ext_ctxt {
|
2012-06-29 18:26:56 -05:00
|
|
|
fn cfg() -> ast::crate_cfg { ~[] }
|
2012-07-18 18:18:02 -05:00
|
|
|
fn parse_sess() -> parse::parse_sess { self }
|
2012-12-12 12:44:01 -06:00
|
|
|
fn call_site() -> span {
|
|
|
|
codemap::span {
|
|
|
|
lo: codemap::BytePos(0),
|
|
|
|
hi: codemap::BytePos(0),
|
|
|
|
expn_info: None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fn ident_of(st: ~str) -> ast::ident {
|
|
|
|
self.interner.intern(@copy st)
|
|
|
|
}
|
2012-02-01 14:41:01 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn mk_ctxt() -> fake_ext_ctxt {
|
2012-08-20 14:23:37 -05:00
|
|
|
parse::new_parse_sess(None) as fake_ext_ctxt
|
2012-02-01 14:41:01 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let ext_cx = mk_ctxt();
|
|
|
|
|
2012-12-12 12:44:01 -06:00
|
|
|
let abc = quote_expr!(23);
|
2012-07-18 18:18:02 -05:00
|
|
|
check_pp(ext_cx, abc, pprust::print_expr, ~"23");
|
2012-02-01 14:41:01 -06:00
|
|
|
|
|
|
|
|
2012-12-12 12:44:01 -06:00
|
|
|
let ty = quote_ty!(int);
|
2012-07-18 18:18:02 -05:00
|
|
|
check_pp(ext_cx, ty, pprust::print_type, ~"int");
|
2012-02-01 23:06:36 -06:00
|
|
|
|
2012-12-12 12:44:01 -06:00
|
|
|
let item = quote_item!(const x : int = 10;).get();
|
2012-07-18 18:18:02 -05:00
|
|
|
check_pp(ext_cx, item, pprust::print_item, ~"const x: int = 10;");
|
2012-02-01 14:41:01 -06:00
|
|
|
|
2012-12-12 12:44:01 -06:00
|
|
|
let stmt = quote_stmt!(let x = 20;);
|
2012-07-18 18:18:02 -05:00
|
|
|
check_pp(ext_cx, *stmt, pprust::print_stmt, ~"let x = 20;");
|
2012-02-01 14:41:01 -06:00
|
|
|
|
2012-12-12 12:44:01 -06:00
|
|
|
let pat = quote_pat!(some(_));
|
2012-12-07 16:39:29 -06:00
|
|
|
check_pp(ext_cx, pat, pprust::print_refutable_pat, ~"some(_)");
|
2012-02-08 18:45:02 -06:00
|
|
|
|
2012-02-01 14:41:01 -06:00
|
|
|
}
|
|
|
|
|
2012-07-18 18:18:02 -05:00
|
|
|
fn check_pp<T>(cx: fake_ext_ctxt,
|
|
|
|
expr: T, f: fn(pprust::ps, T), expect: ~str) {
|
2012-09-14 11:40:28 -05: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-14 00:57:48 -05:00
|
|
|
if expect != ~"" {
|
2012-09-14 11:40:28 -05:00
|
|
|
error!("expect: '%s', got: '%s'", expect, s);
|
2012-09-18 20:46:45 -05:00
|
|
|
assert s == expect;
|
2012-02-03 19:39:39 -06:00
|
|
|
}
|
2012-02-01 14:41:01 -06:00
|
|
|
}
|
|
|
|
|