test: backfill edge cases for notify path helpers

Cover expand_tilde (bare ~, ~/sub, absolute, relative, non-leading tilde,
~user, whitespace) and validate_custom_path (empty/whitespace, missing,
existing file vs dir via CARGO_MANIFEST_DIR, tilde-prefixed missing).
Test-only; no production code or dependency changes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-01 04:35:50 -04:00
co-authored by Claude Opus 4.8
parent 215bb3cf38
commit 2c45a6fb3e
+28 -4
View File
@@ -170,18 +170,42 @@ mod tests {
#[test]
fn test_expand_tilde() {
if let Some(home) = dirs::home_dir() {
// bare `~` -> home dir
assert_eq!(expand_tilde("~"), home);
assert_eq!(expand_tilde("~/foo/bar.wav"), home.join("foo/bar.wav"));
// `~/sub/dir/file.wav` -> home joined with `sub/dir/file.wav`
assert_eq!(expand_tilde("~/sub/dir/file.wav"), home.join("sub/dir/file.wav"));
}
assert_eq!(expand_tilde("/absolute/path.wav"), PathBuf::from("/absolute/path.wav"));
assert_eq!(expand_tilde("relative/path.wav"), PathBuf::from("relative/path.wav"));
assert_eq!(expand_tilde(" "), PathBuf::from(""));
// absolute path (`/etc/foo.wav`) -> unchanged
assert_eq!(expand_tilde("/etc/foo.wav"), PathBuf::from("/etc/foo.wav"));
// relative path (`foo/bar.wav`) -> unchanged
assert_eq!(expand_tilde("foo/bar.wav"), PathBuf::from("foo/bar.wav"));
// a tilde not at the start (`/opt/~/x.wav`) -> unchanged
assert_eq!(expand_tilde("/opt/~/x.wav"), PathBuf::from("/opt/~/x.wav"));
// `~username` style (`~bob/x.wav`) -> unchanged
assert_eq!(expand_tilde("~bob/x.wav"), PathBuf::from("~bob/x.wav"));
// leading/trailing whitespace is trimmed
if let Some(home) = dirs::home_dir() {
assert_eq!(expand_tilde(" ~ "), home);
assert_eq!(expand_tilde(" ~/sub/dir/file.wav "), home.join("sub/dir/file.wav"));
}
assert_eq!(expand_tilde(" /etc/foo.wav "), PathBuf::from("/etc/foo.wav"));
assert_eq!(expand_tilde(" foo/bar.wav "), PathBuf::from("foo/bar.wav"));
}
#[test]
fn test_validate_custom_path() {
// empty and whitespace-only -> None
assert_eq!(validate_custom_path(""), None);
assert_eq!(validate_custom_path(" "), None);
// a path that does not exist -> Some(false)
assert_eq!(validate_custom_path("/non/existent/file.wav"), Some(false));
// a real existing file -> Some(true)
let existing_file = concat!(env!("CARGO_MANIFEST_DIR"), "/Cargo.toml");
assert_eq!(validate_custom_path(existing_file), Some(true));
// an existing directory -> Some(false)
let existing_dir = env!("CARGO_MANIFEST_DIR");
assert_eq!(validate_custom_path(existing_dir), Some(false));
// a `~`-prefixed path that resolves to a non-existent file -> Some(false)
assert_eq!(validate_custom_path("~/non/existent/file.wav"), Some(false));
}
}