#![cfg(feature = "gedzip")]
use std::path::{Path, PathBuf};
fn charset_root() -> PathBuf {
Path::new(env!("CARGO_MANIFEST_DIR")).join("fixtures/external/torture/charset")
}
const ARCHIVES: &[&str] = &[
"ansel.zip",
"uhlbomcl.zip",
"uhlcl.zip",
"ulhbomcl.zip",
"ulhc.zip",
"ulhcl.zip",
"ulhl.zip",
"ulhlc.zip",
];
#[test]
fn every_charset_permutation_of_the_same_tree_reads_to_the_same_records() {
let root = charset_root();
if !root.exists() {
eprintln!(
"skipped: {} is absent; run scripts/fetch-fixtures.ps1",
root.display()
);
return;
}
let mut record_counts = Vec::new();
for name in ARCHIVES {
let bytes = match std::fs::read(root.join(name)) {
Ok(bytes) => bytes,
Err(error) => {
eprintln!("skipped {name}: {error}; run scripts/fetch-fixtures.ps1");
continue;
}
};
let archive = gedcomkit::gedzip::Archive::open(&bytes)
.unwrap_or_else(|error| panic!("{name} did not open as an archive: {error}"));
let document_name = archive
.document_name()
.unwrap_or_else(|error| panic!("{name}: {error}"))
.to_owned();
let inner = archive
.read(&document_name)
.unwrap_or_else(|error| panic!("{name}/{document_name}: {error}"));
let (text, report) = gedcomkit::decode_gedcom(&inner)
.unwrap_or_else(|error| panic!("{name} did not decode: {error}"));
assert_eq!(
report.undecodable_bytes,
0,
"{name} had undecodable bytes: {}",
report.summary()
);
let document = gedcomkit::Document::parse(&text)
.unwrap_or_else(|error| panic!("{name} did not parse: {error}"));
record_counts.push((*name, document.records.len(), document.content_records()));
let written = document.to_text();
let again = gedcomkit::Document::parse(&written)
.unwrap_or_else(|error| panic!("{name} output did not re-parse: {error}"));
assert_eq!(
again.to_text(),
written,
"{name} did not reach a round-trip fixed point"
);
}
if record_counts.is_empty() {
return;
}
let (first_name, first_records, first_content) = record_counts[0];
for (name, records, content) in &record_counts {
assert_eq!(
(*records, *content),
(first_records, first_content),
"{name} read a different tree than {first_name}"
);
}
}