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");
}