use mx20022_codegen::{emit, ir, xsd};
#[test]
fn snapshot_head_001_001_04() {
let xsd_path = concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../schemas/head/head.001.001.04.xsd"
);
let file = std::fs::File::open(xsd_path).expect("head.001.001.04.xsd not found");
let schema = xsd::parse(std::io::BufReader::new(file)).expect("XSD parse failed");
let graph = ir::lower(&schema).unwrap();
let code = emit::emit(&graph);
syn::parse_file(&code).expect("generated code must be valid Rust");
insta::assert_snapshot!("head_001_001_04_emit", code);
}
#[test]
fn snapshot_pacs_008_001_13() {
let xsd_path = concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../schemas/pacs/pacs.008.001.13.xsd"
);
let file = std::fs::File::open(xsd_path).expect("pacs.008.001.13.xsd not found");
let schema = xsd::parse(std::io::BufReader::new(file)).expect("XSD parse failed");
let graph = ir::lower(&schema).unwrap();
let code = emit::emit(&graph);
syn::parse_file(&code).expect("generated code must be valid Rust");
insta::assert_snapshot!("pacs_008_001_13_emit", code);
}
#[test]
fn snapshot_camt_053_001_11() {
let xsd_path = concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../schemas/camt/camt.053.001.11.xsd"
);
let file = std::fs::File::open(xsd_path).expect("camt.053.001.11.xsd not found");
let schema = xsd::parse(std::io::BufReader::new(file)).expect("XSD parse failed");
let graph = ir::lower(&schema).unwrap();
let code = emit::emit(&graph);
syn::parse_file(&code).expect("generated code must be valid Rust");
insta::assert_snapshot!("camt_053_001_11_emit", code);
}
#[test]
fn head_001_emits_expected_types() {
let xsd_path = concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../schemas/head/head.001.001.04.xsd"
);
let file = std::fs::File::open(xsd_path).expect("head.001.001.04.xsd not found");
let schema = xsd::parse(std::io::BufReader::new(file)).expect("XSD parse failed");
let graph = ir::lower(&schema).unwrap();
let code = emit::emit(&graph);
assert!(
code.contains("pub struct BusinessApplicationHeaderV04"),
"missing root struct"
);
assert!(code.contains("pub struct Max35Text"), "missing Max35Text");
assert!(
code.contains("Maximum length"),
"missing max-length constraint doc"
);
assert!(
code.contains("pub enum AddressType3Choice"),
"missing AddressType3Choice"
);
assert!(
code.contains("pub enum AddressType2Code"),
"missing AddressType2Code"
);
assert!(code.contains("\"$value\""), "missing $value field");
assert!(
code.contains("pub struct SignatureEnvelope"),
"missing SignatureEnvelope"
);
assert!(
code.contains("serde::Serialize"),
"missing serde::Serialize derive"
);
assert!(
code.contains("serde::Deserialize"),
"missing serde::Deserialize derive"
);
}