Skip to content

Commit 1f8b294

Browse files
committed
test(util): Show relative path behavior for normalize_path
1 parent 497c228 commit 1f8b294

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

crates/cargo-util/src/paths.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,9 +856,43 @@ fn exclude_from_time_machine(path: &Path) {
856856
#[cfg(test)]
857857
mod tests {
858858
use super::join_paths;
859+
use super::normalize_path;
859860
use super::write;
860861
use super::write_atomic;
861862

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+
862896
#[test]
863897
fn write_works() {
864898
let original_contents = "[dependencies]\nfoo = 0.1.0";

0 commit comments

Comments
 (0)