test: add unified probe unit tests (8 Rust + 6 Python), fix pre-existing test compilation errors
This commit is contained in:
@@ -1,6 +1,75 @@
|
||||
use std::path::Path;
|
||||
use std::time::SystemTime;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::fs;
|
||||
|
||||
#[test]
|
||||
fn test_detect_category_video() {
|
||||
assert_eq!(detect_category(Path::new("video.mp4")), FileCategory::Video);
|
||||
assert_eq!(detect_category(Path::new("video.mov")), FileCategory::Video);
|
||||
assert_eq!(detect_category(Path::new("video.mkv")), FileCategory::Video);
|
||||
assert_eq!(detect_category(Path::new("video.avi")), FileCategory::Video);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_detect_category_image() {
|
||||
assert_eq!(detect_category(Path::new("photo.jpg")), FileCategory::Image);
|
||||
assert_eq!(detect_category(Path::new("photo.jpeg")), FileCategory::Image);
|
||||
assert_eq!(detect_category(Path::new("photo.png")), FileCategory::Image);
|
||||
assert_eq!(detect_category(Path::new("photo.svg")), FileCategory::Image);
|
||||
assert_eq!(detect_category(Path::new("photo.webp")), FileCategory::Image);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_detect_category_document() {
|
||||
assert_eq!(detect_category(Path::new("doc.pdf")), FileCategory::Document);
|
||||
assert_eq!(detect_category(Path::new("doc.docx")), FileCategory::Document);
|
||||
assert_eq!(detect_category(Path::new("doc.pages")), FileCategory::Document);
|
||||
assert_eq!(detect_category(Path::new("doc.txt")), FileCategory::Document);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_detect_category_spreadsheet() {
|
||||
assert_eq!(detect_category(Path::new("data.xlsx")), FileCategory::Spreadsheet);
|
||||
assert_eq!(detect_category(Path::new("data.csv")), FileCategory::Spreadsheet);
|
||||
assert_eq!(detect_category(Path::new("data.numbers")), FileCategory::Spreadsheet);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_detect_category_presentation() {
|
||||
assert_eq!(detect_category(Path::new("deck.pptx")), FileCategory::Presentation);
|
||||
assert_eq!(detect_category(Path::new("deck.key")), FileCategory::Presentation);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_detect_category_archive() {
|
||||
assert_eq!(detect_category(Path::new("files.zip")), FileCategory::Archive);
|
||||
assert_eq!(detect_category(Path::new("files.tar.gz")), FileCategory::Archive);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_detect_category_unknown() {
|
||||
assert_eq!(detect_category(Path::new("file.xyz")), FileCategory::Unknown);
|
||||
assert_eq!(detect_category(Path::new("file")), FileCategory::Unknown);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_base_format_info() {
|
||||
// Create a temp file and verify base_format_info returns correct fields
|
||||
let tmp = std::env::temp_dir().join("_test_unified_probe.txt");
|
||||
fs::write(&tmp, b"hello probe").unwrap();
|
||||
let info = base_format_info(&tmp);
|
||||
assert_eq!(info["file_type"], "document");
|
||||
assert_eq!(info["format_name"], "txt");
|
||||
assert!(!info["size"].as_str().unwrap_or("").is_empty());
|
||||
assert!(!info["mtime"].as_str().unwrap_or("").is_empty());
|
||||
let _ = fs::remove_file(&tmp);
|
||||
}
|
||||
}
|
||||
|
||||
/// File category derived from extension
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum FileCategory {
|
||||
|
||||
Reference in New Issue
Block a user