@@ -29,8 +29,14 @@ fn parse_fill_with_args(args: &[String]) -> HashMap<(String, String), String> {
2929}
3030
3131/// Format the type info string for display.
32- fn format_type_info ( column_type : Option < & String > ) -> String {
33- column_type. map ( |t| format ! ( " ({})" , t) ) . unwrap_or_default ( )
32+ /// Includes column type and default value hint if available.
33+ fn format_type_info ( column_type : Option < & String > , default_value : Option < & String > ) -> String {
34+ match ( column_type, default_value) {
35+ ( Some ( t) , Some ( d) ) => format ! ( " ({}, default: {})" , t, d) ,
36+ ( Some ( t) , None ) => format ! ( " ({})" , t) ,
37+ ( None , Some ( d) ) => format ! ( " (default: {})" , d) ,
38+ ( None , None ) => String :: new ( ) ,
39+ }
3440}
3541
3642/// Format a single fill_with item for display.
@@ -75,9 +81,10 @@ fn print_fill_with_item_and_get_prompt(
7581 table : & str ,
7682 column : & str ,
7783 column_type : Option < & String > ,
84+ default_value : Option < & String > ,
7885 action_type : & str ,
7986) -> String {
80- let type_info = format_type_info ( column_type) ;
87+ let type_info = format_type_info ( column_type, default_value ) ;
8188 let item_display = format_fill_with_item ( table, column, & type_info, action_type) ;
8289 println ! ( "{}" , item_display) ;
8390 format_fill_with_prompt ( table, column)
@@ -128,6 +135,7 @@ where
128135 & item. table ,
129136 & item. column ,
130137 item. column_type . as_ref ( ) ,
138+ item. default_value . as_ref ( ) ,
131139 item. action_type ,
132140 ) ;
133141
@@ -720,15 +728,30 @@ mod tests {
720728 }
721729
722730 #[ test]
723- fn test_format_type_info_with_some ( ) {
724- let column_type = Some ( "Integer" . to_string ( ) ) ;
725- let result = format_type_info ( column_type. as_ref ( ) ) ;
726- assert_eq ! ( result, " (Integer)" ) ;
731+ fn test_format_type_info_with_type_and_default ( ) {
732+ let column_type = Some ( "integer" . to_string ( ) ) ;
733+ let default_value = Some ( "0" . to_string ( ) ) ;
734+ let result = format_type_info ( column_type. as_ref ( ) , default_value. as_ref ( ) ) ;
735+ assert_eq ! ( result, " (integer, default: 0)" ) ;
736+ }
737+
738+ #[ test]
739+ fn test_format_type_info_with_type_only ( ) {
740+ let column_type = Some ( "text" . to_string ( ) ) ;
741+ let result = format_type_info ( column_type. as_ref ( ) , None ) ;
742+ assert_eq ! ( result, " (text)" ) ;
743+ }
744+
745+ #[ test]
746+ fn test_format_type_info_with_default_only ( ) {
747+ let default_value = Some ( "0" . to_string ( ) ) ;
748+ let result = format_type_info ( None , default_value. as_ref ( ) ) ;
749+ assert_eq ! ( result, " (default: 0)" ) ;
727750 }
728751
729752 #[ test]
730753 fn test_format_type_info_with_none ( ) {
731- let result = format_type_info ( None ) ;
754+ let result = format_type_info ( None , None ) ;
732755 assert_eq ! ( result, "" ) ;
733756 }
734757
@@ -766,7 +789,8 @@ mod tests {
766789 let prompt = print_fill_with_item_and_get_prompt (
767790 "users" ,
768791 "email" ,
769- Some ( & "Text" . to_string ( ) ) ,
792+ Some ( & "text" . to_string ( ) ) ,
793+ Some ( & "''" . to_string ( ) ) ,
770794 "AddColumn" ,
771795 ) ;
772796 assert ! ( prompt. contains( "Enter fill value for" ) ) ;
@@ -777,12 +801,26 @@ mod tests {
777801 #[ test]
778802 fn test_print_fill_with_item_and_get_prompt_no_type ( ) {
779803 let prompt =
780- print_fill_with_item_and_get_prompt ( "orders" , "status" , None , "ModifyColumnNullable" ) ;
804+ print_fill_with_item_and_get_prompt ( "orders" , "status" , None , None , "ModifyColumnNullable" ) ;
781805 assert ! ( prompt. contains( "Enter fill value for" ) ) ;
782806 assert ! ( prompt. contains( "orders" ) ) ;
783807 assert ! ( prompt. contains( "status" ) ) ;
784808 }
785809
810+ #[ test]
811+ fn test_print_fill_with_item_and_get_prompt_with_default ( ) {
812+ let prompt = print_fill_with_item_and_get_prompt (
813+ "users" ,
814+ "age" ,
815+ Some ( & "integer" . to_string ( ) ) ,
816+ Some ( & "0" . to_string ( ) ) ,
817+ "AddColumn" ,
818+ ) ;
819+ assert ! ( prompt. contains( "Enter fill value for" ) ) ;
820+ assert ! ( prompt. contains( "users" ) ) ;
821+ assert ! ( prompt. contains( "age" ) ) ;
822+ }
823+
786824 #[ test]
787825 fn test_print_fill_with_header ( ) {
788826 // Just verify it doesn't panic - output goes to stdout
@@ -804,7 +842,8 @@ mod tests {
804842 table: "users" . to_string( ) ,
805843 column: "email" . to_string( ) ,
806844 action_type: "AddColumn" ,
807- column_type: Some ( "Text" . to_string( ) ) ,
845+ column_type: Some ( "text" . to_string( ) ) ,
846+ default_value: Some ( "''" . to_string( ) ) ,
808847 } ] ;
809848
810849 let mut fill_values = HashMap :: new ( ) ;
@@ -832,14 +871,16 @@ mod tests {
832871 table: "users" . to_string( ) ,
833872 column: "email" . to_string( ) ,
834873 action_type: "AddColumn" ,
835- column_type: Some ( "Text" . to_string( ) ) ,
874+ column_type: Some ( "text" . to_string( ) ) ,
875+ default_value: Some ( "''" . to_string( ) ) ,
836876 } ,
837877 FillWithRequired {
838878 action_index: 1 ,
839879 table: "orders" . to_string( ) ,
840880 column: "status" . to_string( ) ,
841881 action_type: "ModifyColumnNullable" ,
842882 column_type: None ,
883+ default_value: None ,
843884 } ,
844885 ] ;
845886
@@ -898,7 +939,8 @@ mod tests {
898939 table: "users" . to_string( ) ,
899940 column: "email" . to_string( ) ,
900941 action_type: "AddColumn" ,
901- column_type: Some ( "Text" . to_string( ) ) ,
942+ column_type: Some ( "text" . to_string( ) ) ,
943+ default_value: Some ( "''" . to_string( ) ) ,
902944 } ] ;
903945
904946 let mut fill_values = HashMap :: new ( ) ;
0 commit comments