use std::path::PathBuf;
fn compute_test_destination(source: &msy::path::SyncPath, dest: &msy::path::SyncPath) -> PathBuf {
let source_path = source.path();
if source.has_trailing_slash() {
return dest.path().to_path_buf();
}
if let Some(dir_name) = source_path.file_name() {
dest.path().join(dir_name)
} else {
dest.path().to_path_buf()
}
}
#[test]
fn test_syncpath_trailing_slash_detection() {
let path_without = msy::path::SyncPath::parse("/home/user/mydir");
assert!(!path_without.has_trailing_slash(), "/home/user/mydir should NOT have trailing slash");
let path_with = msy::path::SyncPath::parse("/home/user/mydir/");
assert!(path_with.has_trailing_slash(), "/home/user/mydir/ should have trailing slash");
let remote_without = msy::path::SyncPath::parse("user@host:/path/to/dir");
assert!(!remote_without.has_trailing_slash(), "user@host:/path/to/dir should NOT have trailing slash");
let remote_with = msy::path::SyncPath::parse("user@host:/path/to/dir/");
assert!(remote_with.has_trailing_slash(), "user@host:/path/to/dir/ should have trailing slash");
let windows_without = msy::path::SyncPath::parse("C:\\Users\\name\\dir");
assert!(!windows_without.has_trailing_slash(), "C:\\Users\\name\\dir should NOT have trailing slash");
let windows_with = msy::path::SyncPath::parse("C:\\Users\\name\\dir\\");
assert!(windows_with.has_trailing_slash(), "C:\\Users\\name\\dir\\ should have trailing slash");
}
#[test]
fn test_destination_computation_without_trailing_slash() {
let source = msy::path::SyncPath::parse("/a/myproject");
let dest = msy::path::SyncPath::parse("/target");
let effective_dest = compute_test_destination(&source, &dest);
assert_eq!(effective_dest, PathBuf::from("/target/myproject"));
}
#[test]
fn test_destination_computation_with_trailing_slash() {
let source = msy::path::SyncPath::parse("/a/myproject/");
let dest = msy::path::SyncPath::parse("/target");
let effective_dest = compute_test_destination(&source, &dest);
assert_eq!(effective_dest, PathBuf::from("/target"));
}
#[test]
fn test_remote_destination_computation_without_trailing_slash() {
let source = msy::path::SyncPath::parse("user@host:/a/myproject");
let dest = msy::path::SyncPath::parse("/target");
assert!(!source.has_trailing_slash());
let effective_dest = compute_test_destination(&source, &dest);
assert_eq!(effective_dest, PathBuf::from("/target/myproject"));
}
#[test]
fn test_remote_destination_computation_with_trailing_slash() {
let source = msy::path::SyncPath::parse("user@host:/a/myproject/");
let dest = msy::path::SyncPath::parse("/target");
assert!(source.has_trailing_slash());
let effective_dest = compute_test_destination(&source, &dest);
assert_eq!(effective_dest, PathBuf::from("/target"));
}