-
Notifications
You must be signed in to change notification settings - Fork 1
π§ͺ Add unit tests for path_to_string_lossy utility #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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); | ||||||||||
|
Comment on lines
+458
to
+459
|
||||||||||
| let os_str = std::ffi::OsString::from_vec(bytes); | |
| let path = std::path::Path::new(&os_str); | |
| let os_string = std::ffi::OsString::from_vec(bytes); | |
| let path = std::path::Path::new(&os_string); |
Copilot
AI
Apr 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assertion builds the expected string with format!, which allocates unnecessarily in a tight unit test. Prefer comparing against a literal like "a\u{FFFD}b" (or otherwise constructing the expected String without formatting) to keep the test simpler and allocation-free.
| assert_eq!(result, format!("a{}b", std::char::REPLACEMENT_CHARACTER)); | |
| assert_eq!(result, "a\u{FFFD}b"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
path_to_string_lossy()currently always prints the "non-UTF-8" warning viaeprintln!even when the input path is valid UTF-8. This new test will therefore emit a misleading warning (and adds noise when running tests with--nocapture). Consider changingpath_to_string_lossyto only warn when the conversion is actually lossy (e.g., whento_string_lossy()returns an ownedCow, or whenpath.to_str()isNone).