wlk 0.1.0

File-centric, event-sourced version control system with implicit branching
Documentation
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();

    // Create and track a file
    let test_file = temp_dir.path().join("test.txt");
    fs::write(&test_file, "initial content").unwrap();
    repo.track_file(&test_file).unwrap();

    // File should not have changes initially
    assert!(!repo.file_has_changes(&test_file).unwrap());

    // Modify file
    fs::write(&test_file, "modified content").unwrap();

    // Now it should have changes
    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();

    // Create tracked file
    let tracked_file = temp_dir.path().join("tracked.txt");
    fs::write(&tracked_file, "tracked").unwrap();
    repo.track_file(&tracked_file).unwrap();

    // Create untracked file
    let untracked_file = temp_dir.path().join("untracked.txt");
    fs::write(&untracked_file, "untracked").unwrap();

    // Modify tracked file
    fs::write(&tracked_file, "modified").unwrap();

    let status = repo.get_status().unwrap();

    // Should have at least 2 files (1 modified, 1 untracked)
    assert!(status.len() >= 2);

    // Find the modified file
    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);
}