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