#[path = "support/font_world.rs"] mod font_world; use std::{fs, process::Command}; use texrra_tex_core::execution::*; const FONTS: &str = include_str!("../../../examples/native-bootstrap/math-fonts.tex"); const SETUP: &str = r#"\newlinechar=-1 \showboxbreadth=1000 \showboxdepth=40 \delcode40="028300 \delcode41="029301 "#; struct Host; impl SourceProvider for Host { font_world::font_resources!(); fn read(&mut self, name: &str, _: &str) -> Result { Err(format!("unexpected input {name}")) } } #[test] fn ruled_math_fields_match_reference_box_reports() { let root = std::env::temp_dir().join(format!("texrra-math-rules-{}", std::process::id())); fs::create_dir(&root).unwrap(); let mut index = 0; let mut compare = |body: &str, single_box: bool| { let case = root.join(index.to_string()); index += 1; fs::create_dir(&case).unwrap(); let tail = if single_box { r"\message{MATH-RULE=\number\wd0,\number\ht0,\number\dp0,\the\badness;}\showbox0 " } else { "" }; let source = format!("{FONTS}{SETUP}{body}{tail}\\end\n"); fs::write(case.join("probe.tex"), &source).unwrap(); let reference = Command::new("pdftex") .args(["-ini", "-etex", "-interaction=nonstopmode", "probe.tex"]) .current_dir(&case) .output() .unwrap(); let log = fs::read_to_string(case.join("probe.log")).unwrap(); let expected_boxes = if single_box { 1 } else { 5 }; assert_eq!(reference.status.code(), Some(1), "{case:?}: {log}"); let diagnostics: Vec<_> = log.lines().filter(|line| line.starts_with("! ")).collect(); assert_eq!(diagnostics, vec!["! OK."; expected_boxes], "{case:?}"); let execution = Executor::new(State::initex().with_etex(), Limits::default()) .run( SourceFile { name: "probe.tex".into(), data: source.into_bytes(), }, &mut Host, ) .unwrap_or_else(|error| panic!("{case:?}: {error}")); let (mut boxes, mut dimensions) = (0, 0); for event in &execution.events { match event { Event::Message { text, .. } if text.starts_with("MATH-RULE=") => { assert!(log.contains(text), "{case:?}: {text}"); dimensions += 1; } Event::ShowBox(report) => { assert!( log.contains(&report.text), "{case:?}:\n{}\n{log}", report.text ); boxes += 1; } _ => {} } } assert_eq!(boxes, expected_boxes); assert_eq!(dimensions, usize::from(single_box)); }; for operation in ["overline", "underline"] { for style in [ "displaystyle", "textstyle", "scriptstyle", "scriptscriptstyle", ] { for field in [ "f", "gj", "", "x^j_g", r"\vbox{\hbox{A}\hbox{gj}}", r"{a\over b}", r"\lower2pt\hbox{g}", ] { compare( &format!(r"\setbox0=\hbox{{$\{style}\{operation}{{{field}}}$}}"), true, ); } for thickness in ["0sp", "3sp", "-3sp"] { compare( &format!( r"\fontdimen8\tenex={thickness}\relax\setbox0=\hbox{{$\{style}\{operation}{{f^j_g}}_x$}}" ), true, ); } } } for body in [ r"\let\bar\overline\setbox0=\hbox{$a+\bar f=g$}", r"\setbox0=\hbox{$\overline{\underline{f^j_g}}^{y}_{g}+\underline{\overline{f}}$}", r"\setbox0=\hbox{$\left(\overline{f^j_g}\underline{g^a_b}\right)$}", ] { compare(body, true); } compare( r#"\mathcode102="0066 \mathcode105="0069 \setbox0=\hbox{$fi$} \setbox1=\hbox{$f\overline i$} \setbox2=\hbox{$\overline f i$} \setbox3=\hbox{$f\underline i$} \setbox4=\hbox{$\underline f i$} \showbox0 \showbox1 \showbox2 \showbox3 \showbox4 "#, false, ); assert_eq!(index, 84); fs::remove_dir_all(root).unwrap(); }