- Extract mover and undo functionality into dedicated modules (mover/ and undo/ subdirectories) - Move cross-platform file operations to separate file_ops.rs module for reusability - Extract batch and categorizer tests into separate test files (batch_test.rs, categorizer_test.rs) - Refactor orchestrator.rs with extracted helper functions for improved readability - Separate cache and undo log initialization - Extract path resolution and offline mode determination logic - Simplify main organization flow by delegating to helper functions - Update module exports to expose new types and functions (MoveError, MoveSummary, UndoError, UndoSummary) - Reduce code duplication of move_file_cross_platform implementation
63 lines
2.4 KiB
Rust
63 lines
2.4 KiB
Rust
use super::*;
|
|
use std::fs::{self, File};
|
|
use std::path::Path;
|
|
|
|
#[test]
|
|
fn test_file_batch_from_path() {
|
|
let temp_dir = tempfile::tempdir().unwrap();
|
|
let dir_path = temp_dir.path();
|
|
|
|
File::create(dir_path.join("file1.txt")).unwrap();
|
|
File::create(dir_path.join("file2.rs")).unwrap();
|
|
fs::create_dir(dir_path.join("subdir")).unwrap();
|
|
|
|
let batch = FileBatch::from_path(dir_path, false);
|
|
assert_eq!(batch.count(), 2);
|
|
assert!(batch.filenames.contains(&"file1.txt".to_string()));
|
|
assert!(batch.filenames.contains(&"file2.rs".to_string()));
|
|
}
|
|
|
|
#[test]
|
|
fn test_file_batch_from_path_nonexistent() {
|
|
let batch = FileBatch::from_path(Path::new("/nonexistent/path"), false);
|
|
assert_eq!(batch.count(), 0);
|
|
}
|
|
|
|
#[test]
|
|
fn test_file_batch_from_path_non_recursive() {
|
|
let temp_dir = tempfile::tempdir().unwrap();
|
|
let dir_path = temp_dir.path();
|
|
File::create(dir_path.join("file1.txt")).unwrap();
|
|
File::create(dir_path.join("file2.rs")).unwrap();
|
|
fs::create_dir(dir_path.join("subdir")).unwrap();
|
|
File::create(dir_path.join("subdir").join("file3.txt")).unwrap();
|
|
let batch = FileBatch::from_path(dir_path, false);
|
|
assert_eq!(batch.count(), 2);
|
|
assert!(batch.filenames.contains(&"file1.txt".to_string()));
|
|
assert!(batch.filenames.contains(&"file2.rs".to_string()));
|
|
assert!(!batch.filenames.contains(&"subdir/file3.txt".to_string()));
|
|
}
|
|
|
|
#[test]
|
|
fn test_file_batch_from_path_recursive() {
|
|
let temp_dir = tempfile::tempdir().unwrap();
|
|
let dir_path = temp_dir.path();
|
|
File::create(dir_path.join("file1.txt")).unwrap();
|
|
fs::create_dir(dir_path.join("subdir1")).unwrap();
|
|
File::create(dir_path.join("subdir1").join("file2.rs")).unwrap();
|
|
fs::create_dir(dir_path.join("subdir1").join("nested")).unwrap();
|
|
File::create(dir_path.join("subdir1").join("nested").join("file3.md")).unwrap();
|
|
fs::create_dir(dir_path.join("subdir2")).unwrap();
|
|
File::create(dir_path.join("subdir2").join("file4.py")).unwrap();
|
|
let batch = FileBatch::from_path(dir_path, true);
|
|
assert_eq!(batch.count(), 4);
|
|
assert!(batch.filenames.contains(&"file1.txt".to_string()));
|
|
assert!(batch.filenames.contains(&"subdir1/file2.rs".to_string()));
|
|
assert!(
|
|
batch
|
|
.filenames
|
|
.contains(&"subdir1/nested/file3.md".to_string())
|
|
);
|
|
assert!(batch.filenames.contains(&"subdir2/file4.py".to_string()));
|
|
}
|