@@ -856,9 +856,43 @@ fn exclude_from_time_machine(path: &Path) {
856
856
#[ cfg( test) ]
857
857
mod tests {
858
858
use super :: join_paths;
859
+ use super :: normalize_path;
859
860
use super :: write;
860
861
use super :: write_atomic;
861
862
863
+ #[ test]
864
+ fn test_normalize_path ( ) {
865
+ let cases = & [
866
+ ( "" , "" ) ,
867
+ ( "." , "" ) ,
868
+ ( ".////./." , "" ) ,
869
+ ( "/" , "/" ) ,
870
+ ( "/.." , "/" ) ,
871
+ ( "/foo/bar" , "/foo/bar" ) ,
872
+ ( "/foo/bar/" , "/foo/bar" ) ,
873
+ ( "/foo/bar/./././///" , "/foo/bar" ) ,
874
+ ( "/foo/bar/.." , "/foo" ) ,
875
+ ( "/foo/bar/../.." , "/" ) ,
876
+ ( "/foo/bar/../../.." , "/" ) ,
877
+ ( "foo/bar" , "foo/bar" ) ,
878
+ ( "foo/bar/" , "foo/bar" ) ,
879
+ ( "foo/bar/./././///" , "foo/bar" ) ,
880
+ ( "foo/bar/.." , "foo" ) ,
881
+ ( "foo/bar/../.." , "" ) ,
882
+ ( "foo/bar/../../.." , "" ) ,
883
+ ( "../../foo/bar" , "foo/bar" ) ,
884
+ ( "../../foo/bar/" , "foo/bar" ) ,
885
+ ( "../../foo/bar/./././///" , "foo/bar" ) ,
886
+ ( "../../foo/bar/.." , "foo" ) ,
887
+ ( "../../foo/bar/../.." , "" ) ,
888
+ ( "../../foo/bar/../../.." , "" ) ,
889
+ ] ;
890
+ for ( input, expected) in cases {
891
+ let actual = normalize_path ( std:: path:: Path :: new ( input) ) ;
892
+ assert_eq ! ( actual, std:: path:: Path :: new( expected) , "input: {input}" ) ;
893
+ }
894
+ }
895
+
862
896
#[ test]
863
897
fn write_works ( ) {
864
898
let original_contents = "[dependencies]\n foo = 0.1.0" ;
0 commit comments