@@ -23,6 +23,14 @@ impl LinkPathList {
2323 LinkPathList ( vec ! [ path] )
2424 }
2525
26+ /// Create a list of many paths.
27+ #[ cfg( test) ]
28+ pub ( crate ) fn many ( paths : impl IntoIterator < Item : Into < PathBuf > > ) -> Self {
29+ let paths: Vec < _ > = paths. into_iter ( ) . map ( Into :: into) . collect ( ) ;
30+ assert ! ( !paths. is_empty( ) , "paths must not be empty" ) ;
31+ LinkPathList ( paths)
32+ }
33+
2634 /// Add a path to the list.
2735 pub ( crate ) fn add ( & mut self , path : PathBuf ) {
2836 self . 0 . push ( path)
@@ -43,3 +51,50 @@ impl LinkPathList {
4351 self . into ( )
4452 }
4553}
54+
55+ #[ cfg( test) ]
56+ mod tests {
57+ use super :: LinkPathList ;
58+ use pipe_trait:: Pipe ;
59+ use pretty_assertions:: { assert_eq, assert_ne} ;
60+
61+ #[ test]
62+ fn item_order_is_irrelevant_to_equality ( ) {
63+ let a = [ "3" , "4" , "0" , "2" , "1" ]
64+ . pipe ( LinkPathList :: many)
65+ . into_reflection ( ) ;
66+ let b = [ "4" , "0" , "3" , "2" , "1" ]
67+ . pipe ( LinkPathList :: many)
68+ . into_reflection ( ) ;
69+ let c = [ "0" , "1" , "2" , "3" , "4" ]
70+ . pipe ( LinkPathList :: many)
71+ . into_reflection ( ) ;
72+ assert_eq ! ( a, b) ;
73+ assert_eq ! ( b, c) ;
74+ assert_eq ! ( a, c) ;
75+ }
76+
77+ #[ test]
78+ fn item_absent_cause_inequality ( ) {
79+ let a = [ "0" , "1" , "2" , "3" ]
80+ . pipe ( LinkPathList :: many)
81+ . into_reflection ( ) ;
82+ let b = [ "0" , "1" , "2" , "3" , "4" ]
83+ . pipe ( LinkPathList :: many)
84+ . into_reflection ( ) ;
85+ assert_ne ! ( a, b) ;
86+ assert_ne ! ( b, a) ;
87+ }
88+
89+ #[ test]
90+ fn item_difference_cause_inequality ( ) {
91+ let a = [ "0" , "1" , "2" , "3" , "5" ]
92+ . pipe ( LinkPathList :: many)
93+ . into_reflection ( ) ;
94+ let b = [ "0" , "1" , "2" , "3" , "4" ]
95+ . pipe ( LinkPathList :: many)
96+ . into_reflection ( ) ;
97+ assert_ne ! ( a, b) ;
98+ assert_ne ! ( b, a) ;
99+ }
100+ }
0 commit comments