use std::fs;
use tempfile::TempDir;
use wlk::{Config, Repository};
#[test]
fn test_config_get_set() {
let temp_dir = TempDir::new().unwrap();
let _repo = Repository::init(temp_dir.path()).unwrap();
let wlk_root = temp_dir.path().join(".wlk");
let mut config = Config::load(&wlk_root).unwrap();
config.set("user.name", "Test User").unwrap();
config.set("user.email", "test@example.com").unwrap();
config.save(&wlk_root).unwrap();
let loaded = Config::load(&wlk_root).unwrap();
assert_eq!(loaded.get("user.name"), Some("Test User".to_string()));
assert_eq!(
loaded.get("user.email"),
Some("test@example.com".to_string())
);
}
#[test]
fn test_file_status() {
let temp_dir = TempDir::new().unwrap();
let mut repo = Repository::init(temp_dir.path()).unwrap();
let test_file = temp_dir.path().join("test.txt");
fs::write(&test_file, "initial content").unwrap();
repo.track_file(&test_file).unwrap();
assert!(!repo.file_has_changes(&test_file).unwrap());
fs::write(&test_file, "modified content").unwrap();
assert!(repo.file_has_changes(&test_file).unwrap());
}
#[test]
fn test_get_status() {
let temp_dir = TempDir::new().unwrap();
let mut repo = Repository::init(temp_dir.path()).unwrap();
let tracked_file = temp_dir.path().join("tracked.txt");
fs::write(&tracked_file, "tracked").unwrap();
repo.track_file(&tracked_file).unwrap();
let untracked_file = temp_dir.path().join("untracked.txt");
fs::write(&untracked_file, "untracked").unwrap();
fs::write(&tracked_file, "modified").unwrap();
let status = repo.get_status().unwrap();
assert!(status.len() >= 2);
let modified = status.iter().find(|s| s.path == tracked_file).unwrap();
assert_eq!(modified.status, wlk::FileStatus::Modified);
}
#[test]
fn test_shadow_search() {
use wlk::{DeltaOperation, ShadowFile};
let mut shadow = ShadowFile::new("test.txt", "initial".to_string());
shadow
.apply_delta(
DeltaOperation::Insert {
index: 7,
value: " content".to_string(),
},
Some("Added content".to_string()),
)
.unwrap();
shadow
.apply_delta(
DeltaOperation::Insert {
index: 15,
value: " more".to_string(),
},
Some("Added more".to_string()),
)
.unwrap();
let results = shadow.search_by_annotation("content");
assert_eq!(results.len(), 1);
let results = shadow.search_by_annotation("added");
assert_eq!(results.len(), 2);
}