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/bus.rs
 */
use std::sync::atomic::Ordering;

use crate::base_types::{
    TgqeCoordinate, TgqeCtx, TgqeErrorInfo,
    TgqePosition, TgqeSpan,
};
use crate::channel::bus::TgqeBus;
use crate::enums::TgqeLevelFilter;
use crate::singletons::ERROR_COUNTER;

fn sample_ctx() -> TgqeCtx {
    let coord = TgqeCoordinate::new(
        "test.rs", 1, 0, 0,
    );
    let span = TgqeSpan::new(
        coord.clone(),
        coord.clone(),
    );
    TgqeCtx::new(
        TgqePosition::new(coord, span),
        TgqeErrorInfo::new(
            "test",
            "expected x",
            "got y",
            TgqeLevelFilter::Error,
        ),
        "hints",
        "labels",
        "winnow",
        0,
    )
}

#[tokio::test]
async fn report_moves_ctxs_and_increments_counter()
 {
    let mut bus = TgqeBus::new();
    let before = ERROR_COUNTER
        .load(Ordering::Relaxed);

    let mut ctxs =
        vec![sample_ctx(), sample_ctx()];
    bus.report(&mut ctxs).await;

    // 所有权被移入总线处理, 调用方 vec 变空
    assert!(ctxs.is_empty());
    assert_eq!(
        ERROR_COUNTER
            .load(Ordering::Relaxed),
        before + 2
    );
}