@@ -995,4 +995,44 @@ pub const NOT_STRUCT: i32 = 1;
995995 assert ! ( result. is_some( ) , "Should find Model" ) ;
996996 assert ! ( result. unwrap( ) . definition. contains( "Model" ) ) ;
997997 }
998+
999+ #[ test]
1000+ #[ serial]
1001+ fn test_find_struct_disambiguation_fallback_contains ( ) {
1002+ // Tests: No exact match, but fallback "contains" finds exactly one match
1003+ // This covers lines 169-174 (the fallback contains path)
1004+ let temp_dir = TempDir :: new ( ) . unwrap ( ) ;
1005+ let src_dir = temp_dir. path ( ) ;
1006+
1007+ std:: fs:: create_dir ( src_dir. join ( "models" ) ) . unwrap ( ) ;
1008+ // No file named exactly "special.rs", but "special_item.rs" contains "special"
1009+ std:: fs:: write (
1010+ src_dir. join ( "models" ) . join ( "special_item.rs" ) ,
1011+ "pub struct Model { pub special_field: i32 }" ,
1012+ )
1013+ . unwrap ( ) ;
1014+ // Another file that doesn't match
1015+ std:: fs:: write (
1016+ src_dir. join ( "models" ) . join ( "regular.rs" ) ,
1017+ "pub struct Model { pub regular_field: String }" ,
1018+ )
1019+ . unwrap ( ) ;
1020+
1021+ // With hint "SpecialSchema" -> prefix "special"
1022+ // No exact match (no "special.rs"), but "special_item.rs" contains "special"
1023+ let result = find_struct_by_name_in_all_files ( src_dir, "Model" , Some ( "SpecialSchema" ) ) ;
1024+ assert ! (
1025+ result. is_some( ) ,
1026+ "SpecialSchema hint should match special_item.rs via contains fallback"
1027+ ) ;
1028+ let ( metadata, module_path) = result. unwrap ( ) ;
1029+ assert ! (
1030+ metadata. definition. contains( "special_field" ) ,
1031+ "Should be special_item Model with special_field"
1032+ ) ;
1033+ assert ! (
1034+ module_path. contains( & "special_item" . to_string( ) ) ,
1035+ "Module path should contain 'special_item'"
1036+ ) ;
1037+ }
9981038}
0 commit comments