use proc_macro2::TokenStream;
use quote::quote;
mod generate;
pub use generate::generate_from_model_with_relations;
pub fn build_entity_path_from_schema_path(
schema_path: &TokenStream,
_source_module_path: &[String],
) -> TokenStream {
let path_str = schema_path.to_string();
let path_idents: Vec<syn::Ident> = path_str
.split("::")
.map(|s| {
let s = s.trim();
let name = if s == "Schema" { "Entity" } else { s };
syn::Ident::new(name, proc_macro2::Span::call_site())
})
.collect();
quote! { #(#path_idents)::* }
}
#[cfg(test)]
mod tests {
use rstest::rstest;
use super::*;
#[rstest]
#[case::crate_qualified("entity_path_crate_qualified", quote! { crate::models::user::Schema })]
#[case::simple_module("entity_path_simple_module", quote! { user::Schema })]
#[case::deeply_nested(
"entity_path_deeply_nested",
quote! { crate::api::models::entities::user::Schema }
)]
#[case::single_segment("entity_path_single_segment", quote! { Schema })]
fn build_entity_path_from_schema_path_snapshot(
#[case] snapshot_name: &str,
#[case] schema_path: TokenStream,
) {
insta::assert_snapshot!(
snapshot_name,
build_entity_path_from_schema_path(&schema_path, &[]).to_string()
);
}
}