rusty-todo-md 1.10.2

A multi-language TODO comment extractor for source code files.
Documentation
use log::info;
use log::LevelFilter;
use rusty_todo_md::git_utils::{GitOps, GitOpsTrait};
use rusty_todo_md::logger;
use std::fs::File;
use std::io::Write;
use std::path::Path;
use std::path::PathBuf;
use std::sync::Once;
mod utils;
use utils::init_repo;

static INIT: Once = Once::new();

fn init_logger() {
    INIT.call_once(|| {
        env_logger::Builder::from_default_env()
            .format(logger::format_logger)
            .filter_level(LevelFilter::Debug)
            .is_test(true)
            .try_init()
            .ok();
    });
}

#[test]
fn test_get_tracked_files() {
    init_logger();
    info!("Starting test_get_tracked_files");
    let (_temp_dir, repo) = init_repo().unwrap();
    let tracked = GitOps.get_tracked_files(&repo).unwrap();
    assert!(tracked.contains(&PathBuf::from("test.txt")));
    // Verify nested directory file is tracked with correct path (no double slashes)
    assert!(
        tracked.contains(&PathBuf::from("app/src/nested.txt")),
        "Expected 'app/src/nested.txt' in tracked files, got: {:?}",
        tracked
    );
    // Verify no path contains double slashes
    for path in &tracked {
        let path_str = path.to_string_lossy();
        assert!(
            !path_str.contains("//"),
            "Path '{}' contains double slashes",
            path_str
        );
    }
    info!("Completed test_get_tracked_files");
}

#[test]
fn test_get_staged_files() {
    init_logger();
    info!("Starting test_get_staged_files");
    let (temp_dir, repo) = init_repo().unwrap();

    // Modify the file to simulate staged changes.
    let file_path = temp_dir.path().join("test.txt");
    {
        let mut file = File::create(&file_path).unwrap();
        writeln!(file, "modified content").unwrap();
    }

    // Stage the modified file.
    let mut index = repo.index().unwrap();
    index.add_path(Path::new("test.txt")).unwrap();
    index.write().unwrap();

    let staged = GitOps.get_staged_files(&repo).unwrap();
    assert!(staged.contains(&PathBuf::from("test.txt")));
    info!("Completed test_get_staged_files");
}