Add Insights Model Discovery and Fallback Handling
This commit is contained in:
83
src/utils.rs
Normal file
83
src/utils.rs
Normal file
@@ -0,0 +1,83 @@
|
||||
/// Normalize a file path to use forward slashes for cross-platform consistency
|
||||
/// This ensures paths stored in the database always use `/` regardless of OS
|
||||
///
|
||||
/// # Examples
|
||||
/// ```
|
||||
/// use image_api::utils::normalize_path;
|
||||
///
|
||||
/// assert_eq!(normalize_path("foo\\bar\\baz.jpg"), "foo/bar/baz.jpg");
|
||||
/// assert_eq!(normalize_path("foo/bar/baz.jpg"), "foo/bar/baz.jpg");
|
||||
/// ```
|
||||
pub fn normalize_path(path: &str) -> String {
|
||||
path.replace('\\', "/")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_normalize_path_with_backslashes() {
|
||||
assert_eq!(normalize_path("foo\\bar\\baz.jpg"), "foo/bar/baz.jpg");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_normalize_path_with_forward_slashes() {
|
||||
assert_eq!(normalize_path("foo/bar/baz.jpg"), "foo/bar/baz.jpg");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_normalize_path_mixed() {
|
||||
assert_eq!(
|
||||
normalize_path("foo\\bar/baz\\qux.jpg"),
|
||||
"foo/bar/baz/qux.jpg"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_normalize_path_empty() {
|
||||
assert_eq!(normalize_path(""), "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_normalize_path_absolute_windows() {
|
||||
assert_eq!(
|
||||
normalize_path("C:\\Users\\Photos\\image.jpg"),
|
||||
"C:/Users/Photos/image.jpg"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_normalize_path_unc_path() {
|
||||
assert_eq!(
|
||||
normalize_path("\\\\server\\share\\folder\\file.jpg"),
|
||||
"//server/share/folder/file.jpg"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_normalize_path_single_filename() {
|
||||
assert_eq!(normalize_path("image.jpg"), "image.jpg");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_normalize_path_trailing_slash() {
|
||||
assert_eq!(normalize_path("foo\\bar\\"), "foo/bar/");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_normalize_path_multiple_consecutive_backslashes() {
|
||||
assert_eq!(
|
||||
normalize_path("foo\\\\bar\\\\\\baz.jpg"),
|
||||
"foo//bar///baz.jpg"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_normalize_path_deep_nesting() {
|
||||
assert_eq!(
|
||||
normalize_path("a\\b\\c\\d\\e\\f\\g\\file.jpg"),
|
||||
"a/b/c/d/e/f/g/file.jpg"
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user