iocore 3.1.0

IOCore is a safe library for unix CLI tools and Systems programming. IOCore provides the [`iocore::Path`] abstraction of file-system paths designed to replace most [`std::path`] and [`std::fs`] operations with practical methods, other abstractions include: - handling file-system permissions via [`iocore::PathPermissions`] powered by the crate [`trilobyte`]. - handling file-system timestamps via [`iocore::PathTimestamps`] granularly via [`iocore::PathDateTime`]. IOCore provides the [`iocore::walk_dir`] function and its companion trait [`iocore::WalkProgressHandler`] which traverses file-systems quickly via threads. IOcore provides [`iocore::User`] which provides unix user information such as uid, path to home etc. The module [`iocore::env`] provides [`iocore::env:args`] returns a [`Vec<String>`] from [`std::env:args`], and [`iocore::env:var`] that returns environment variables as string.
Documentation
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/");
}