Skip to content

Commit 1d17390

Browse files
committed
Add tests for path prefix normalization
1 parent bc947f4 commit 1d17390

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/util.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,3 +412,39 @@ pub fn to_lowercase(s: impl AsRef<str>) -> String {
412412
s.to_lowercase()
413413
}
414414
}
415+
416+
#[cfg(test)]
417+
#[cfg(windows)]
418+
mod tests_win {
419+
use std::path::PathBuf;
420+
421+
use rstest::rstest;
422+
423+
#[rstest]
424+
#[case(r"c:\", r"C:\")]
425+
#[case(r"C:\", r"C:\")]
426+
#[case(r"c:\\.", r"C:\")]
427+
#[case(r"c:\..", r"C:\")]
428+
#[case(r"C:\.\.", r"C:\")]
429+
#[case(r"\\?\C:\", r"C:\")]
430+
#[case(r"\\?\c:\", r"C:\")]
431+
#[case(r"\\?\C:\\\", r"C:\")]
432+
#[case(r"\\?\c:\\.\", r"C:\")]
433+
#[case(r"c:\Windows", r"C:\Windows")]
434+
#[case(r"C:\WINDOWS", r"C:\WINDOWS")]
435+
#[case(r"c:\\\Windows\.", r"C:\Windows")]
436+
#[case(r"C:\$WinREAgent", r"C:\$WinREAgent")]
437+
#[case(r"\\?\c:\\Windows\\.", r"C:\Windows")]
438+
#[case(r"\\?\c:\..\.\windows", r"C:\windows")]
439+
#[case(r"c:\Windows\System32\.", r"C:\Windows\System32")]
440+
#[case(r"c:\WINDOWS\..\..\Windows", r"C:\Windows")]
441+
#[case(r"c:\Windows\..\.\.\..\Temp\..\tmp", r"C:\tmp")]
442+
#[case(r"c:\.\Windows\..\..\Program Files", r"C:\Program Files")]
443+
#[case(r"\\?\C:\\$WinREAgent\\..\Program Files\.", r"C:\Program Files")]
444+
fn resolve_path(#[case] absolute_path: &str, #[case] normalized_form: &str) {
445+
let path = PathBuf::from(absolute_path);
446+
let resolved_path = super::resolve_path(path).unwrap();
447+
assert_eq!(resolved_path.to_str().unwrap(), normalized_form);
448+
}
449+
450+
}

0 commit comments

Comments
 (0)