@@ -10,18 +10,21 @@ use parallel_disk_usage::{
1010 fs_tree_builder:: FsTreeBuilder ,
1111 get_size:: GetApparentSize ,
1212 hardlink:: HardlinkIgnorant ,
13- ls_colors:: LsColors ,
1413 os_string_display:: OsStringDisplay ,
1514 reporter:: { ErrorOnlyReporter , ErrorReport } ,
16- visualizer:: { BarAlignment , Color , Coloring , ColumnWidthDistribution , Direction , Visualizer } ,
15+ visualizer:: { BarAlignment , ColumnWidthDistribution , Direction , Visualizer } ,
1716} ;
1817use pipe_trait:: Pipe ;
1918use pretty_assertions:: assert_eq;
20- use std:: {
21- collections:: HashMap ,
22- path:: PathBuf ,
23- process:: { Command , Stdio } ,
19+ use std:: process:: { Command , Stdio } ;
20+
21+ #[ cfg( unix) ]
22+ use parallel_disk_usage:: {
23+ ls_colors:: LsColors ,
24+ visualizer:: { Color , Coloring } ,
2425} ;
26+ #[ cfg( unix) ]
27+ use std:: collections:: HashMap ;
2528
2629#[ cfg( unix) ]
2730use parallel_disk_usage:: get_size:: { GetBlockCount , GetBlockSize } ;
@@ -824,7 +827,9 @@ fn colorful_equals_colorless() {
824827 . expect ( "spawn command with --color=always" ) ;
825828 inspect_stderr ( & colorful. stderr ) ;
826829 assert ! ( colorful. status. success( ) , "pdu exited with non-zero status" ) ;
827- let colorful_stripped = String :: from_utf8 ( colorful. stdout )
830+ let colorful_stripped = colorful
831+ . stdout
832+ . pipe ( String :: from_utf8)
828833 . expect ( "UTF-8" )
829834 . pipe ( strip_ansi_escapes:: strip_str)
830835 . trim_end ( )
@@ -842,37 +847,16 @@ fn colorful_equals_colorless() {
842847 assert_eq ! ( colorful_stripped, colorless) ;
843848}
844849
845- /// Recursively build a coloring map from a data tree.
846- fn build_coloring_map (
847- node : & DataTree < OsStringDisplay , impl parallel_disk_usage:: size:: Size > ,
848- path : PathBuf ,
849- map : & mut HashMap < OsStringDisplay , Color > ,
850- ) {
851- let node_path = path. join ( node. name ( ) . as_os_str ( ) ) ;
852- if !node. children ( ) . is_empty ( ) {
853- for child in node. children ( ) {
854- build_coloring_map ( child, node_path. clone ( ) , map) ;
855- }
856- return ;
857- }
858- let color = if node_path. is_symlink ( ) {
859- Color :: Symlink
860- } else if node_path. is_dir ( ) {
861- Color :: Directory
862- } else {
863- Color :: Normal
864- } ;
865- map. insert ( node. name ( ) . clone ( ) , color) ;
866- }
867-
850+ #[ cfg( unix) ]
868851#[ test]
869852fn color_always ( ) {
870- let workspace = SampleWorkspace :: default ( ) ;
853+ let workspace = SampleWorkspace :: simple_tree_with_diverse_kinds ( ) ;
871854
872855 let actual = Command :: new ( PDU )
873856 . with_current_dir ( & workspace)
874857 . with_arg ( "--color=always" )
875858 . with_arg ( "--total-width=100" )
859+ . with_arg ( "--min-ratio=0" )
876860 . pipe ( stdio)
877861 . output ( )
878862 . expect ( "spawn command with --color=always" )
@@ -887,13 +871,45 @@ fn color_always() {
887871 max_depth : 10 ,
888872 } ;
889873 let mut data_tree: DataTree < OsStringDisplay , _ > = builder. into ( ) ;
890- data_tree. par_cull_insignificant_data ( 0.01 ) ;
891874 data_tree. par_sort_by ( |left, right| left. size ( ) . cmp ( & right. size ( ) ) . reverse ( ) ) ;
892875 * data_tree. name_mut ( ) = OsStringDisplay :: os_string_from ( "." ) ;
893876
894877 let ls_colors = LsColors :: from_env ( ) ;
895- let mut map = HashMap :: new ( ) ;
896- build_coloring_map ( & data_tree, workspace. to_path_buf ( ) , & mut map) ;
878+ let map = HashMap :: from ( [
879+ (
880+ OsStringDisplay :: os_string_from ( "file-a1.txt" ) ,
881+ Color :: Normal ,
882+ ) ,
883+ (
884+ OsStringDisplay :: os_string_from ( "file-a2.txt" ) ,
885+ Color :: Normal ,
886+ ) ,
887+ (
888+ OsStringDisplay :: os_string_from ( "file-a3.txt" ) ,
889+ Color :: Normal ,
890+ ) ,
891+ (
892+ OsStringDisplay :: os_string_from ( "file-b1.txt" ) ,
893+ Color :: Normal ,
894+ ) ,
895+ (
896+ OsStringDisplay :: os_string_from ( "file-root.txt" ) ,
897+ Color :: Normal ,
898+ ) ,
899+ ( OsStringDisplay :: os_string_from ( "link-dir" ) , Color :: Symlink ) ,
900+ (
901+ OsStringDisplay :: os_string_from ( "link-file.txt" ) ,
902+ Color :: Symlink ,
903+ ) ,
904+ (
905+ OsStringDisplay :: os_string_from ( "empty-dir-1" ) ,
906+ Color :: Directory ,
907+ ) ,
908+ (
909+ OsStringDisplay :: os_string_from ( "empty-dir-2" ) ,
910+ Color :: Directory ,
911+ ) ,
912+ ] ) ;
897913 let coloring = Coloring :: new ( ls_colors, map) ;
898914
899915 let visualizer = Visualizer :: < OsStringDisplay , _ > {
0 commit comments