@@ -37,12 +37,12 @@ fn path_join_handling() {
3737 let absolute = p ( "/absolute" ) ;
3838 assert ! (
3939 absolute. is_relative( ) ,
40- "on Windows, absolute linux paths are considered relative"
40+ "on Windows, absolute Linux paths are considered relative (and relative to the current drive) "
4141 ) ;
4242 let bs_absolute = p ( "\\ absolute" ) ;
4343 assert ! (
4444 absolute. is_relative( ) ,
45- "on Windows, strange single-backslash paths are relative"
45+ "on Windows, strange single-backslash paths are relative (and relative to the current drive) "
4646 ) ;
4747 assert_eq ! (
4848 p( "relative" ) . join( absolute) ,
@@ -58,7 +58,7 @@ fn path_join_handling() {
5858 assert_eq ! (
5959 p( "c:" ) . join( "relative" ) ,
6060 p( "c:relative" ) ,
61- "absolute + relative = strange joined result with missing slash - but that shouldn't usually happen "
61+ "absolute + relative = strange joined result with missing back- slash, but it's a valid path that works just like `c: \r elative` "
6262 ) ;
6363 assert_eq ! (
6464 p( "c:\\ " ) . join( "relative" ) ,
@@ -69,34 +69,52 @@ fn path_join_handling() {
6969 assert_eq ! (
7070 p( "\\ \\ ?\\ base" ) . join( absolute) ,
7171 p( "\\ \\ ?\\ base\\ absolute" ) ,
72- "absolute1 + absolute2 = joined result with backslash"
72+ "absolute1 + unix-absolute2 = joined result with backslash"
73+ ) ;
74+ assert_eq ! (
75+ p( "\\ \\ .\\ base" ) . join( absolute) ,
76+ p( "\\ \\ .\\ base\\ absolute" ) ,
77+ "absolute1 + absolute2 = joined result with backslash (device relative)"
7378 ) ;
7479 assert_eq ! (
7580 p( "\\ \\ ?\\ base" ) . join( bs_absolute) ,
7681 p( "\\ \\ ?\\ base\\ absolute" ) ,
7782 "absolute1 + absolute2 = joined result"
7883 ) ;
84+ assert_eq ! (
85+ p( "\\ \\ .\\ base" ) . join( bs_absolute) ,
86+ p( "\\ \\ .\\ base\\ absolute" ) ,
87+ "absolute1 + absolute2 = joined result (device relative)"
88+ ) ;
7989
90+ assert_eq ! ( p( "/" ) . join( "C:" ) , p( "C:" ) , "unix-absolute + win-drive = win-drive" ) ;
8091 assert_eq ! (
81- p( "/" ) . join( "C:" ) ,
92+ p( "d: /" ) . join( "C:" ) ,
8293 p( "C:" ) ,
83- "unix-absolute + win-absolute = win-absolute "
94+ "d-drive + c-drive = c-drive - interesting, as C: is supposed to be relative "
8495 ) ;
8596 assert_eq ! (
86- p( "/ " ) . join( "C:/ " ) ,
97+ p( "d: \\ " ) . join( "C:\\ " ) ,
8798 p( "C:\\ " ) ,
88- "unix-absolute + win-absolute = win-result, strangely enough it changed the trailing slash to backslash, so better not have trailing slashes "
99+ "d-drive-with-bs + c-drive-with-bs = c-drive-with-bs - nothing special happens with backslashes "
89100 ) ;
90101 assert_eq ! (
91- p( "/" ) . join( "C:\\ " ) ,
102+ p( "c:\\ " ) . join( "\\ \\ .\\ " ) ,
103+ p( "\\ \\ .\\ " ) ,
104+ "d-drive-with-bs + device-relative-unc = device-relative-unc"
105+ ) ;
106+ assert_eq ! (
107+ p( "/" ) . join( "C:/" ) ,
92108 p( "C:\\ " ) ,
93- "unix-absolute + win-absolute = win-result "
109+ "unix-absolute + win-drive = win-drive, strangely enough it changed the trailing slash to backslash, so better not have trailing slashes "
94110 ) ;
111+ assert_eq ! ( p( "/" ) . join( "C:\\ " ) , p( "C:\\ " ) , "unix-absolute + win-drive = win-drive" ) ;
95112 assert_eq ! (
96- p( "relative " ) . join( "C:" ) ,
113+ p( "\\ \\ . " ) . join( "C:" ) ,
97114 p( "C:" ) ,
98- "relative + win-absolute = win-result "
115+ "device- relative-unc + win-drive-relative = win-drive-relative - c: was supposed to be relative, but it's not acting like it. "
99116 ) ;
117+ assert_eq ! ( p( "relative" ) . join( "C:" ) , p( "C:" ) , "relative + win-drive = win-drive" ) ;
100118
101119 assert_eq ! (
102120 p( "/" ) . join( "\\ \\ localhost" ) ,
@@ -202,6 +220,17 @@ fn relative_components_are_invalid() {
202220 if cfg!( windows) { ".\\ a\\ b" } else { "./a/b" } ,
203221 "dot is silently ignored"
204222 ) ;
223+ s. make_relative_path_current ( "a//b/" . as_ref ( ) , & mut r)
224+ . expect ( "multiple-slashes are ignored" ) ;
225+ assert_eq ! (
226+ r,
227+ Record {
228+ push_dir: 2 ,
229+ dirs: vec![ "." . into( ) , "./a" . into( ) ] ,
230+ push: 2 ,
231+ } ,
232+ "nothing changed"
233+ ) ;
205234}
206235
207236#[ test]
@@ -226,7 +255,7 @@ fn absolute_paths_are_invalid() -> crate::Result {
226255 assert_eq ! (
227256 s. current( ) ,
228257 p( "./b\\ " ) ,
229- "trailing back-slashes are fine both on Windows and unix - on Unix it's part fo the filename"
258+ "trailing backslashes are fine both on Windows and Unix - on Unix it's part fo the filename"
230259 ) ;
231260
232261 #[ cfg( windows) ]
@@ -235,22 +264,28 @@ fn absolute_paths_are_invalid() -> crate::Result {
235264 assert_eq ! (
236265 err. to_string( ) ,
237266 "Input path \" \\ \" contains relative or absolute components" ,
238- "on windows , backslashes are considered absolute and replace the base if it is relative, \
267+ "on Windows , backslashes are considered absolute and replace the base if it is relative, \
239268 hence they are forbidden."
240269 ) ;
241270
242271 let err = s. make_relative_path_current ( "c:" . as_ref ( ) , & mut r) . unwrap_err ( ) ;
243272 assert_eq ! (
244273 err. to_string( ) ,
245274 "Input path \" c:\" contains relative or absolute components" ,
246- "on windows, drive-letters are also absolute"
275+ "on Windows, drive-letters without trailing backslash or slash are also absolute (even though they ought to be relative)"
276+ ) ;
277+ let err = s. make_relative_path_current ( "c:\\ " . as_ref ( ) , & mut r) . unwrap_err ( ) ;
278+ assert_eq ! (
279+ err. to_string( ) ,
280+ "Input path \" c:\\ \" contains relative or absolute components" ,
281+ "on Windows, drive-letters are absolute, which is expected"
247282 ) ;
248283
249284 s. make_relative_path_current ( "֍:" . as_ref ( ) , & mut r) ?;
250285 assert_eq ! (
251286 s. current( ) . to_string_lossy( ) ,
252287 ".\\ ֍:" ,
253- "on windows, any unicode character will do as virtual drive-letter actually with `subst`, \
288+ "on Windows, almost any unicode character will do as virtual drive-letter actually with `subst`, \
254289 but we just turn it into a presumably invalid path which is fine, i.e. we get a joined path"
255290 ) ;
256291 let err = s
@@ -440,7 +475,7 @@ fn delegate_calls_are_consistent() -> crate::Result {
440475 dirs: dirs. clone( ) ,
441476 push: 19 ,
442477 } ,
443- "a backslash is a normal character outside of windows , so it's fine to have it as component"
478+ "a backslash is a normal character outside of Windows , so it's fine to have it as component"
444479 ) ;
445480
446481 s. make_relative_path_current ( "\\ " . as_ref ( ) , & mut r) ?;
0 commit comments