automapper-validation 0.30.21

AHB condition expression parsing, evaluation, and EDIFACT validation
Documentation
//! Condition [911] — REQOTE running counter format check.
//!
//! "Format: Mögliche Werte: 1 bis n, je Nachricht oder Segmentgruppe bei 1
//! beginnend und fortlaufend aufsteigend"
//!
//! Per-field implementation verifies that the value is a positive integer
//! (>= 1) without leading zeros. The cross-field "fortlaufend aufsteigend,
//! ohne Lücken" invariant is a structural sequence check not expressible
//! in the per-field `ConditionResult` model; documented as out of scope.

use automapper_validation::eval::{
    ConditionEvaluator, ConditionResult, EvaluationContext, NoOpExternalProvider,
};
use automapper_validation::ReqoteConditionEvaluatorFV2510;
use mig_types::segment::OwnedSegment;

fn eval(value: Option<&str>) -> ConditionResult {
    let evaluator = ReqoteConditionEvaluatorFV2510::default();
    let ext = NoOpExternalProvider;
    let segs: Vec<OwnedSegment> = vec![];
    let base = EvaluationContext::new("15002", &ext, &segs);
    let ctx = base.with_resolved(value, None);
    evaluator.evaluate(911, &ctx)
}

#[test]
fn reqote_911_true_for_1() {
    assert_eq!(eval(Some("1")), ConditionResult::True);
}

#[test]
fn reqote_911_true_for_multi_digit() {
    assert_eq!(eval(Some("42")), ConditionResult::True);
    assert_eq!(eval(Some("12345")), ConditionResult::True);
}

#[test]
fn reqote_911_false_for_zero() {
    assert_eq!(eval(Some("0")), ConditionResult::False);
}

#[test]
fn reqote_911_false_for_leading_zeros() {
    // "01" violates "1..n" form.
    assert_eq!(eval(Some("01")), ConditionResult::False);
    assert_eq!(eval(Some("001")), ConditionResult::False);
}

#[test]
fn reqote_911_false_for_negative_or_decimal() {
    assert_eq!(eval(Some("-1")), ConditionResult::False);
    assert_eq!(eval(Some("1.5")), ConditionResult::False);
}

#[test]
fn reqote_911_false_for_non_digit() {
    assert_eq!(eval(Some("abc")), ConditionResult::False);
    assert_eq!(eval(Some("1x")), ConditionResult::False);
}

#[test]
fn reqote_911_unknown_for_missing_value() {
    assert_eq!(eval(None), ConditionResult::Unknown);
    assert_eq!(eval(Some("")), ConditionResult::Unknown);
}