@@ -42,6 +42,28 @@ fn special_cases_around_cwd() -> crate::Result {
42
42
"absolute CWDs are always shortened…"
43
43
) ;
44
44
assert_eq ! ( normalize( p( "./a/.." ) , & cwd) . unwrap( ) , p( "." ) , "…like this as well…" ) ;
45
+ assert_eq ! (
46
+ normalize( & cwd, & cwd) . unwrap( ) ,
47
+ cwd,
48
+ "…but only if there were relative to begin with."
49
+ ) ;
50
+ assert_eq ! (
51
+ normalize( p( "." ) , & cwd) . unwrap( ) ,
52
+ p( "." ) ,
53
+ "and this means that `.`. stays `.`"
54
+ ) ;
55
+ {
56
+ let mut path = cwd. clone ( ) ;
57
+ let last_component = path. file_name ( ) . expect ( "directory" ) . to_owned ( ) ;
58
+ path. push ( ".." ) ;
59
+ path. push ( last_component) ;
60
+
61
+ assert_eq ! (
62
+ normalize( path, & cwd) . unwrap( ) ,
63
+ cwd,
64
+ "absolute input paths stay absolute"
65
+ ) ;
66
+ }
45
67
Ok ( ( ) )
46
68
}
47
69
@@ -53,6 +75,18 @@ fn parent_dirs_cause_the_cwd_to_be_used() {
53
75
) ;
54
76
}
55
77
78
+ #[ test]
79
+ fn multiple_parent_dir_movements_eat_into_the_current_dir ( ) {
80
+ assert_eq ! (
81
+ normalize( p( "../../../d/e" ) , "/users/name/a/b/c" ) . unwrap( ) . as_ref( ) ,
82
+ p( "/users/name/d/e" )
83
+ ) ;
84
+ assert_eq ! (
85
+ normalize( p( "c/../../../d/e" ) , "/users/name/a/b" ) . unwrap( ) . as_ref( ) ,
86
+ p( "/users/name/d/e" )
87
+ ) ;
88
+ }
89
+
56
90
#[ test]
57
91
fn walking_up_too_much_yield_none ( ) {
58
92
let cwd = "/users/name" ;
@@ -71,14 +105,15 @@ fn trailing_directories_after_too_numereous_parent_dirs_yield_none() {
71
105
72
106
#[ test]
73
107
fn trailing_relative_components_are_resolved ( ) {
74
- let cwd = std :: env :: current_dir ( ) . unwrap ( ) ;
108
+ let cwd = Path :: new ( "/a/b/c" ) ;
75
109
for ( input, expected) in [
76
110
( "./a/b/./c/../d/.." , "./a/b" ) ,
77
111
( "a/./b/c/.././.." , "a" ) ,
78
112
( "/a/b/c/.././../." , "/a" ) ,
79
113
( "./a/.." , "." ) ,
80
114
( "a/.." , "." ) ,
81
115
( "./a" , "./a" ) ,
116
+ ( "./a/./b" , "./a/./b" ) ,
82
117
( "./a/./b/.." , "./a/." ) ,
83
118
( "/a/./b/c/.././../." , "/a" ) ,
84
119
( "/a/./b" , "/a/./b" ) ,
@@ -90,7 +125,7 @@ fn trailing_relative_components_are_resolved() {
90
125
] {
91
126
let path = p ( input) ;
92
127
assert_eq ! (
93
- normalize( path, & cwd) . unwrap_or_else( || panic!( "{path:?}" ) ) ,
128
+ normalize( path, cwd) . unwrap_or_else( || panic!( "{path:?}" ) ) ,
94
129
Cow :: Borrowed ( p( expected) ) ,
95
130
"'{}' got an unexpected result" ,
96
131
input
0 commit comments