vize_l1 0.608.0

L1 - the lossless Vue-template surface tree (codename Sinopia, Davinci P2-7)
Documentation
//! Davinci P2-7 TS-19 lane — corpus-runnable entry.
//!
//! Compiled only with the `legacy-differential` feature (see `[[test]]
//! required-features` in Cargo.toml), the P1-6/P1-7 lane shape. Runs the
//! committed battery with its exact-pinned scope and hole census (the
//! cfg-regression witness — the plain suite pins the same numbers, so a
//! feature-wiring regression fails loudly in both lanes), then, with
//! `VIZE_DAVINCI_DIFFERENTIAL_CORPUS=<dir>`, additionally sweeps every
//! `.vue` file under `<dir>` (e.g. `tests/_fixtures/_git` for the
//! hydrated ecosystem corpus): the **whole file's bytes** go through the
//! L1 parser — SFC block markup as markup, `<script>`/`<style>` content
//! as raw text — and `render(parse(src)) == src` is asserted per file.
//! The canonical fixture root fails closed unless its submodule inventory
//! reconciles; other roots sweep in smoke scope with
//! `closure_evidence=false` (see `davinci_test_support::corpus`).
//!
//! Run:
//!
//! ```text
//! VIZE_DAVINCI_DIFFERENTIAL_CORPUS=tests/_fixtures/_git \
//!     cargo test -p vize_l1 --features legacy-differential \
//!     --test surface_corpus -- --nocapture
//! ```

use std::fs;

use davinci_test_support::surface_fixture as common;
use vize_l0::{Allocator, String};
use vize_l1::markup::{HoleCounts, hole_counts, parse, render};

fn assert_round_trip(source: &str, context: &str) {
    let allocator = Allocator::new();
    let (tree, _errors) = parse(&allocator, source);
    let mut out = String::default();
    render(&tree, &mut |piece| out.push_str(piece));
    assert_eq!(out.as_str(), source, "L1 fidelity diverged: {context}");
}

#[test]
fn surface_corpus_round_trips() {
    // -- committed battery, exact-pinned scope ---------------------------
    assert_eq!(common::WELL_FORMED.len(), 16);
    assert_eq!(common::MALFORMED.len(), 26);
    for fixture in common::WELL_FORMED.iter().chain(common::MALFORMED) {
        let allocator = Allocator::new();
        let (tree, _errors) = parse(&allocator, fixture.source);
        let mut out = String::default();
        render(&tree, &mut |piece| out.push_str(piece));
        assert_eq!(out.as_str(), fixture.source, "fidelity: {}", fixture.name);
        let expected = HoleCounts {
            missing_tokens: fixture.missing_tokens,
            missing_close_tags: fixture.missing_close_tags,
            unexpected_nodes: fixture.unexpected_nodes,
        };
        assert_eq!(
            hole_counts(&tree),
            expected,
            "hole census: {}",
            fixture.name
        );
    }

    // -- optional corpus sweep -------------------------------------------
    let Some(sweep) = davinci_test_support::corpus::resolve_env_sweep() else {
        eprintln!("VIZE_DAVINCI_DIFFERENTIAL_CORPUS unset: committed battery only");
        return;
    };
    let files = &sweep.files;
    assert!(
        !files.is_empty(),
        "corpus sweep found no .vue files under {}",
        sweep.root.display()
    );
    let mut checked = 0u64;
    for file in files {
        let Ok(source) = fs::read_to_string(file) else {
            continue;
        };
        let mut context = String::default();
        context.push_str(file.to_string_lossy().as_ref());
        assert_round_trip(&source, context.as_str());
        checked += 1;
    }
    eprintln!(
        "davinci surface corpus sweep: files={} checked={}",
        files.len(),
        checked
    );
}