File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments