651 lines
25 KiB
Rust
651 lines
25 KiB
Rust
//! Actual online native job pages/output compared with independent INITEX.
|
|
#[path = "support/font_world.rs"]
|
|
mod font_world;
|
|
use std::{
|
|
collections::BTreeMap,
|
|
fs,
|
|
io::Write,
|
|
path::PathBuf,
|
|
process::Command,
|
|
sync::atomic::{AtomicU64, Ordering},
|
|
};
|
|
use texrra_tex_core::execution::*;
|
|
use texrra_tex_core::math_engine_tex::MathItem;
|
|
const FONTS: &str = include_str!("../../../examples/native-bootstrap/math-fonts.tex");
|
|
const SETUP: &str = r"\newlinechar=-1\tracingonline=1\showboxbreadth=10000\showboxdepth=40\hfuzz=1000pt\hbadness=10000\vbadness=10000\vsize=20pt\topskip=10pt\maxdepth=2pt ";
|
|
fn directory() -> PathBuf {
|
|
static N: AtomicU64 = AtomicU64::new(0);
|
|
let p = std::env::temp_dir().join(format!(
|
|
"texrra-pages-{}-{}",
|
|
std::process::id(),
|
|
N.fetch_add(1, Ordering::Relaxed)
|
|
));
|
|
fs::create_dir_all(&p).unwrap();
|
|
p
|
|
}
|
|
|
|
struct FileHost {
|
|
dir: PathBuf,
|
|
outputs: BTreeMap<u8, fs::File>,
|
|
terminal: Vec<String>,
|
|
before_shipout: Vec<Vec<u8>>,
|
|
}
|
|
impl SourceProvider for FileHost {
|
|
font_world::font_resources!();
|
|
fn read(&mut self, name: &str, _: &str) -> Result<SourceFile, String> {
|
|
let p = self.dir.join(name);
|
|
Ok(SourceFile {
|
|
name: p.display().to_string(),
|
|
data: fs::read(&p).map_err(|e| e.to_string())?,
|
|
})
|
|
}
|
|
fn open_out(&mut self, stream: u8, name: &str, _: &str) -> Result<String, String> {
|
|
let mut p = self.dir.join(name);
|
|
if p.extension().is_none() {
|
|
p.set_extension("tex");
|
|
}
|
|
self.outputs
|
|
.insert(stream, fs::File::create(&p).map_err(|e| e.to_string())?);
|
|
Ok(p.display().to_string())
|
|
}
|
|
fn write_out(&mut self, stream: u8, text: &str) -> Result<(), String> {
|
|
self.outputs
|
|
.get_mut(&stream)
|
|
.ok_or("stream not open")?
|
|
.write_all(text.as_bytes())
|
|
.map_err(|e| e.to_string())
|
|
}
|
|
fn close_out(&mut self, stream: u8) -> Result<(), String> {
|
|
if let Some(mut f) = self.outputs.remove(&stream) {
|
|
f.flush().map_err(|e| e.to_string())?;
|
|
}
|
|
Ok(())
|
|
}
|
|
fn diagnostic(&mut self, _: WriteDestination, text: &str) -> Result<(), String> {
|
|
self.terminal.push(text.into());
|
|
Ok(())
|
|
}
|
|
fn observe_message(&mut self, text: &str) -> Result<(), String> {
|
|
if text == "IO-BEFORE-SHIP" {
|
|
self.before_shipout
|
|
.push(fs::read(self.dir.join("result.aux")).map_err(|e| e.to_string())?);
|
|
}
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn deferred_whatsits_execute_actual_files_only_for_material_actually_shipped() {
|
|
let mut jobs = 0;
|
|
for body in [
|
|
r"\immediate\openout1=result.aux\def\Value{EARLY}\setbox1=\hbox{A\write1{BOX=\Value:\number\count0:\ifhmode H\fi/\ifvmode V\fi/\ifmmode M\fi/\ifinner I\fi}}\setbox2=\hbox{\write1{NEVER-SHIPPED}}\def\Value{LATE}\count0=7\copy1\count0=9\message{IO-BEFORE-SHIP}\shipout\copy1\setbox1=\hbox{}\setbox2=\hbox{}\def\Value{FINAL}\closeout1",
|
|
r"\immediate\openout1=result.aux\output{\global\advance\count0 by1\shipout\copy255\shipout\box255}\write1{PAGE=\number\count0}\hbox{A}\penalty-10000\closeout1",
|
|
r"\immediate\openout1=result.aux\splitmaxdepth=2pt\splittopskip=10pt\setbox1=\vbox{\hbox{A\write1{FIRST}}\penalty-10000\write1{BETWEEN}\hbox{B\write1{LAST}}}\setbox0=\vsplit1 to5pt\relax\shipout\box0\shipout\box1\immediate\closeout1",
|
|
r"\immediate\openout1=result.aux\setbox1=\hbox{A\write1{TRANSFERRED}}\hsize=20pt\noindent\unhcopy1 B C D\par\closeout1",
|
|
r"\immediate\openout1=result.aux\output{\count0=37\shipout\box255}\noindent A $x\write1{MATH=\number\count0:\ifmmode M\fi\ifinner I\fi}y$ B\par\closeout1",
|
|
r"\immediate\openout1=result.aux\noindent A $$x\write1{DISPLAY:\ifmmode M\fi/\ifvmode V\fi}y$$B\par\closeout1",
|
|
r"\immediate\openout1=result.aux\catcode94=7\immediate\write1{HASH=# BYTE=^^c8 STRING=\string# DETOK=\detokenize{#}}\write1{DEFERRED=#}\catcode33=6\write1{OTHER=!}\closeout1\hbox{A}\message{HASH=# BYTE=^^c8 STRING=\string# DETOK=\detokenize{#}}",
|
|
r"\immediate\openout1=result.aux\hsize=15pt\noindent A\write1{BREAK-A} B\write1{BREAK-B} C\par\closeout1",
|
|
] {
|
|
let p = directory();
|
|
let np = p.join("native");
|
|
let rp = p.join("reference");
|
|
fs::create_dir(&np).unwrap();
|
|
fs::create_dir(&rp).unwrap();
|
|
let source = format!("{FONTS}{SETUP}\\vsize=100pt\n{body}\\end\n");
|
|
let mut host = FileHost {
|
|
dir: np.clone(),
|
|
outputs: BTreeMap::new(),
|
|
terminal: Vec::new(),
|
|
before_shipout: Vec::new(),
|
|
};
|
|
let e = Executor::new(
|
|
State::initex()
|
|
.with_etex()
|
|
.with_input_profile(InputProfile::TeX8Bit),
|
|
Limits {
|
|
steps: 8_000_000,
|
|
tokens: 16_000_000,
|
|
..Limits::default()
|
|
},
|
|
)
|
|
.with_native_pages()
|
|
.run(
|
|
SourceFile {
|
|
name: "probe.tex".into(),
|
|
data: source.as_bytes().to_vec(),
|
|
},
|
|
&mut host,
|
|
)
|
|
.unwrap_or_else(|e| panic!("{p:?}: {body}: {e:?}"));
|
|
assert!(host.outputs.is_empty(), "{body}");
|
|
for data in &host.before_shipout {
|
|
assert!(data.is_empty(), "write executed before shipout: {data:?}");
|
|
}
|
|
fs::write(rp.join("probe.tex"), source).unwrap();
|
|
let r = Command::new("pdftex")
|
|
.args([
|
|
"-ini",
|
|
"-etex",
|
|
"-interaction=nonstopmode",
|
|
"-halt-on-error",
|
|
"probe.tex",
|
|
])
|
|
.current_dir(&rp)
|
|
.output()
|
|
.unwrap();
|
|
assert!(
|
|
r.status.success(),
|
|
"{p:?}: {}",
|
|
String::from_utf8_lossy(&r.stdout)
|
|
);
|
|
let actual = fs::read(np.join("result.aux")).unwrap();
|
|
let expected = fs::read(rp.join("result.aux")).unwrap();
|
|
assert!(!actual.is_empty());
|
|
assert_eq!(actual, expected, "{p:?}: {body}");
|
|
let log = fs::read_to_string(rp.join("probe.log")).unwrap();
|
|
for message in e.events.iter().filter_map(|event| match event {
|
|
Event::Message { text, .. } => Some(text),
|
|
_ => None,
|
|
}) {
|
|
assert!(log.contains(message), "{p:?}: missing {message:?}: {log}");
|
|
}
|
|
assert!(e.events.iter().any(|e| matches!(e, Event::Shipout(_))));
|
|
assert!(
|
|
!e.events
|
|
.iter()
|
|
.any(|e| matches!(e, Event::DeferredOutput(_)))
|
|
);
|
|
fs::remove_dir_all(p).unwrap();
|
|
jobs += 1;
|
|
}
|
|
eprintln!("{jobs} actual deferred I/O file jobs matched real INITEX");
|
|
}
|
|
fn native(source: &str) -> Result<Execution, Error> {
|
|
let dir = directory();
|
|
let mut host = FileHost {
|
|
dir: dir.clone(),
|
|
outputs: BTreeMap::new(),
|
|
terminal: Vec::new(),
|
|
before_shipout: Vec::new(),
|
|
};
|
|
let result = Executor::new(
|
|
State::initex()
|
|
.with_etex()
|
|
.with_input_profile(InputProfile::TeX8Bit),
|
|
Limits {
|
|
steps: 8_000_000,
|
|
tokens: 16_000_000,
|
|
..Limits::default()
|
|
},
|
|
)
|
|
.with_native_pages()
|
|
.run(
|
|
SourceFile {
|
|
name: "probe.tex".into(),
|
|
data: source.as_bytes().to_vec(),
|
|
},
|
|
&mut host,
|
|
);
|
|
if result.is_ok() {
|
|
fs::remove_dir_all(dir).unwrap();
|
|
}
|
|
result
|
|
}
|
|
fn observe(text: &str) -> String {
|
|
format!(r"\newlinechar=33\message{{!PAGE:{text}!}}\newlinechar=-1 ")
|
|
}
|
|
fn compare(body: &str, output: &str) -> Execution {
|
|
let p = directory();
|
|
let source = format!("{FONTS}{SETUP}\\output={{{output}}}\n{body}\\end\n");
|
|
fs::write(p.join("probe.tex"), &source).unwrap();
|
|
let e = native(&source).unwrap_or_else(|e| panic!("{p:?}: {body}: {e:?}"));
|
|
let r = Command::new("pdftex")
|
|
.args(["-ini", "-etex", "-interaction=nonstopmode", "probe.tex"])
|
|
.current_dir(&p)
|
|
.output()
|
|
.unwrap();
|
|
let log = fs::read_to_string(p.join("probe.log")).unwrap();
|
|
assert_eq!(r.status.code(), Some(1), "{p:?}: {log}");
|
|
for line in log.lines().filter(|line| line.starts_with("! ")) {
|
|
assert_eq!(line, "! OK.", "{p:?}: {log}");
|
|
}
|
|
let expected: Vec<_> = log
|
|
.split("> \\box255=")
|
|
.skip(1)
|
|
.map(|s| format!("> \\box255={}", s.split("! OK.").next().unwrap().trim_end()))
|
|
.collect();
|
|
let actual: Vec<_> = e
|
|
.events
|
|
.iter()
|
|
.filter_map(|e| {
|
|
if let Event::ShowBox(r) = e {
|
|
Some(r.text.trim_end())
|
|
} else {
|
|
None
|
|
}
|
|
})
|
|
.collect();
|
|
assert!(!actual.is_empty(), "{body}");
|
|
assert_eq!(actual.len(), expected.len(), "{p:?}: {body}: {log}");
|
|
for (a, b) in actual.iter().zip(&expected) {
|
|
assert_eq!(*a, b, "{p:?}: {body}");
|
|
}
|
|
for m in e.events.iter().filter_map(|e| {
|
|
if let Event::Message { text, .. } = e {
|
|
Some(text)
|
|
} else {
|
|
None
|
|
}
|
|
}) {
|
|
assert!(
|
|
log.contains(m.trim()),
|
|
"{p:?}: missing message {m:?}: {log}"
|
|
);
|
|
}
|
|
let messages: Vec<_> = e
|
|
.events
|
|
.iter()
|
|
.filter_map(|e| {
|
|
if let Event::Message { text, .. } = e {
|
|
Some(text.trim())
|
|
} else {
|
|
None
|
|
}
|
|
})
|
|
.filter(|s| s.starts_with("PAGE:"))
|
|
.collect();
|
|
let reference_messages: Vec<_> = log.lines().filter(|s| s.starts_with("PAGE:")).collect();
|
|
assert_eq!(
|
|
messages, reference_messages,
|
|
"{p:?}: actual hook/output message order"
|
|
);
|
|
assert!(!e.native_page.as_ref().unwrap().output_active);
|
|
assert!(e.native_page.as_ref().unwrap().nodes.is_empty());
|
|
assert!(e.native_page.as_ref().unwrap().contributions.is_empty());
|
|
fs::remove_dir_all(p).unwrap();
|
|
e
|
|
}
|
|
#[test]
|
|
fn actual_online_page_boxes_topskip_depth_and_end_material_match_initex() {
|
|
let mut jobs = 0;
|
|
let mut pages = 0;
|
|
for size in [0, 5, 10, 20, 30] {
|
|
for depth in [-2, 0, 1, 2] {
|
|
for top in [0, 3, 10] {
|
|
let e = compare(
|
|
&format!(
|
|
r"\vsize={size}pt\maxdepth={depth}pt\topskip={top}pt\hbox{{gj}}\vskip2pt plus1fil\hbox{{A}}\penalty37\hrule height1pt depth3pt\kern1pt\vskip0pt\hbox{{B}}"
|
|
),
|
|
r"\showbox255\shipout\box255",
|
|
);
|
|
jobs += 1;
|
|
pages += e
|
|
.events
|
|
.iter()
|
|
.filter(|e| matches!(e, Event::Shipout(_)))
|
|
.count();
|
|
}
|
|
}
|
|
}
|
|
eprintln!("{jobs} actual native jobs / {pages} page boxes matched INITEX");
|
|
}
|
|
#[test]
|
|
fn page_dimensions_are_live_global_and_specs_freeze_at_the_first_box() {
|
|
let snapshot = observe(r"D:\number\pagegoal/\number\pagetotal/\number\pagedepth");
|
|
let output = format!(
|
|
r"{}\showbox255\shipout\box255",
|
|
observe(r"OUT:\number\pagegoal/\number\pagetotal/\number\pagedepth/\number\deadcycles")
|
|
);
|
|
for body in [
|
|
format!(
|
|
r"{snapshot}\pagegoal=3pt{{\pagetotal=9pt}}{snapshot}\hbox{{gj}}{snapshot}\vsize=30pt\maxdepth=-3pt\topskip=100pt{snapshot}\vskip2pt{snapshot}\kern1pt{snapshot}\penalty0{snapshot}\hbox{{A}}\penalty-10000"
|
|
),
|
|
format!(
|
|
r"\hbox{{gj}}\vskip1pt plus2pt minus1pt\vskip0pt plus3fil\vskip0pt plus4fill\vskip0pt plus5filll\penalty0{}\hbox{{A}}\penalty-10000",
|
|
observe(
|
|
r"F:\number\pagestretch/\number\pagefilstretch/\number\pagefillstretch/\number\pagefilllstretch/\number\pageshrink"
|
|
)
|
|
),
|
|
format!(
|
|
r"\mark{{FIRST}}\vskip4pt\hrule height2pt width5pt{snapshot}\par{snapshot}\hbox{{A}}"
|
|
),
|
|
] {
|
|
compare(&body, &output);
|
|
}
|
|
}
|
|
#[test]
|
|
fn output_groups_can_wrap_drop_and_reinsert_real_box255_material() {
|
|
let body = r"\hsize=28pt\noindent A B C D E F G H I J K L M N.\par";
|
|
for output in [
|
|
format!(
|
|
r"{}\global\advance\count0 by1\showbox255\shipout\vbox{{\hbox{{Heading \number\count0}}\unvbox255\hbox{{Footer}}}}",
|
|
observe(
|
|
r"MODE:\ifvmode V\fi\ifinner I\fi/\number\currentgrouptype/\number\currentgrouplevel/\number\prevdepth"
|
|
)
|
|
),
|
|
r"\showbox255\global\setbox0=\box255\deadcycles=0".into(),
|
|
r"\showbox255\global\advance\count0 by1\ifnum\count0=1\unvbox255\else\shipout\box255\fi"
|
|
.into(),
|
|
] {
|
|
compare(body, &output);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn actual_page_marks_carry_by_output_attempt_and_remain_separate_from_split_marks() {
|
|
let mut jobs = 0;
|
|
for class in [0, 1, 256, 32767] {
|
|
for size in [0, 20] {
|
|
let report = observe(&format!(
|
|
r"M{class}:\topmarks{class}/\firstmarks{class}/\botmarks{class}"
|
|
));
|
|
let output = format!(r"{report}\showbox255\shipout\box255");
|
|
let body = format!(
|
|
r"\vsize={size}pt\marks{class}{{A}}\hbox{{A}}\marks{class}{{B}}\penalty-10000\hbox{{C}}\penalty-10000\marks{class}{{}}\hbox{{D}}\marks{class}{{E}}\penalty-10000\setbox7=\vbox{{\marks{class}{{SPLIT}}\hbox{{Q}}}}\setbox8=\vsplit7 to100pt\relax{}",
|
|
observe(&format!(
|
|
r"S{class}:\botmarks{class}/\splitfirstmarks{class}"
|
|
))
|
|
);
|
|
compare(&body, &output);
|
|
jobs += 1;
|
|
}
|
|
}
|
|
eprintln!("{jobs} actual per-class page/split mark jobs matched INITEX");
|
|
}
|
|
|
|
#[test]
|
|
fn output_timing_suspends_actual_paragraph_and_display_hooks_and_copies_toks() {
|
|
let output = format!(
|
|
r"{}\showbox255\shipout\box255",
|
|
observe(r"OUTPUT:\ifvmode V\fi\ifinner I\fi")
|
|
);
|
|
let hook = observe(r"HOOK:\ifhmode H\fi\ifmmode M\fi");
|
|
for body in [
|
|
format!(r"\vsize=7pt\hbox{{A}}\kern0pt\vskip0pt\everypar{{{hook}}}\noindent B C\par"),
|
|
format!(r"\vsize=7pt\hbox{{A}}\vskip0pt\everydisplay{{{hook}}}\noindent A $$x$$B\par"),
|
|
format!(r"\toks0=\output\output={{}}\output=\toks0\hbox{{A}}\penalty-10000"),
|
|
format!(r"\toks0={{{{\showbox255\shipout\box255}}}}\output=\toks0\hbox{{A}}\penalty-10000"),
|
|
format!(
|
|
r"\toks0={{\relax{{\showbox255\shipout\box255}}}}\output=\toks0\hbox{{A}}\penalty-10000"
|
|
),
|
|
] {
|
|
compare(&body, &output);
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
fn native_output_input_contexts_match_actual_initex() {
|
|
let p = directory();
|
|
let mut cases = 0;
|
|
for limit in [-2, -1, 0, 1, 2, 100] {
|
|
for output in [
|
|
r"\bad x",
|
|
r"\A\relax",
|
|
r"\message{\bad x}",
|
|
r"\immediate\write16{\bad x}",
|
|
] {
|
|
let s = format!(
|
|
"{FONTS}{SETUP}\\errorcontextlines={limit}\\def\\A{{\\bad x}}\\output{{{output}}}\n\\hbox{{A}}\\penalty-10000\\end\n"
|
|
);
|
|
let e = native(&s).unwrap_err();
|
|
assert!(
|
|
e.message.contains("undefined native control sequence"),
|
|
"{e:?}"
|
|
);
|
|
fs::write(p.join("probe.tex"), s).unwrap();
|
|
let r = Command::new("pdftex")
|
|
.args([
|
|
"-ini",
|
|
"-etex",
|
|
"-interaction=nonstopmode",
|
|
"-halt-on-error",
|
|
"probe.tex",
|
|
])
|
|
.current_dir(&p)
|
|
.output()
|
|
.unwrap();
|
|
assert_eq!(r.status.code(), Some(1));
|
|
let out = String::from_utf8(r.stdout).unwrap();
|
|
let expected = out
|
|
.split_once("Undefined control sequence.\n")
|
|
.unwrap()
|
|
.1
|
|
.split_once("No pages of output.")
|
|
.unwrap()
|
|
.0;
|
|
assert_eq!(e.context.text, expected, "output:{output}: {out}");
|
|
cases += 1;
|
|
}
|
|
}
|
|
eprintln!("{cases} actual output/write error contexts matched INITEX");
|
|
fs::remove_dir_all(p).unwrap();
|
|
}
|
|
|
|
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)]
|
|
enum Ink {
|
|
Glyph(String, i64, u8, i64, i64),
|
|
Rule(i64, i64, i64, i64),
|
|
}
|
|
|
|
#[test]
|
|
fn actual_shipouts_match_independent_dvi_fonts_dimensions_and_positions() {
|
|
let mut cases = Vec::new();
|
|
for size in [0, 10, 20, 35] {
|
|
for depth in [-1, 0, 2] {
|
|
for top in [0, 10] {
|
|
cases.push(format!(r"\vsize={size}pt\maxdepth={depth}pt\topskip={top}pt\moveright2pt\hbox{{g\vrule}}\vskip2pt plus1fil\hbox{{Aj}}\penalty37\hrule height1pt depth3pt\kern1pt\vskip0pt\hbox{{B}}"));
|
|
}
|
|
}
|
|
}
|
|
cases.extend([
|
|
r"\hsize=28pt\noindent A B C D E F G H I J K L M N.\par".into(),
|
|
r"\hsize=60pt\noindent A $$x+\raise2pt\hbox{g}$$ B\par".into(),
|
|
r"\hsize=14pt\overfullrule=2pt\hfuzz=0pt\noindent gj B C D\par".into(),
|
|
r"\hsize=30pt\lefthyphenmin=1\righthyphenmin=1\hyphenation{ab-cd-ef}\noindent A\write16{BREAK} abcdef abcdef\write16{TAIL} abcdef\par".into(),
|
|
r"\hsize=30pt\lefthyphenmin=1\righthyphenmin=1\hyphenation{ab-cd-ef}\noindent A \write16{BEFORE-WORD}abcdef abcdef\write16{AFTER-WORD} abcdef\par".into(),
|
|
]);
|
|
let p = directory();
|
|
let mut page_count = 0;
|
|
for (i, body) in cases.iter().enumerate() {
|
|
// A is a shared, fixed origin for TeX's physical-page offset. Neither
|
|
// the native page layout nor its baseline is fitted to the reference.
|
|
let output = r"\setbox0=\hbox{A\box255}\message{!DIM:\number\wd0,\number\ht0,\number\dp0;!}\shipout\box0";
|
|
let source = format!(r"{FONTS}{SETUP}\newlinechar=33\output{{{output}}}{body}\end");
|
|
let e = native(&source).unwrap_or_else(|e| panic!("{i}: {body}: {e:?}"));
|
|
fs::write(p.join("probe.tex"), format!(r"\pdfoutput=0 {source}")).unwrap();
|
|
let r = Command::new("pdftex")
|
|
.args([
|
|
"-ini",
|
|
"-etex",
|
|
"-interaction=nonstopmode",
|
|
"-halt-on-error",
|
|
"probe.tex",
|
|
])
|
|
.current_dir(&p)
|
|
.output()
|
|
.unwrap();
|
|
let log = fs::read_to_string(p.join("probe.log")).unwrap();
|
|
assert!(r.status.success(), "{p:?}: case {i}: {log}");
|
|
let r = Command::new("python3")
|
|
.arg(
|
|
PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
|
.join("../../scripts/native-math-dvi-oracle.py"),
|
|
)
|
|
.arg(p.join("probe.dvi"))
|
|
.output()
|
|
.unwrap();
|
|
assert!(r.status.success(), "{}", String::from_utf8_lossy(&r.stderr));
|
|
let pages: serde_json::Value = serde_json::from_slice(&r.stdout).unwrap();
|
|
let boxes: Vec<_> = e
|
|
.events
|
|
.iter()
|
|
.filter_map(|event| match event {
|
|
Event::Shipout(b) => Some(&b.box_node),
|
|
_ => None,
|
|
})
|
|
.collect();
|
|
assert_eq!(boxes.len(), pages.as_array().unwrap().len(), "case {i}");
|
|
let dims: Vec<Vec<i64>> = log
|
|
.split("DIM:")
|
|
.skip(1)
|
|
.map(|s| {
|
|
s.split(';')
|
|
.next()
|
|
.unwrap()
|
|
.split(',')
|
|
.map(|n| n.trim().parse().unwrap())
|
|
.collect()
|
|
})
|
|
.collect();
|
|
assert_eq!(boxes.len(), dims.len());
|
|
for (j, b) in boxes.iter().enumerate() {
|
|
let context = format!("{p:?}: case {i}, page {j}: {body}");
|
|
for (actual, expected) in [b.width, b.height, b.depth].iter().zip(&dims[j]) {
|
|
assert!(
|
|
(actual - expected).abs() <= 1,
|
|
"{context}: dimension {actual} != {expected}"
|
|
);
|
|
}
|
|
let page = &pages[j];
|
|
let anchor = &page["glyphs"][0];
|
|
assert_eq!(anchor["slot"], 65);
|
|
let (ox, oy) = (anchor["x"].as_i64().unwrap(), anchor["y"].as_i64().unwrap());
|
|
let mut expected: Vec<_> = page["glyphs"]
|
|
.as_array()
|
|
.unwrap()
|
|
.iter()
|
|
.map(|v| {
|
|
Ink::Glyph(
|
|
v["font"].as_str().unwrap().into(),
|
|
v["size"].as_i64().unwrap(),
|
|
v["slot"].as_u64().unwrap() as u8,
|
|
v["x"].as_i64().unwrap() - ox,
|
|
v["y"].as_i64().unwrap() - oy,
|
|
)
|
|
})
|
|
.collect();
|
|
expected.extend(page["rules"].as_array().unwrap().iter().map(|v| {
|
|
Ink::Rule(
|
|
v["x"].as_i64().unwrap() - ox,
|
|
v["y"].as_i64().unwrap() - oy,
|
|
v["width"].as_i64().unwrap(),
|
|
v["height"].as_i64().unwrap(),
|
|
)
|
|
}));
|
|
let mut actual: Vec<_> = b
|
|
.geometry()
|
|
.unwrap()
|
|
.items
|
|
.into_iter()
|
|
.map(|v| match v.item {
|
|
MathItem::NativeGlyph {
|
|
font, slot, size, ..
|
|
} => Ink::Glyph(font.name.clone(), size, slot, v.x, v.y),
|
|
MathItem::Rule { width, height } => Ink::Rule(v.x, v.y, width, height),
|
|
_ => panic!("legacy font in native shipout"),
|
|
})
|
|
.collect();
|
|
expected.sort();
|
|
actual.sort();
|
|
assert_eq!(actual.len(), expected.len(), "{context}");
|
|
for (a, b) in actual.iter().zip(&expected) {
|
|
match (a, b) {
|
|
(Ink::Glyph(af, az, ac, ax, ay), Ink::Glyph(bf, bz, bc, bx, by)) => {
|
|
assert_eq!((af, az, ac), (bf, bz, bc), "{context}");
|
|
assert!(
|
|
(ax - bx).abs() <= 1 && (ay - by).abs() <= 1,
|
|
"{context}: {a:?} != {b:?}"
|
|
);
|
|
}
|
|
(Ink::Rule(ax, ay, aw, ah), Ink::Rule(bx, by, bw, bh)) => assert!(
|
|
[ax - bx, ay - by, aw - bw, ah - bh]
|
|
.iter()
|
|
.all(|n| n.abs() <= 1),
|
|
"{context}: {a:?} != {b:?}"
|
|
),
|
|
_ => panic!("{context}: {a:?} != {b:?}"),
|
|
}
|
|
}
|
|
}
|
|
page_count += boxes.len();
|
|
}
|
|
eprintln!(
|
|
"{} actual native jobs / {page_count} shipped DVI pages matched at 1sp",
|
|
cases.len()
|
|
);
|
|
fs::remove_dir_all(p).unwrap();
|
|
}
|
|
|
|
#[test]
|
|
fn invalid_output_state_and_dead_cycles_fail_without_manufacturing_shipouts() {
|
|
let p = directory();
|
|
for body in [
|
|
r"\setbox255=\hbox{A}\hbox{B}\penalty-10000",
|
|
r"\output{\relax}\hbox{B}\penalty-10000",
|
|
r"\toks0={\relax}\output=\toks0\hbox{B}\penalty-10000",
|
|
r"\toks0={{\shipout\box255}\relax}\output=\toks0\hbox{B}\penalty-10000",
|
|
r"\maxdeadcycles=2\output{\unvbox255}\hbox{A}\penalty-10000",
|
|
r"\output{\end}\hbox{B}\penalty-10000",
|
|
r"\hbox{A}\vskip0pt minus1fil\hbox{B}",
|
|
] {
|
|
let source = format!("{FONTS}{SETUP}{body}\\end");
|
|
let e = native(&source)
|
|
.err()
|
|
.unwrap_or_else(|| panic!("invalid native job accepted: {body}"));
|
|
assert!(
|
|
!e.message.contains("undefined native control sequence"),
|
|
"{body}: {e:?}"
|
|
);
|
|
fs::write(p.join("probe.tex"), source).unwrap();
|
|
let r = Command::new("pdftex")
|
|
.args([
|
|
"-ini",
|
|
"-etex",
|
|
"-interaction=nonstopmode",
|
|
"-halt-on-error",
|
|
"probe.tex",
|
|
])
|
|
.current_dir(&p)
|
|
.output()
|
|
.unwrap();
|
|
assert_eq!(
|
|
r.status.code(),
|
|
Some(1),
|
|
"{body}: {}",
|
|
String::from_utf8_lossy(&r.stdout)
|
|
);
|
|
}
|
|
assert!(
|
|
native(&format!("{FONTS}{SETUP}\\hbox{{A}} "))
|
|
.unwrap_err()
|
|
.message
|
|
.contains("end")
|
|
);
|
|
let e = native(&format!(
|
|
"{FONTS}{SETUP}\\output{{\\deadcycles=0\\unvbox255}}\\hbox{{A}}\\penalty-10000\\end"
|
|
));
|
|
assert!(e.unwrap_err().message.contains("limit"));
|
|
fs::remove_dir_all(p).unwrap();
|
|
}
|
|
|
|
#[test]
|
|
fn original_whatsit_diagnostics_and_paragraph_breaks_match_actual_initex() {
|
|
for body in [
|
|
r"\openout1=result\hbox{A\write1{HASH=#}}\write1{OUTER}\closeout1",
|
|
r#"\openout1="has space.aux"\hbox{A\write1{\noexpand\relax ##}}\closeout1"#.into(),
|
|
r"\hbox{A\write16{TERMINAL}\write-1{LOG}\write99{TERMINAL-CLAMP}}",
|
|
r"\hsize=15pt\noindent A\write16{A-BREAK} B\write16{B-BREAK} C D\par",
|
|
r"\hsize=30pt\pretolerance=-1\lefthyphenmin=1\righthyphenmin=1\hyphenation{ab-cd-ef}\noindent A \write16{BEFORE}abcdef abcdef\write16{AFTER} abcdef\par",
|
|
] {
|
|
compare(body, r"\showbox255\shipout\box255");
|
|
}
|
|
compare(
|
|
&format!(
|
|
r"\hbox{{A\write16{{{}}}}}",
|
|
r"\noexpand\relax # ".repeat(40)
|
|
),
|
|
r"\showbox255\shipout\box255",
|
|
);
|
|
}
|