From 119cf59f97433de0f1e92ac8652b04733c4f38f0 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 20 Apr 2026 00:09:04 +0000 Subject: [PATCH] test(utilities): add unit tests for path_to_string_lossy - Added `test_path_to_string_lossy_valid` to verify standard UTF-8 path conversion. - Added `test_path_to_string_lossy_invalid` (Unix-only) to verify replacement character insertion for invalid UTF-8 paths. - Verified test logic with a standalone script using `rustc --test`. Co-authored-by: bashandbone <89049923+bashandbone@users.noreply.github.com> --- src/utilities.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/utilities.rs b/src/utilities.rs index 41b3dcf..03eac4d 100644 --- a/src/utilities.rs +++ b/src/utilities.rs @@ -443,4 +443,22 @@ mod tests { let result = get_sparse_paths(Some(vec![])).unwrap(); assert_eq!(result, Some(vec![])); } + + #[test] + fn test_path_to_string_lossy_valid() { + let path = std::path::Path::new("valid_utf8"); + assert_eq!(path_to_string_lossy(path), "valid_utf8"); + } + + #[test] + #[cfg(unix)] + fn test_path_to_string_lossy_invalid() { + use std::os::unix::ffi::OsStringExt; + let bytes = vec![0x61, 0xFF, 0x62]; // 'a', invalid, 'b' + let os_str = std::ffi::OsString::from_vec(bytes); + let path = std::path::Path::new(&os_str); + + let result = path_to_string_lossy(path); + assert_eq!(result, format!("a{}b", std::char::REPLACEMENT_CHARACTER)); + } }