master
John Lauer rust: netlist, lint, libraries/settings/design rules, model_check/pcm/updates groups (33 verbs); net feature gate; serv… 2a09607 2mo ago
//! Parser tests against real KiCad 10 reports produced by service-kicad
//! (`service-kicad pcb drc` / `sch erc` on tour-pack-rp2040), so the shapes the
//! bridge summarises are the shapes kicad-cli actually writes.

use kicad_core::cli::{flatten_violations, summarize_report};

fn fixture(name: &str) -> serde_json::Value {
    let p = std::path::Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures").join(name);
    serde_json::from_str(&std::fs::read_to_string(&p).expect("fixture readable")).expect("fixture is JSON")
}

#[test]
fn drc_report_summarises_and_flattens() {
    let rep = fixture("rp2040-drc.json");
    let s = summarize_report(&rep);
    let v = flatten_violations(&rep);
    assert_eq!(s["kicadVersion"], rep["kicad_version"]);
    let errors = s["errors"].as_u64().unwrap();
    let warnings = s["warnings"].as_u64().unwrap();
    assert!(errors + warnings > 0, "a real board report has findings: {s}");
    assert_eq!(s["unconnected"].as_u64().unwrap() as usize, rep["unconnected_items"].as_array().map(|a| a.len()).unwrap_or(0));
    assert!(v.len() >= (errors + warnings) as usize);
    for item in &v {
        assert!(item["severity"].is_string() && item["description"].is_string() && item["items"].is_array());
    }
    assert_eq!(s["clean"], serde_json::json!(errors == 0 && s["unconnected"] == 0));
}

#[test]
fn erc_report_walks_sheets() {
    let rep = fixture("rp2040-erc.json");
    let sheet_total: usize = rep["sheets"].as_array().unwrap().iter().map(|s| s["violations"].as_array().map(|a| a.len()).unwrap_or(0)).sum();
    let v = flatten_violations(&rep);
    assert_eq!(v.len(), sheet_total, "every sheet violation is flattened");
    let s = summarize_report(&rep);
    assert!(s["errors"].as_u64().unwrap() + s["warnings"].as_u64().unwrap() <= sheet_total as u64);
}