@@ -2058,4 +2058,86 @@ pub fn get_users() -> String {
20582058 // It should return a PathBuf (either from src/nonexistent... or just the folder name)
20592059 assert ! ( result. to_string_lossy( ) . contains( "nonexistent_folder_xyz" ) ) ;
20602060 }
2061+
2062+ // ========== Tests for extract_schema_name_attr ==========
2063+
2064+ #[ test]
2065+ fn test_extract_schema_name_attr_with_name ( ) {
2066+ let attrs: Vec < syn:: Attribute > = syn:: parse_quote! {
2067+ #[ schema( name = "CustomName" ) ]
2068+ } ;
2069+ let result = extract_schema_name_attr ( & attrs) ;
2070+ assert_eq ! ( result, Some ( "CustomName" . to_string( ) ) ) ;
2071+ }
2072+
2073+ #[ test]
2074+ fn test_extract_schema_name_attr_without_name ( ) {
2075+ let attrs: Vec < syn:: Attribute > = syn:: parse_quote! {
2076+ #[ derive( Debug ) ]
2077+ } ;
2078+ let result = extract_schema_name_attr ( & attrs) ;
2079+ assert_eq ! ( result, None ) ;
2080+ }
2081+
2082+ #[ test]
2083+ fn test_extract_schema_name_attr_empty_schema ( ) {
2084+ let attrs: Vec < syn:: Attribute > = syn:: parse_quote! {
2085+ #[ schema]
2086+ } ;
2087+ let result = extract_schema_name_attr ( & attrs) ;
2088+ assert_eq ! ( result, None ) ;
2089+ }
2090+
2091+ #[ test]
2092+ fn test_extract_schema_name_attr_with_other_attrs ( ) {
2093+ let attrs: Vec < syn:: Attribute > = syn:: parse_quote! {
2094+ #[ derive( Clone ) ]
2095+ #[ schema( name = "MySchema" ) ]
2096+ #[ serde( rename_all = "camelCase" ) ]
2097+ } ;
2098+ let result = extract_schema_name_attr ( & attrs) ;
2099+ assert_eq ! ( result, Some ( "MySchema" . to_string( ) ) ) ;
2100+ }
2101+
2102+ // ========== Tests for process_derive_schema ==========
2103+
2104+ #[ test]
2105+ fn test_process_derive_schema_simple ( ) {
2106+ let input: syn:: DeriveInput = syn:: parse_quote! {
2107+ struct User {
2108+ id: i32 ,
2109+ name: String ,
2110+ }
2111+ } ;
2112+ let ( metadata, tokens) = process_derive_schema ( & input) ;
2113+ assert_eq ! ( metadata. name, "User" ) ;
2114+ assert ! ( metadata. definition. contains( "User" ) ) ;
2115+ let tokens_str = tokens. to_string ( ) ;
2116+ assert ! ( tokens_str. contains( "SchemaBuilder" ) ) ;
2117+ }
2118+
2119+ #[ test]
2120+ fn test_process_derive_schema_with_custom_name ( ) {
2121+ let input: syn:: DeriveInput = syn:: parse_quote! {
2122+ #[ schema( name = "CustomUserSchema" ) ]
2123+ struct User {
2124+ id: i32 ,
2125+ }
2126+ } ;
2127+ let ( metadata, _) = process_derive_schema ( & input) ;
2128+ assert_eq ! ( metadata. name, "CustomUserSchema" ) ;
2129+ }
2130+
2131+ #[ test]
2132+ fn test_process_derive_schema_with_generics ( ) {
2133+ let input: syn:: DeriveInput = syn:: parse_quote! {
2134+ struct Container <T > {
2135+ value: T ,
2136+ }
2137+ } ;
2138+ let ( metadata, tokens) = process_derive_schema ( & input) ;
2139+ assert_eq ! ( metadata. name, "Container" ) ;
2140+ let tokens_str = tokens. to_string ( ) ;
2141+ assert ! ( tokens_str. contains( "< T >" ) || tokens_str. contains( "<T>" ) ) ;
2142+ }
20612143}
0 commit comments