Skip to content

Commit 0ade269

Browse files
authored
Add simple test to xdv crate to ensure all outputs parse (#1314)
2 parents deb2a5d + 74fa4bf commit 0ade269

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

crates/xdv/src/lib.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,3 +1414,53 @@ enum NativeFontFlags {
14141414
Slant = 0x2000,
14151415
Embolden = 0x4000,
14161416
}
1417+
1418+
#[cfg(test)]
1419+
mod tests {
1420+
use super::*;
1421+
use std::ffi::OsStr;
1422+
use std::fs;
1423+
use std::path::{Path, PathBuf};
1424+
1425+
fn tex_outputs() -> PathBuf {
1426+
Path::new(env!("CARGO_MANIFEST_DIR"))
1427+
.join("../../tests/tex-outputs")
1428+
.canonicalize()
1429+
.unwrap()
1430+
}
1431+
1432+
// Run the parser on all XDV files in tex-outputs, to ensure it successfully handles
1433+
// all the outputs we expect to produce.
1434+
#[test]
1435+
fn test_output_xdvs() {
1436+
struct TestEvents;
1437+
1438+
impl XdvEvents for TestEvents {
1439+
type Error = XdvError;
1440+
1441+
fn handle_header(
1442+
&mut self,
1443+
filetype: FileType,
1444+
comment: &[u8],
1445+
) -> Result<(), Self::Error> {
1446+
assert_eq!(filetype, FileType::Xdv);
1447+
assert_eq!(comment, b"tectonic");
1448+
Ok(())
1449+
}
1450+
}
1451+
1452+
let xdvs = fs::read_dir(tex_outputs()).unwrap().filter_map(|f| {
1453+
f.ok()
1454+
.filter(|dir| dir.path().extension() == Some(OsStr::new("xdv")))
1455+
});
1456+
1457+
for xdv in xdvs {
1458+
let file = fs::read(xdv.path()).unwrap();
1459+
1460+
let mut parser = XdvParser::new(TestEvents);
1461+
let (consumed, keep_going) = parser.parse(&file).unwrap();
1462+
assert!(keep_going);
1463+
assert_eq!(consumed, file.len());
1464+
}
1465+
}
1466+
}

0 commit comments

Comments
 (0)