2019-08-01 16:26:40 -05:00
|
|
|
use super::*;
|
|
|
|
|
2020-04-27 12:56:11 -05:00
|
|
|
use rustc_ast as ast;
|
2021-05-05 14:31:25 -05:00
|
|
|
use rustc_span::create_default_session_globals_then;
|
2020-04-25 14:13:56 -05:00
|
|
|
use rustc_span::symbol::Ident;
|
2019-08-01 16:26:40 -05:00
|
|
|
|
2019-08-01 17:58:40 -05:00
|
|
|
fn fun_to_string(
|
|
|
|
decl: &ast::FnDecl,
|
|
|
|
header: ast::FnHeader,
|
2020-04-25 14:13:56 -05:00
|
|
|
name: Ident,
|
2019-08-01 17:58:40 -05:00
|
|
|
generics: &ast::Generics,
|
|
|
|
) -> String {
|
|
|
|
to_string(|s| {
|
|
|
|
s.head("");
|
2020-02-20 18:21:17 -06:00
|
|
|
s.print_fn(decl, header, Some(name), generics);
|
2019-09-05 21:56:45 -05:00
|
|
|
s.end(); // Close the head box.
|
|
|
|
s.end(); // Close the outer box.
|
2019-08-01 17:58:40 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
fn variant_to_string(var: &ast::Variant) -> String {
|
|
|
|
to_string(|s| s.print_variant(var))
|
|
|
|
}
|
|
|
|
|
2019-08-01 16:26:40 -05:00
|
|
|
#[test]
|
|
|
|
fn test_fun_to_string() {
|
2021-05-05 14:31:25 -05:00
|
|
|
create_default_session_globals_then(|| {
|
2020-04-25 14:13:56 -05:00
|
|
|
let abba_ident = Ident::from_str("abba");
|
2019-08-01 16:26:40 -05:00
|
|
|
|
2020-02-14 21:10:59 -06:00
|
|
|
let decl =
|
|
|
|
ast::FnDecl { inputs: Vec::new(), output: ast::FnRetTy::Default(rustc_span::DUMMY_SP) };
|
2019-08-01 16:26:40 -05:00
|
|
|
let generics = ast::Generics::default();
|
|
|
|
assert_eq!(
|
2019-10-27 17:14:35 -05:00
|
|
|
fun_to_string(&decl, ast::FnHeader::default(), abba_ident, &generics),
|
2019-08-01 16:26:40 -05:00
|
|
|
"fn abba()"
|
|
|
|
);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_variant_to_string() {
|
2021-05-05 14:31:25 -05:00
|
|
|
create_default_session_globals_then(|| {
|
2020-04-25 14:13:56 -05:00
|
|
|
let ident = Ident::from_str("principal_skinner");
|
2019-08-01 16:26:40 -05:00
|
|
|
|
2019-08-13 19:40:21 -05:00
|
|
|
let var = ast::Variant {
|
2019-08-01 16:26:40 -05:00
|
|
|
ident,
|
2020-08-21 21:11:41 -05:00
|
|
|
vis: ast::Visibility {
|
|
|
|
span: rustc_span::DUMMY_SP,
|
|
|
|
kind: ast::VisibilityKind::Inherited,
|
|
|
|
tokens: None,
|
|
|
|
},
|
2021-06-16 17:11:13 -05:00
|
|
|
attrs: ast::AttrVec::new(),
|
2019-08-01 16:26:40 -05:00
|
|
|
id: ast::DUMMY_NODE_ID,
|
|
|
|
data: ast::VariantData::Unit(ast::DUMMY_NODE_ID),
|
|
|
|
disr_expr: None,
|
2019-12-31 11:15:40 -06:00
|
|
|
span: rustc_span::DUMMY_SP,
|
2019-09-09 07:26:25 -05:00
|
|
|
is_placeholder: false,
|
2019-08-13 19:40:21 -05:00
|
|
|
};
|
2019-08-01 16:26:40 -05:00
|
|
|
|
|
|
|
let varstr = variant_to_string(&var);
|
|
|
|
assert_eq!(varstr, "principal_skinner");
|
|
|
|
})
|
|
|
|
}
|