use super::expand;
macro_rules! assert_contains {
($tokens:expr, $( $needle:expr ),+ $(,)?) => {
$(assert!(
$tokens.contains($needle),
"expected {:?} in expansion, got: {}",
$needle,
$tokens
);)+
};
}
fn expand_to_string(item: syn::ItemType) -> String {
expand(item).unwrap().to_string()
}
#[test]
fn test_declare_emits_exported_type_alias() {
let tokens = expand_to_string(syn::parse_quote! {
type TypeAlias<T, U> = Foo<T, i32, U>;
});
assert_contains!(
tokens,
"export type TypeAlias<T, U> = Foo<T, number, U>;",
"TS_APPEND_CONTENT",
"typescript_custom_section",
);
}
#[test]
fn test_declare_without_generics() {
let tokens = expand_to_string(syn::parse_quote! {
type Simple = Vec<String>;
});
assert_contains!(tokens, "export type Simple = string[];");
}
#[test]
fn test_declare_keeps_doc_comments() {
let tokens = expand_to_string(syn::parse_quote! {
type Documented = i32;
});
assert_contains!(tokens, "Alias docs", "export type Documented = number;");
}