//! Differential parity against a generated golden table.
//!
//! `fixtures/oracle.tsv` holds tens of thousands of `(min, max, options) =>
//! output` rows. This test reproduces every row exactly and compiles each
//! output as a regex. It is the broad zero-drift gate.

mod common;

use common::to_regex;
use regex_range::{to_regex_range, Options};

fn opts_for(tag: &str) -> Options {
    match tag {
        "default" => Options::default(),
        "capture" => Options::default().capture(true),
        "shorthand" => Options::default().shorthand(true),
        "strict" => Options::default().relax_zeros(false),
        "wrapfalse" => Options::default().wrap(false),
        other => panic!("unknown tag {other}"),
    }
}

#[test]
fn oracle_parity() {
    let data = include_str!("fixtures/oracle.tsv");
    let mut checked = 0usize;

    for (line_no, line) in data.lines().enumerate() {
        if line.is_empty() {
            continue;
        }
        let mut cols = line.split('\t');
        let min = cols.next().expect("min column");
        let max_raw = cols.next().expect("max column");
        let tag = cols.next().expect("tag column");
        let want = cols.next().expect("output column");

        let max = if max_raw.is_empty() {
            None
        } else {
            Some(max_raw)
        };
        let opts = opts_for(tag);

        let got = to_regex_range(min, max, &opts).expect("valid range");
        assert_eq!(
            got,
            want,
            "line {} min={min} max={max_raw} tag={tag}",
            line_no + 1
        );

        // Every output must compile.
        let _ = to_regex(&got);
        checked += 1;
    }

    assert!(
        checked > 10_000,
        "expected a broad table, got {checked} rows"
    );
}
