@@ -271,9 +271,6 @@ fn format(opt: opt::Opt) -> Result<i32> {
271271 let opt_for_config_resolver = opt. clone ( ) ;
272272 let mut config_resolver = config:: ConfigResolver :: new ( & opt_for_config_resolver) ?;
273273
274- // TODO:
275- // debug!("config: {:#?}", config);
276-
277274 // Create range if provided
278275 let range = if opt. range_start . is_some ( ) || opt. range_end . is_some ( ) {
279276 Some ( Range :: from_values ( opt. range_start , opt. range_end ) )
@@ -953,4 +950,74 @@ mod tests {
953950
954951 cwd. close ( ) . unwrap ( ) ;
955952 }
953+
954+ #[ test]
955+ fn test_uses_cli_overrides_instead_of_default_configuration ( ) {
956+ let cwd = construct_tree ! ( {
957+ "foo.lua" : "local x = \" hello\" " ,
958+ } ) ;
959+
960+ let mut cmd = create_stylua ( ) ;
961+ cmd. current_dir ( cwd. path ( ) )
962+ . args ( [ "--quote-style" , "AutoPreferSingle" , "." ] )
963+ . assert ( )
964+ . success ( ) ;
965+
966+ cwd. child ( "foo.lua" ) . assert ( "local x = 'hello'\n " ) ;
967+
968+ cwd. close ( ) . unwrap ( ) ;
969+ }
970+
971+ #[ test]
972+ fn test_uses_cli_overrides_instead_of_default_configuration_stdin_filepath ( ) {
973+ let cwd = construct_tree ! ( {
974+ "foo.lua" : "local x = \" hello\" " ,
975+ } ) ;
976+
977+ let mut cmd = create_stylua ( ) ;
978+ cmd. current_dir ( cwd. path ( ) )
979+ . args ( [ "--quote-style" , "AutoPreferSingle" , "-" ] )
980+ . write_stdin ( "local x = \" hello\" " )
981+ . assert ( )
982+ . success ( )
983+ . stdout ( "local x = 'hello'\n " ) ;
984+
985+ cwd. close ( ) . unwrap ( ) ;
986+ }
987+
988+ #[ test]
989+ fn test_uses_cli_overrides_instead_of_found_configuration ( ) {
990+ let cwd = construct_tree ! ( {
991+ "stylua.toml" : "quote_style = 'AutoPreferDouble'" ,
992+ "foo.lua" : "local x = \" hello\" " ,
993+ } ) ;
994+
995+ let mut cmd = create_stylua ( ) ;
996+ cmd. current_dir ( cwd. path ( ) )
997+ . args ( [ "--quote-style" , "AutoPreferSingle" , "." ] )
998+ . assert ( )
999+ . success ( ) ;
1000+
1001+ cwd. child ( "foo.lua" ) . assert ( "local x = 'hello'\n " ) ;
1002+
1003+ cwd. close ( ) . unwrap ( ) ;
1004+ }
1005+
1006+ #[ test]
1007+ fn test_uses_cli_overrides_instead_of_found_configuration_stdin_filepath ( ) {
1008+ let cwd = construct_tree ! ( {
1009+ "stylua.toml" : "quote_style = 'AutoPreferDouble'" ,
1010+ "foo.lua" : "local x = \" hello\" " ,
1011+ } ) ;
1012+
1013+ let mut cmd = create_stylua ( ) ;
1014+ cmd. current_dir ( cwd. path ( ) )
1015+ . args ( [ "--quote-style" , "AutoPreferSingle" , "-" ] )
1016+ . write_stdin ( "local x = \" hello\" " )
1017+ . assert ( )
1018+ . success ( )
1019+ . stdout ( "local x = 'hello'\n " ) ;
1020+
1021+ cwd. close ( ) . unwrap ( ) ;
1022+ }
9561023}
0 commit comments