@@ -28,7 +28,7 @@ use parallel_disk_usage::{
2828 visualizer:: { Color , Coloring } ,
2929} ;
3030#[ cfg( unix) ]
31- use std:: { collections:: HashMap , ffi:: OsStr } ;
31+ use std:: { collections:: HashMap , ffi:: OsString } ;
3232
3333fn stdio ( command : Command ) -> Command {
3434 command
@@ -857,9 +857,98 @@ fn color_always() {
857857 ] ;
858858 let leaf_colors = HashMap :: from ( leaf_colors. map ( |( path, color) | {
859859 (
860- path. split ( '/' )
861- . map ( AsRef :: < OsStr > :: as_ref)
862- . collect :: < Vec < _ > > ( ) ,
860+ path. split ( '/' ) . map ( OsString :: from) . collect :: < Vec < _ > > ( ) ,
861+ color,
862+ )
863+ } ) ) ;
864+ let coloring = Coloring :: new ( ls_colors, leaf_colors) ;
865+
866+ let visualizer = Visualizer :: < OsStringDisplay , _ > {
867+ data_tree : & data_tree,
868+ bytes_format : BytesFormat :: MetricUnits ,
869+ direction : Direction :: BottomUp ,
870+ bar_alignment : BarAlignment :: Left ,
871+ column_width_distribution : ColumnWidthDistribution :: total ( 100 ) ,
872+ coloring : Some ( & coloring) ,
873+ } ;
874+ let expected = format ! ( "{visualizer}" ) ;
875+ let expected = expected. trim_end ( ) ;
876+ eprintln ! ( "EXPECTED:\n {expected}\n " ) ;
877+
878+ assert_eq ! ( actual, expected) ;
879+ }
880+
881+ #[ cfg( unix) ]
882+ #[ test]
883+ fn color_always_multiple_args ( ) {
884+ let workspace = SampleWorkspace :: simple_tree_with_diverse_kinds ( ) ;
885+
886+ let args = [
887+ "dir-a" ,
888+ "dir-b" ,
889+ "file-root.txt" ,
890+ "link-dir" ,
891+ "link-file.txt" ,
892+ "empty-dir-1" ,
893+ "empty-dir-2" ,
894+ ] ;
895+
896+ let actual = {
897+ let mut cmd = Command :: new ( PDU ) ;
898+ cmd = cmd
899+ . with_current_dir ( & workspace)
900+ . with_arg ( "--color=always" )
901+ . with_arg ( "--total-width=100" )
902+ . with_arg ( "--min-ratio=0" )
903+ . with_env ( "LS_COLORS" , LS_COLORS ) ;
904+ for arg in & args {
905+ cmd = cmd. with_arg ( arg) ;
906+ }
907+ cmd. pipe ( stdio)
908+ . output ( )
909+ . expect ( "spawn command with --color=always and multiple args" )
910+ . pipe ( stdout_text)
911+ } ;
912+ eprintln ! ( "ACTUAL:\n {actual}\n " ) ;
913+
914+ let data_tree = args
915+ . iter ( )
916+ . map ( |name| {
917+ let builder = FsTreeBuilder {
918+ root : workspace. to_path_buf ( ) . join ( name) ,
919+ size_getter : DEFAULT_GET_SIZE ,
920+ hardlinks_recorder : & HardlinkIgnorant ,
921+ reporter : & ErrorOnlyReporter :: new ( ErrorReport :: SILENT ) ,
922+ max_depth : 10 ,
923+ } ;
924+ let mut data_tree: DataTree < OsStringDisplay , _ > = builder. into ( ) ;
925+ * data_tree. name_mut ( ) = OsStringDisplay :: os_string_from ( name) ;
926+ data_tree
927+ } )
928+ . pipe ( |children| {
929+ DataTree :: dir (
930+ OsStringDisplay :: os_string_from ( "(total)" ) ,
931+ 0 . into ( ) ,
932+ children. collect ( ) ,
933+ )
934+ } )
935+ . into_par_sorted ( |left, right| left. size ( ) . cmp ( & right. size ( ) ) . reverse ( ) ) ;
936+
937+ let ls_colors = LsColors :: from_str ( LS_COLORS ) ;
938+ let leaf_colors = [
939+ ( "(total)/dir-a/file-a1.txt" , Color :: Normal ) ,
940+ ( "(total)/dir-a/file-a2.txt" , Color :: Normal ) ,
941+ ( "(total)/dir-a/subdir-a/file-a3.txt" , Color :: Normal ) ,
942+ ( "(total)/dir-b/file-b1.txt" , Color :: Normal ) ,
943+ ( "(total)/file-root.txt" , Color :: Normal ) ,
944+ ( "(total)/link-dir" , Color :: Symlink ) ,
945+ ( "(total)/link-file.txt" , Color :: Symlink ) ,
946+ ( "(total)/empty-dir-1" , Color :: Directory ) ,
947+ ( "(total)/empty-dir-2" , Color :: Directory ) ,
948+ ] ;
949+ let leaf_colors = HashMap :: from ( leaf_colors. map ( |( path, color) | {
950+ (
951+ path. split ( '/' ) . map ( OsString :: from) . collect :: < Vec < _ > > ( ) ,
863952 color,
864953 )
865954 } ) ) ;
0 commit comments