use k9::assert_equal;
use iocore::{
expand_home_regex, path_str_to_relative_subpath, remove_duplicate_separators, remove_end,
remove_equal_prefix_from_path_strings, remove_redundant_current_path, remove_start,
remove_trailing_slash, repl_beg, repl_end, split_str_into_relative_subpath_parts,
};
#[test]
fn test_remove_start() {
assert_equal!(remove_start("a/b/c/", "a/b/c/x/y/z.bin"), "x/y/z.bin");
assert_equal!(repl_beg("a/b/c/", "a/b/c/x/y/z.bin", ""), "x/y/z.bin");
}
#[test]
fn test_remove_end() {
assert_equal!(remove_end("x/y/z.bin", "a/b/c/x/y/z.bin"), "a/b/c/");
assert_equal!(repl_end("x/y/z.bin", "a/b/c/x/y/z.bin", ""), "a/b/c/");
}
#[test]
fn test_remove_equal_prefix_from_path_strings() {
assert_eq!(
remove_equal_prefix_from_path_strings(
"/absolute/path/to/a/b/c/x/y/z.bin",
"/absolute/path/to/a/b/c",
),
("x/y/z.bin".to_string(), "".to_string()),
);
assert_eq!(
remove_equal_prefix_from_path_strings(
"/absolute/path/to/a/b/c",
"/absolute/path/to/a/b/c/x/y/z.bin",
),
("".to_string(), "x/y/z.bin".to_string())
);
assert_eq!(
remove_equal_prefix_from_path_strings(
"relative/path/to/a/b/c/x/y/z.bin",
"relative/path/to/a/b/c",
),
("x/y/z.bin".to_string(), "".to_string())
);
assert_eq!(
remove_equal_prefix_from_path_strings(
"relative/path/to/a/b/c",
"relative/path/to/a/b/c/x/y/z.bin",
),
("".to_string(), "x/y/z.bin".to_string()),
);
}
#[test]
fn test_remove_trailing_slash() {
assert_equal!(remove_trailing_slash("a/b/c/"), "a/b/c");
}
#[test]
fn test_remove_duplicate_separators() {
assert_equal!(remove_duplicate_separators("a//b//c/"), "a/b/c/");
}
#[test]
fn test_expand_home_regex() {
assert_equal!(expand_home_regex("~baz", "/foo/"), "~baz");
assert_equal!(expand_home_regex("~/baz", "/foo/"), "/foo/baz");
assert_equal!(expand_home_regex("~", "/foo/"), "/foo/");
assert_equal!(expand_home_regex("~~", "/foo/"), "~~");
}
#[test]
fn test_split_str_into_relative_subpath_parts() {
assert_equal!(split_str_into_relative_subpath_parts("a/b/c/"), vec!["..", "..", ".."]);
}
#[test]
fn test_path_str_to_relative_subpath() {
assert_equal!(path_str_to_relative_subpath("a/b/c"), "../../../");
}
#[test]
fn test_repl_beg() {
assert_equal!(repl_beg("a/b/c/", "a/b/c/x/y/z.bin", ""), "x/y/z.bin");
}
#[test]
fn test_repl_end() {
assert_equal!(repl_end("x/y/z.bin", "a/b/c/x/y/z.bin", ""), "a/b/c/");
}
#[test]
fn test_remove_redundant_current_path() {
assert_equal!(remove_redundant_current_path("a/./b/./c/"), "a/b/c/");
}