ImageLoader: load image info (dimensions, format, file size) and pixels. Discovery: find image files by extension, flat or recursive, single file or directory. All 9 tests passing.
53 lines
1.5 KiB
Rust
53 lines
1.5 KiB
Rust
use pixstrip_core::discovery::discover_images;
|
|
use std::fs;
|
|
|
|
fn create_test_tree(root: &std::path::Path) {
|
|
fs::create_dir_all(root.join("subdir")).unwrap();
|
|
fs::write(root.join("photo1.jpg"), b"fake jpeg").unwrap();
|
|
fs::write(root.join("photo2.png"), b"fake png").unwrap();
|
|
fs::write(root.join("readme.txt"), b"not an image").unwrap();
|
|
fs::write(root.join("subdir/nested.webp"), b"fake webp").unwrap();
|
|
fs::write(root.join("subdir/doc.pdf"), b"not an image").unwrap();
|
|
}
|
|
|
|
#[test]
|
|
fn discover_flat() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
create_test_tree(dir.path());
|
|
|
|
let images = discover_images(dir.path(), false);
|
|
assert_eq!(images.len(), 2);
|
|
let names: Vec<String> = images
|
|
.iter()
|
|
.map(|p| p.file_name().unwrap().to_string_lossy().into_owned())
|
|
.collect();
|
|
assert!(names.contains(&"photo1.jpg".to_string()));
|
|
assert!(names.contains(&"photo2.png".to_string()));
|
|
}
|
|
|
|
#[test]
|
|
fn discover_recursive() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
create_test_tree(dir.path());
|
|
|
|
let images = discover_images(dir.path(), true);
|
|
assert_eq!(images.len(), 3);
|
|
}
|
|
|
|
#[test]
|
|
fn discover_empty_dir() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let images = discover_images(dir.path(), true);
|
|
assert!(images.is_empty());
|
|
}
|
|
|
|
#[test]
|
|
fn discover_single_file() {
|
|
let dir = tempfile::tempdir().unwrap();
|
|
let path = dir.path().join("single.jpg");
|
|
fs::write(&path, b"fake jpeg").unwrap();
|
|
|
|
let images = discover_images(&path, false);
|
|
assert_eq!(images.len(), 1);
|
|
}
|