tgqe 0.0.2

The Great Qin Empire —— A centralized system for integrating and summarizing common compiler front-end library errors and span error output libraries, with optional Ariadne integration.
/**

 *  - Copyright (c) 星灿长风v(Starwindv) 2026/08/03
 *  - License: BSD-3
 *  - Author: 星灿长风v(StarWindv)
 *  - Location: tgqe/src/modules/tests/reader.rs
 */
use crate::base_types::TgqeReader;
use crate::singletons::SourceManager;

#[test]
fn store_file_computes_line_offsets() {
    let path =
        std::env::temp_dir().join(format!(
            "tgqe_store_{}.txt",
            std::time::SystemTime::now()
                .duration_since(
                    std::time::UNIX_EPOCH,
                )
                .unwrap()
                .as_nanos()
        ));
    std::fs::write(&path, "ab\ncde\nf")
        .unwrap();

    assert!(
        TgqeReader::store_file(
            path.to_str().unwrap(),
        )
        .unwrap()
    );

    // 第二行中间(偏移 4)到文件尾(偏移 8):
    // 窗口应覆盖 2..3 行, 基准偏移 3, 显示行号偏移 1
    let cache =
        SourceManager.lock().unwrap();
    let (text, start, end, display) = cache
        .source_window(
            path.to_str().unwrap(),
            4,
            8,
        )
        .unwrap();

    assert_eq!(text, "cde\nf");
    assert_eq!((start, end), (1, 5));
    assert_eq!(display, 1);

    // 完整文本应在 store 时一次性缓存, 与原始文件字节一致
    assert_eq!(
        cache
            .source_text(
                path.to_str().unwrap()
            )
            .as_deref(),
        Some("ab\ncde\nf")
    );

    drop(cache);
    let _ = std::fs::remove_file(&path);
}