@@ -179,42 +179,62 @@ fn test_with_deny_list_from_files() {
179179
180180#[ test]
181181fn test_with_no_deny_list_from_files ( ) {
182- let generated_docs = generate_docs_from_dir_no_deny ( "sql_files" )
183- . unwrap_or_else ( |_| panic ! ( "unable to locate test dir" ) ) ;
184- let expected_paths = [
185- "sql_files/without_comments.sql" ,
186- "sql_files/with_multiline_comments.sql" ,
187- "sql_files/with_single_line_comments.sql" ,
188- "sql_files/with_mixed_comments.sql" ,
182+ use std:: path:: Path ;
183+ let Ok ( generated_docs) = generate_docs_from_dir_no_deny ( "sql_files" ) else {
184+ panic ! ( "unable to locate test dir" ) ;
185+ } ;
186+ let mut actual_paths: Vec < String > = generated_docs
187+ . iter ( )
188+ . map ( |( path, _) | path. to_string_lossy ( ) . into_owned ( ) )
189+ . collect ( ) ;
190+ actual_paths. sort ( ) ;
191+ let mut expected_paths = vec ! [
192+ "sql_files/without_comments.sql" . to_string( ) ,
193+ "sql_files/with_multiline_comments.sql" . to_string( ) ,
194+ "sql_files/with_single_line_comments.sql" . to_string( ) ,
195+ "sql_files/with_mixed_comments.sql" . to_string( ) ,
189196 ] ;
197+ expected_paths. sort ( ) ;
198+ assert_eq ! ( actual_paths, expected_paths) ;
199+ let target = Path :: new ( "sql_files/with_mixed_comments.sql" ) ;
200+ let Some ( ( _, mixed_docs) ) = generated_docs
201+ . iter ( )
202+ . find ( |( path, _) | path. as_path ( ) == target)
203+ else {
204+ panic ! ( "with_mixed_comments.sql should be present" ) ;
205+ } ;
190206 let table_names = [ "users" , "posts" ] ;
191- let table_comments =
192- [ "Users table stores user account information" , "Posts table stores blog posts" ] ;
207+ let table_comments = [
208+ "Users table stores user account information" ,
209+ "Posts table stores blog posts" ,
210+ ] ;
193211 let user_columns = [ "id" , "username" , "email" , "created_at" ] ;
194- let user_columns_comments =
195- [ "Primary key" , "Username for login" , "Email address" , "When the user registered" ] ;
196- for ( i, ( buf, sql_docs) ) in generated_docs. iter ( ) . enumerate ( ) {
197- assert_eq ! ( buf, expected_paths[ i] ) ;
198- if buf == "sql_files/with_mixed_comments.sql" {
199- for ( i, table) in sql_docs. tables ( ) . iter ( ) . enumerate ( ) {
200- assert_eq ! ( table. name( ) , table_names[ i] ) ;
201- match table. doc ( ) . as_ref ( ) {
202- Some ( val) => assert_eq ! ( val, table_comments[ i] ) ,
203- None => panic ! ( "There should be a value for the table doc" ) ,
204- }
205- if table. name ( ) == "users" {
206- for ( i, column) in table. columns ( ) . iter ( ) . enumerate ( ) {
207- assert_eq ! ( column. name( ) , user_columns[ i] ) ;
208- match column. doc ( ) . as_ref ( ) {
209- Some ( val) => assert_eq ! ( val, user_columns_comments[ i] ) ,
210- None => panic ! ( "there should be a value for the doc column" ) ,
211- }
212- }
212+ let user_columns_comments = [
213+ "Primary key" ,
214+ "Username for login" ,
215+ "Email address" ,
216+ "When the user registered" ,
217+ ] ;
218+ for ( i, table) in mixed_docs. tables ( ) . iter ( ) . enumerate ( ) {
219+ assert_eq ! ( table. name( ) , table_names[ i] ) ;
220+
221+ match table. doc ( ) . as_ref ( ) {
222+ Some ( val) => assert_eq ! ( val, & table_comments[ i] ) ,
223+ None => panic ! ( "There should be a value for the table doc" ) ,
224+ }
225+
226+ if table. name ( ) == "users" {
227+ for ( i, column) in table. columns ( ) . iter ( ) . enumerate ( ) {
228+ assert_eq ! ( column. name( ) , user_columns[ i] ) ;
229+ match column. doc ( ) . as_ref ( ) {
230+ Some ( val) => assert_eq ! ( val, & user_columns_comments[ i] ) ,
231+ None => panic ! ( "there should be a value for the doc column" ) ,
213232 }
214233 }
215234 }
216235 }
217236}
237+
218238#[ test]
219239fn test_doc_errors ( ) {
220240 use std:: fs;
0 commit comments