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/trans_winnow.rs
 */
use winnow::Parser;
use winnow::ascii::dec_uint;
use winnow::error::{
    ContextError, InputError, ParseError,
    StrContext,
};

use crate::base_types::TgqeCtx;

#[test]
fn context_error_maps_hints() {
    let mut err = ContextError::new();
    err.push(StrContext::Label("integer"));

    let ctx: TgqeCtx = err.into();

    assert_eq!(ctx.hints, "invalid integer");
    assert_eq!(ctx.publisher, "winnow");
}

#[test]
fn input_error_maps_input() {
    let ctx: TgqeCtx =
        InputError::at("abc").into();

    assert_eq!(ctx.err_info.got, "abc");
}

#[test]
fn parse_error_maps_offset_and_publisher() {
    let result: Result<
        u32,
        ParseError<&str, ContextError>,
    > = dec_uint::<&str, u32, ContextError>
        .parse("x");
    let ctx: TgqeCtx =
        result.unwrap_err().into();

    assert_eq!(ctx.position.coord.offset, 0);
    assert_eq!(ctx.position.coord.line, -2);
    assert_eq!(ctx.publisher, "winnow");
}