use super::*;
#[test]
fn test_01_slash() {
let cross_path = CrossPathBuf::new("test/path").expect("error");
assert_eq!(cross_path.as_str(), "test/path");
assert_eq!(cross_path.to_path_buf_nix().to_string_lossy(), "test/path");
assert_eq!(cross_path.to_path_buf_win().to_string_lossy(), "test/path");
}
#[test]
fn test_02_backslash() {
let cross_path = CrossPathBuf::new(r#"test\path"#).expect("error");
assert_eq!(cross_path.as_str(), "test/path");
assert_eq!(cross_path.to_path_buf_nix().to_string_lossy(), "test/path");
assert_eq!(cross_path.to_path_buf_win().to_string_lossy(), "test/path");
}
#[test]
fn test_03_c_drive_backslash() {
let cross_path = CrossPathBuf::new(r#"c:\test\path"#).expect("error");
assert_eq!(cross_path.as_str(), "/mnt/c/test/path");
assert_eq!(cross_path.to_path_buf_nix().to_string_lossy(), "/mnt/c/test/path");
assert_eq!(cross_path.to_path_buf_win().to_string_lossy(), "c:/test/path");
}
#[test]
fn test_03_c_drive_slash() {
let cross_path = CrossPathBuf::new(r#"c:/test/path"#).expect("error");
assert_eq!(cross_path.as_str(), "/mnt/c/test/path");
assert_eq!(cross_path.to_path_buf_nix().to_string_lossy(), "/mnt/c/test/path");
assert_eq!(cross_path.to_path_buf_win().to_string_lossy(), "c:/test/path");
}
#[test]
fn test_04_invalid_character() {
match CrossPathBuf::new(r#"c:\test:\path"#) {
Err(err) => assert_eq!(
err.to_string(),
r#"The string /mnt/c/test:/path contains an invalid windows path character < > : " | ? * "#
),
Ok(_path) => (),
}
}
#[test]
fn test_05_home() {
let cross_path = CrossPathBuf::new(r#"~/test/path"#).expect("error");
assert_eq!(cross_path.as_str(), "~/test/path");
assert_eq!(cross_path.to_path_buf_nix().to_string_lossy(), "/home/rustdevuser/test/path");
assert_eq!(cross_path.to_path_buf_win().to_string_lossy(), "/home/rustdevuser/test/path");
}
#[test]
fn test_06_join_relative() {
let cross_path = CrossPathBuf::new(r#"test/path"#).expect("error");
let cross_path = cross_path
.join_relative("foo/bar")
.expect("error")
.join_relative("foo2/bar2")
.expect("error");
assert_eq!(cross_path.as_str(), "test/path/foo/bar/foo2/bar2");
assert_eq!(cross_path.to_path_buf_nix().to_string_lossy(), "test/path/foo/bar/foo2/bar2");
assert_eq!(cross_path.to_path_buf_win().to_string_lossy(), "test/path/foo/bar/foo2/bar2");
}
#[test]
fn test_07_trim_add() {
let cross_path = CrossPathBuf::new(r#"test/path"#).expect("error");
let cross_path = cross_path.add_start_slash().expect("error").add_end_slash().expect("error");
assert_eq!(cross_path.as_str(), "/test/path/");
let cross_path = cross_path.trim_start_slash().expect("error").trim_end_slash().expect("error");
assert_eq!(cross_path.as_str(), "test/path");
}
#[test]
fn test_07_file_name() {
let cross_path = CrossPathBuf::new(r#"foo/bar.txt"#).expect("error");
assert_eq!(cross_path.file_name().expect("error"), "bar.txt");
assert_eq!(cross_path.file_stem().expect("error"), "bar");
assert_eq!(cross_path.extension().expect("error"), "txt");
let cross_path = CrossPathBuf::new(r#"foo/bar.txt"#).expect("error");
let cross_path = cross_path.replace_extension("md").expect("error");
assert_eq!(cross_path.file_name().expect("error"), "bar.md");
assert_eq!(cross_path.file_stem().expect("error"), "bar");
assert_eq!(cross_path.extension().expect("error"), "md");
let cross_path = CrossPathBuf::new(r#"foo/bar.txt"#).expect("error");
let cross_path = cross_path.add_extension("md").expect("error");
assert_eq!(cross_path.file_name().expect("error"), "bar.txt.md");
assert_eq!(cross_path.file_stem().expect("error"), "bar.txt");
assert_eq!(cross_path.extension().expect("error"), "md");
}