@@ -66,7 +66,7 @@ pub struct TableDoc {
6666 name : String ,
6767 doc : Option < String > ,
6868 columns : Vec < ColumnDoc > ,
69- file : Option < PathBuf > ,
69+ path : Option < PathBuf > ,
7070}
7171
7272impl TableDoc {
@@ -83,9 +83,9 @@ impl TableDoc {
8383 name : String ,
8484 doc : Option < String > ,
8585 columns : Vec < ColumnDoc > ,
86- file : Option < PathBuf > ,
86+ path : Option < PathBuf > ,
8787 ) -> Self {
88- Self { schema, name, doc, columns, file }
88+ Self { schema, name, doc, columns, path }
8989 }
9090
9191 /// Getter for the `Schema` of the table (if there is one)
@@ -113,6 +113,11 @@ impl TableDoc {
113113 self . doc = Some ( doc. into ( ) ) ;
114114 }
115115
116+ /// Setter for updating the table [`PathBuf`] source
117+ pub fn set_path ( & mut self , path : Option < impl Into < PathBuf > > ) {
118+ self . path = path. map ( Into :: into) ;
119+ }
120+
116121 /// Getter for the `columns` field
117122 #[ must_use]
118123 #[ allow( clippy:: missing_const_for_fn) ]
@@ -202,22 +207,13 @@ impl SqlFileDoc {
202207 }
203208 let table_leading = comments. leading_comment ( table_start) ;
204209 let ( schema, name) = schema_and_table ( & table. name ) ?;
205- let table_doc = match table_leading {
206- Some ( comment) => TableDoc :: new (
207- schema,
208- name,
209- Some ( comment. text ( ) . to_string ( ) ) ,
210- column_docs,
211- Some ( file. path_into_path_buf ( ) ) ,
212- ) ,
213- None => TableDoc :: new (
214- schema,
215- name,
216- None ,
217- column_docs,
218- Some ( file. path_into_path_buf ( ) ) ,
219- ) ,
220- } ;
210+ let table_doc = TableDoc :: new (
211+ schema,
212+ name,
213+ table_leading. as_ref ( ) . map ( |c| c. text ( ) . to_string ( ) ) ,
214+ column_docs,
215+ file. path_into_path_buf ( ) ,
216+ ) ;
221217 tables. push ( table_doc) ;
222218 }
223219 // can add support for other types of statements below
@@ -233,6 +229,12 @@ impl SqlFileDoc {
233229 pub fn tables ( & self ) -> & [ TableDoc ] {
234230 & self . tables
235231 }
232+
233+ /// Getter that returns a mutable reference to the [`TableDoc`] vec
234+ pub fn tables_mut ( & mut self ) -> & mut [ TableDoc ] {
235+ & mut self . tables
236+ }
237+
236238 /// Returns the number fo tables in the `SqlFileDoc`
237239 #[ must_use]
238240 pub fn number_of_tables ( & self ) -> usize {
@@ -336,32 +338,43 @@ mod tests {
336338 let filename = file
337339 . file ( )
338340 . path ( )
339- . file_name ( )
341+ . and_then ( |p| p . file_name ( ) )
340342 . and_then ( |s| s. to_str ( ) )
341- . unwrap_or_else ( || panic ! ( "unable to find file name" ) ) ;
343+ . ok_or ( "unable to parse file" ) ?;
344+
345+ let got = docs?;
346+ let file_path = file. file ( ) . path ( ) . ok_or ( "missing path" ) ?;
342347
343348 match filename {
344349 "with_single_line_comments.sql" | "with_mixed_comments.sql" => {
345- assert_eq ! ( & docs?, & expected_values[ 0 ] ) ;
350+ let expected = with_path ( expected_values[ 0 ] . clone ( ) , file_path) ;
351+ assert_eq ! ( & got, & expected) ;
346352 }
347353 "with_multiline_comments.sql" => {
348- assert_eq ! ( & docs?, & expected_values[ 1 ] ) ;
354+ let expected = with_path ( expected_values[ 1 ] . clone ( ) , file_path) ;
355+ assert_eq ! ( & got, & expected) ;
349356 }
350357 "without_comments.sql" => {
351- let expected = expected_without_comments_docs ( ) ;
352- assert_eq ! ( & docs?, & expected) ;
353- }
354- other => {
355- unreachable ! (
356- "unexpected test file {other}; directory should only contain known test files"
357- ) ;
358+ let expected = with_path ( expected_without_comments_docs ( ) , file_path) ;
359+ assert_eq ! ( & got, & expected) ;
358360 }
361+ _ => unreachable ! ( ) ,
359362 }
360363 }
361364
362365 Ok ( ( ) )
363366 }
364367
368+ fn with_path ( mut doc : SqlFileDoc , path : & std:: path:: Path ) -> SqlFileDoc {
369+ let pb = path. to_path_buf ( ) ;
370+
371+ for table in doc. tables_mut ( ) {
372+ table. set_path ( Some ( pb. clone ( ) ) ) ;
373+ }
374+
375+ doc
376+ }
377+
365378 fn expected_without_comments_docs ( ) -> SqlFileDoc {
366379 SqlFileDoc :: new ( vec ! [
367380 TableDoc :: new(
0 commit comments