//! Snapshot regression tests for the DOCX reader.
//!
//! Three corpora are exercised, each in its own module:
//! - `pandoc`      — mirror of the Pandoc DOCX test suite (GPL-2.0-or-later)
//! - `docspec`     — original DocSpec-curated fixtures (ODC-By-1.0)
//! - `apache_tika` — mirror of the Apache Tika DOCX test documents (Apache-2.0)
//!
//! Every fixture is read through both `DocxReader::from_reader` and
//! `DocxReader::from_path`; the two constructors must emit identical event
//! streams (a divergence anywhere in any corpus fails fast) and the
//! `from_reader` stream is compared against the committed snapshot. This is
//! the canonical way to keep the `StreamingArchive` (`from_path`) and
//! in-memory (`from_reader`) paths in lockstep.
//!
//! All three corpora flow through the same [`assert_fixture_snapshot`] helper. The
//! per-fixture test functions are generated by `build.rs` from the contents of
//! `tests/fixtures/docx/<corpus>/` and `include!`d into each module.
//!
//! See `tests/fixtures/ATTRIBUTION.md` for corpus provenance and licensing,
//! and TESTING.md § Snapshot Review for the first-run and CI-mode workflow.
#![allow(
    clippy::arbitrary_source_item_ordering,
    clippy::expect_used,
    clippy::panic,
    clippy::redundant_test_prefix,
    clippy::std_instead_of_core,
    clippy::tests_outside_test_module,
    clippy::unwrap_used,
    dead_code
)]

use std::io::Cursor;
use std::path::PathBuf;

use docspec_docx_reader::DocxReader;
use docspec_test_utils::capture;

fn assert_fixture_snapshot(corpus: &str, file_name: &str) {
    let path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .join(format!("../../tests/fixtures/docx/{corpus}"))
        .join(file_name);

    let from_reader_snapshot = capture(&path, |bytes| DocxReader::from_reader(Cursor::new(bytes)));
    let from_path_snapshot = capture(&path, |_bytes| DocxReader::from_path(&path));

    assert_eq!(
        from_reader_snapshot, from_path_snapshot,
        "from_reader and from_path produced divergent event streams for {corpus}/{file_name}"
    );

    let snapshot_path = format!("../../../tests/snapshots/docx/{corpus}");
    insta::with_settings!({
        snapshot_path => snapshot_path,
        prepend_module_to_snapshot => false,
    }, {
        insta::assert_debug_snapshot!(file_name, from_reader_snapshot);
    });
}

mod pandoc {
    include!(concat!(env!("OUT_DIR"), "/pandoc_corpus_tests.rs"));
}

mod docspec {
    include!(concat!(env!("OUT_DIR"), "/docspec_corpus_tests.rs"));
}

mod apache_tika {
    include!(concat!(env!("OUT_DIR"), "/apache_tika_corpus_tests.rs"));
}
