573 lines
24 KiB
Rust
573 lines
24 KiB
Rust
//! Original-list vertical splitting and mark state against actual INITEX.
|
|
#[path = "support/font_world.rs"]
|
|
mod font_world;
|
|
use std::{
|
|
fs,
|
|
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 ";
|
|
|
|
fn directory() -> PathBuf {
|
|
static N: AtomicU64 = AtomicU64::new(0);
|
|
let p = std::env::temp_dir().join(format!(
|
|
"texrra-splitting-{}-{}",
|
|
std::process::id(),
|
|
N.fetch_add(1, Ordering::Relaxed)
|
|
));
|
|
fs::create_dir_all(&p).unwrap();
|
|
p
|
|
}
|
|
fn native(source: &str) -> Result<Execution, Error> {
|
|
Executor::new(
|
|
State::initex().with_etex(),
|
|
Limits {
|
|
steps: 16_000_000,
|
|
tokens: 16_000_000,
|
|
..Limits::default()
|
|
},
|
|
)
|
|
.run(
|
|
SourceFile {
|
|
name: "probe.tex".into(),
|
|
data: source.as_bytes().to_vec(),
|
|
},
|
|
&mut font_world::FontFiles,
|
|
)
|
|
}
|
|
fn observe(text: &str) -> String {
|
|
format!(r"\newlinechar=33\message{{!OBS:{text}!}}\newlinechar=-1 ")
|
|
}
|
|
fn compare(cases: &[String]) -> Execution {
|
|
let p = directory();
|
|
let source = format!(
|
|
"{FONTS}{SETUP}{}\\end",
|
|
cases
|
|
.iter()
|
|
.map(|body| format!("{{{body}\\showbox0\\showbox1}}\n"))
|
|
.collect::<String>()
|
|
);
|
|
let e = native(&source).unwrap_or_else(|e| panic!("{p:?}: {e:?}"));
|
|
fs::write(p.join("probe.tex"), &source).unwrap();
|
|
let output = 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!(output.status.code(), Some(1), "{p:?}: {log}");
|
|
for line in log.lines().filter(|line| line.starts_with("! ")) {
|
|
assert_eq!(line, "! OK.", "{p:?}: {log}");
|
|
}
|
|
let actual: Vec<_> = e
|
|
.events
|
|
.iter()
|
|
.filter_map(|e| {
|
|
if let Event::ShowBox(r) = e {
|
|
Some(r.text.trim_end())
|
|
} else {
|
|
None
|
|
}
|
|
})
|
|
.collect();
|
|
let reference: Vec<_> = log
|
|
.split("> \\box")
|
|
.skip(1)
|
|
.map(|s| format!("> \\box{}", s.split("! OK.").next().unwrap().trim_end()))
|
|
.collect();
|
|
assert_eq!(actual.len(), 2 * cases.len());
|
|
assert_eq!(reference.len(), actual.len(), "{p:?}: {log}");
|
|
for (i, (a, b)) in actual.iter().zip(&reference).enumerate() {
|
|
assert_eq!(*a, b, "{p:?}: case {}: {}", i / 2, cases[i / 2]);
|
|
}
|
|
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}"
|
|
);
|
|
}
|
|
eprintln!(
|
|
"{} actual split/remaining box pairs matched INITEX",
|
|
cases.len()
|
|
);
|
|
fs::remove_dir_all(p).unwrap();
|
|
e
|
|
}
|
|
|
|
#[test]
|
|
fn vertical_break_depth_and_pruned_remainders_match_actual_initex() {
|
|
let mut cases = Vec::new();
|
|
for height in [-131072, 0, 1, 8 * 65536, 13 * 65536, 50 * 65536] {
|
|
for depth in [-131072, 0, 1, 2 * 65536, 100 * 65536] {
|
|
for kind in ["vbox", "vtop"] {
|
|
for body in [
|
|
r"\hbox{gj}\vskip2pt plus3pt minus1pt\hbox{A}\penalty37\kern1pt\vskip0pt plus1fil\hrule width12pt height1pt depth3pt\mark{bottom}",
|
|
r"\vskip1pt\kern2pt\penalty7\hbox{g}\kern1pt\vskip2pt\hbox{j}",
|
|
r"\mark{head}\hrule width10pt height-1pt depth4pt\penalty-10000\mark{tail}\hbox{A}",
|
|
r"\hbox{A}\penalty10000\vskip1pt\hbox{g}\penalty-9000\vskip2pt\hbox{j}",
|
|
] {
|
|
cases.push(format!(r"\splitmaxdepth={depth}sp\splittopskip=9pt plus2fil minus1pt\setbox1=\{kind}{{{body}}}\setbox0=\vsplit1 to{height}sp"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
cases.extend([
|
|
r"\splitmaxdepth=2pt\splittopskip=10pt\setbox1=\vbox to100pt{\hbox{gj}\vskip2pt\hbox{A}}\ht1=3pt\dp1=2pt\wd1=1pt\setbox0=\vsplit1 to8pt".into(),
|
|
r"\splitmaxdepth=1pt\splittopskip=-3pt\setbox1=\vbox{\hrule width10pt height-2pt depth5pt\penalty-10000\hrule width8pt height-4pt depth6pt}\setbox0=\vsplit1 to0pt".into(),
|
|
r"\setbox1=\vbox{}\splitmaxdepth=-2pt\setbox0=\vsplit1 to3pt".into(),
|
|
r"\setbox0=\vsplit1 to3pt".into(),
|
|
]);
|
|
compare(&cases);
|
|
}
|
|
|
|
#[test]
|
|
fn legal_breaks_costs_ties_and_forced_stops_match_actual_initex() {
|
|
let mut cases = Vec::new();
|
|
for penalty in [-10001, -10000, -500, 0, 9999, 10000, 10001] {
|
|
for height in [0, 5, 12, 30] {
|
|
for glue in [
|
|
"0pt plus1pt",
|
|
"0pt plus1fil",
|
|
"0pt plus1fill",
|
|
"0pt plus1filll",
|
|
] {
|
|
cases.push(format!(r"\splitmaxdepth=1pt\splittopskip=3pt\setbox1=\vbox{{\hrule width2pt height3pt depth1pt\vskip{glue}\penalty{penalty}\hrule width3pt height4pt\kern1pt\vskip2pt minus2pt\hrule width4pt height2pt}}\setbox0=\vsplit1 to{height}pt"));
|
|
}
|
|
}
|
|
}
|
|
for body in [
|
|
r"\vskip0pt plus1fil\hrule width1pt height2pt\penalty0\penalty0\kern0pt\vskip0pt\hrule width2pt height2pt",
|
|
r"\kern0pt\vskip0pt\hrule width1pt height2pt",
|
|
r"\mark{before}\vskip0pt\hrule width1pt height2pt",
|
|
r"\penalty10000\vskip0pt\hrule width1pt height2pt",
|
|
r"\hrule width1pt height2pt\kern0pt\mark{between}\vskip0pt\hrule width2pt height2pt",
|
|
r"\penalty-10000\mark{retained}\kern1pt\vskip3pt\penalty-10000\hbox{A}",
|
|
r"\hbox{A}\penalty-10000\vss\hbox{B}",
|
|
] {
|
|
cases.push(format!(
|
|
r"\splitmaxdepth=0pt\splittopskip=10pt\setbox1=\vbox{{{body}}}\setbox0=\vsplit1 to1pt"
|
|
));
|
|
}
|
|
compare(&cases);
|
|
}
|
|
|
|
#[test]
|
|
fn split_marks_are_global_expanded_tokens_per_class_and_clear_on_void() {
|
|
let mut cases = Vec::new();
|
|
for class in [0, 1, 15, 256, 32767] {
|
|
cases.push(format!(r"\def\A{{FIRST}}\protected\def\P{{OLD}}\setbox1=\vbox{{\marks{class}{{\A\P}}\hbox{{g}}\marks{class}{{BOTTOM}}\penalty-10000\marks{class}{{REST}}\hbox{{j}}}}\def\A{{CHANGED}}\protected\def\P{{NEW}}\setbox0=\vsplit1 to5pt{}\setbox0=\vsplit1 to5pt{}",observe(&format!(r"C{class}:\splitfirstmarks{class}/\splitbotmarks{class}")),observe(&format!(r"R{class}:\splitfirstmarks{class}/\splitbotmarks{class}"))));
|
|
cases.push(format!(r"\setbox1=\vbox{{\marks{class}{{}}\hbox{{A}}\marks{class}{{B}}}}\setbox0=\vsplit1 to100pt{}\setbox0=\vsplit2 to5pt{}",observe(&format!(r"E{class}:\splitfirstmarks{class}/\splitbotmarks{class}")),observe(&format!(r"V{class}:\splitfirstmarks{class}/\splitbotmarks{class}"))));
|
|
}
|
|
cases.push(format!(r"\setbox1=\vbox{{\mark{{A}}\marks1{{B}}\hbox{{g}}}} {{\setbox0=\vsplit1 to20pt}}{}\setbox0=\vsplit2 to0pt{}",observe(r"GLOBAL:\splitfirstmark/\splitfirstmarks1"),observe(r"CLEAR:\splitbotmark/\splitbotmarks1")));
|
|
cases.push(format!(r"\setbox1=\vbox{{\mark{{FIRST}}\penalty-10000\marks2{{KEEP}}}}\setbox0=\vsplit1 to0pt{}\setbox0=\vsplit1 to0pt{}",observe(r"MARKONLY:\splitfirstmark/\splitbotmarks2"),observe(r"TAIL:\splitfirstmark/\splitbotmarks2")));
|
|
cases.push(format!(r"\setbox1=\vbox{{\marks0{{ZERO}}\hbox{{A}}}}\setbox0=\vsplit1 to10pt\let\M=\splitfirstmarks{}",observe(r"ALIASES:\splitfirstmark/\M\numexpr1-1\relax")));
|
|
let e = compare(&cases);
|
|
assert!(e.state.split_marks(0).is_some());
|
|
assert!(e.reads.contains(&Dependency::SplitMarks(32767)));
|
|
let restored: Execution = serde_json::from_slice(&serde_json::to_vec(&e).unwrap()).unwrap();
|
|
assert_eq!(e, restored);
|
|
}
|
|
|
|
#[test]
|
|
fn marks_migrate_from_actual_lines_adjusted_hboxes_and_displays_only() {
|
|
let mut cases = Vec::new();
|
|
for height in [0, 8, 20, 100] {
|
|
for body in [
|
|
r"\hbox{A\mark{DIRECT}B}\hbox{\marks1{SECOND}C}",
|
|
r"\setbox2=\hbox{A\mark{HIDDEN}B}\copy2\hbox{C\mark{VISIBLE}}",
|
|
r"\setbox2=\hbox{A\mark{UNBOXED}B}\hsize=25pt\noindent\unhcopy2 C D\par",
|
|
r"\setbox2=\vbox{\mark{TRANSFERRED}\hbox{A}}\unvcopy2\hbox{B}",
|
|
r"\hsize=25pt\noindent A\mark{P0} B C D\marks1{C1} E F\mark{LAST} G H.\par",
|
|
r"\hsize=10pt\noindent AB\mark{BREAK} CD\par",
|
|
r"\hsize=100pt\noindent A\hbox{B\mark{HIDDEN}}C\mark{LINE}\par",
|
|
r"\hsize=100pt\noindent $a\mark{MATH}b$\par",
|
|
r"\hsize=100pt\noindent A $$x\mark{DISPLAY}y$$B\par",
|
|
r"\hsize=5pt\noindent A $$xy\mark{OVERFULL}$$B\par",
|
|
] {
|
|
cases.push(format!(r"\splitmaxdepth=2pt\splittopskip=10pt\setbox1=\vbox{{{body}}}\setbox0=\vsplit1 to{height}pt{}",observe(r"MIGRATE:\splitfirstmark/\splitbotmark/\splitfirstmarks1")));
|
|
}
|
|
}
|
|
for ending in [r"aaaa\mark{AFTER}", r"\mark{BEFORE}aaaa"] {
|
|
cases.push(format!(r"\lccode`a=`a\hyphenchar\tenrm=45\lefthyphenmin=1\righthyphenmin=1\hyphenation{{aa-aa}}\pretolerance=-1\tolerance=200\hsize=15pt\splitmaxdepth=2pt\setbox1=\vbox{{\noindent A {ending} A\par}}\setbox0=\vsplit1 to100pt"));
|
|
}
|
|
let e = compare(&cases);
|
|
for p in e.events.iter().filter_map(|e| {
|
|
if let Event::BuiltParagraph(p) = e {
|
|
Some(p)
|
|
} else {
|
|
None
|
|
}
|
|
}) {
|
|
for b in &p.line_boxes {
|
|
assert!(
|
|
matches!(&b.content,BoxContent::Horizontal(n) if !n.iter().any(|n|matches!(n,TextNode::Mark(_))))
|
|
);
|
|
}
|
|
}
|
|
assert!(e.events.iter().any(|e|matches!(e,Event::BuiltParagraph(p) if p.line_adjustments.iter().any(|a|a.iter().any(|n|matches!(n,NativeVerticalNode::Mark(_)))))));
|
|
}
|
|
|
|
#[test]
|
|
fn split_mutates_original_register_level_and_obeys_scan_and_assignment_order() {
|
|
let mut cases = Vec::new();
|
|
for global in ["", r"\global "] {
|
|
for target in [0, 1] {
|
|
cases.push(format!(r"\setbox1=\vbox{{\hbox{{OUTER}}\vskip2pt\hbox{{TAIL}}}} {{\setbox{target}=\vsplit1 to5pt}}{}\setbox0=\hbox{{\copy1}}",observe(r"LEVEL:\ifvoid1 V\else B\fi")));
|
|
cases.push(format!(r"\setbox1=\vbox{{\hbox{{OUTER}}}} {{ {global}\setbox1=\vbox{{\hbox{{INNER}}\vskip2pt\hbox{{TAIL}}}}\setbox{target}=\vsplit1 to5pt}}"));
|
|
}
|
|
}
|
|
cases.extend([
|
|
r"\splitmaxdepth=1pt\splittopskip=10pt{\advance\splitmaxdepth by1pt\splittopskip=20pt}\setbox1=\vbox{\hbox{g}\penalty-10000\hbox{j}}\setbox0=\vsplit1 to5pt".into(),
|
|
r"\let\V=\vsplit\setbox1=\vbox{\hbox{g}\vskip1pt\hbox{j}}\setbox0=\V\numexpr2-1\relax to\dimexpr3pt+2pt\relax".into(),
|
|
r"\setbox1=\vbox{\hbox{g}\penalty-10000\hbox{j}}\setbox0=\hbox{$a\vsplit1 to5pt b$}".into(),
|
|
r"\setbox1=\vbox{\hbox{g}\vskip2pt\hbox{j}}\setbox0=\hbox{\raise2pt\vsplit1 to5pt}".into(),
|
|
]);
|
|
cases.push(format!(r"\setbox0=\vsplit2 to0pt\relax\setbox1=\vbox{{\mark{{\noexpand\def\noexpand\Seen{{Y}}}}\hbox{{}}}}\setbox0=\vsplit1 to0pt\splitfirstmark{}\setbox0=\vsplit2 to0pt\splitfirstmark{}",observe(r"EARLY:\ifdefined\Seen Y\else N\fi"),observe(r"LATE:\ifdefined\Seen Y\else N\fi")));
|
|
cases.push(format!(r"\setbox1=\vbox{{\mark{{READY}}\hbox{{A}}}}\def\After{{{}}}\afterassignment\After\setbox0=\vsplit1 to5pt\relax",observe(r"AFTER:\splitfirstmark")));
|
|
compare(&cases);
|
|
}
|
|
|
|
#[test]
|
|
fn mark_tokens_print_from_actual_categories_and_truncate_at_tex_token_boundaries() {
|
|
let mut cases = Vec::new();
|
|
for length in [0, 68, 69, 70, 100] {
|
|
cases.push(format!(
|
|
r"\setbox1=\vbox{{\mark{{{}}}\hbox{{A}}}}\setbox0=\vsplit1 to5pt",
|
|
"X".repeat(length)
|
|
));
|
|
}
|
|
cases.extend([
|
|
r"\def\A{A}\protected\def\P{P}\setbox1=\vbox{\mark{\P\A #\noexpand\foo}\marks1{X}\marks0{Y}}\setbox0=\copy1".into(),
|
|
r"\catcode`~=13\def~{ACTIVE}\setbox1=\vbox{\mark{\noexpand~\noexpand\A\noexpand\!\noexpand\csname\unexpanded{Z}}}\setbox0=\copy1".into(),
|
|
r"\setbox1=\vbox{\mark{\noexpand\A\noexpand\!}}\catcode`A=12\escapechar=64\setbox0=\copy1".into(),
|
|
r"\font\^^c8=cmr10\^^c8\setbox1=\vbox{\mark{\the\font}\hbox{}}\setbox0=\copy1".into(),
|
|
r"\newlinechar=88\setbox1=\vbox{\mark{XAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXAXA}}\setbox0=\copy1".into(),
|
|
r"\setbox1=\vbox{\mark{\expandafter\noexpand\csname\endcsname}}\setbox0=\copy1".into(),
|
|
r"\catcode200=13\setbox1=\vbox{\mark{\noexpand^^c8}}\setbox0=\copy1".into(),
|
|
]);
|
|
for n in [1, 30] {
|
|
cases.push(format!(
|
|
r"\catcode200=11\setbox1=\vbox{{\mark{{{}}}}}\setbox0=\copy1",
|
|
r"\noexpand\^^c8 ".repeat(n)
|
|
));
|
|
}
|
|
cases.push(format!(
|
|
r"\setbox1=\vbox{{\mark{{\noexpand\{} A}}}}\setbox0=\copy1",
|
|
"A".repeat(80)
|
|
));
|
|
let e = compare(&cases);
|
|
assert!(e.reads.contains(&Dependency::CatCode('A')));
|
|
}
|
|
|
|
#[test]
|
|
fn invalid_split_modes_classes_glue_and_real_capacity_fail_explicitly() {
|
|
let p = directory();
|
|
for body in [
|
|
r"\setbox1=\hbox{A}\setbox0=\vsplit1 to5pt",
|
|
r"\setbox0=\vsplit1 5pt",
|
|
r"\setbox0=\vsplit-1 to5pt",
|
|
r"\setbox0=\vsplit32768 to5pt",
|
|
r"\marks-1{A}",
|
|
r"\marks32768{A}",
|
|
r"\message{\splitfirstmarks32768}",
|
|
r"\setbox1=\vbox{\hbox{A}\vskip0pt minus1fil\hbox{B}}\setbox0=\vsplit1 to100pt",
|
|
r"\setbox1=\vbox{\hbox{A}}$a^\vsplit1 to5pt$",
|
|
r"\hbox{\discretionary{\mark{A}}{}{}}",
|
|
r"\hbox{\discretionary{}{\marks1{B}}{}}",
|
|
] {
|
|
let s = format!("{FONTS}{SETUP}{body}\\end");
|
|
assert!(native(&s).is_err(), "{body}");
|
|
fs::write(p.join("bad.tex"), s).unwrap();
|
|
let r = Command::new("pdftex")
|
|
.args([
|
|
"-ini",
|
|
"-etex",
|
|
"-interaction=nonstopmode",
|
|
"-halt-on-error",
|
|
"bad.tex",
|
|
])
|
|
.current_dir(&p)
|
|
.output()
|
|
.unwrap();
|
|
assert!(!r.status.success(), "{body}");
|
|
}
|
|
let prefix = format!(
|
|
"{FONTS}{SETUP}\\setbox1=\\vbox{{{}}}",
|
|
(0..80).map(|_| r"\hbox{A}\vskip0pt ").collect::<String>()
|
|
);
|
|
let source = format!(r"{prefix}\setbox0=\vsplit1 to10000pt\end");
|
|
let e = native(&format!(r"{prefix}\end")).unwrap();
|
|
let r = Executor::new(
|
|
State::initex().with_etex(),
|
|
Limits {
|
|
steps: e.steps + 30,
|
|
tokens: 16_000_000,
|
|
..Limits::default()
|
|
},
|
|
)
|
|
.run(
|
|
SourceFile {
|
|
name: "limit.tex".into(),
|
|
data: source.into_bytes(),
|
|
},
|
|
&mut font_world::FontFiles,
|
|
)
|
|
.unwrap_err();
|
|
assert!(r.message.contains("step limit"), "{r:?}");
|
|
for (body, limits, expected) in [
|
|
(
|
|
r"\mark{AAA}\mark{BBB}\mark{CCC}\end",
|
|
Limits {
|
|
tokens: 10,
|
|
steps: 1000,
|
|
..Limits::default()
|
|
},
|
|
"mark token/node capacity",
|
|
),
|
|
(
|
|
r"\setbox1=\vbox{\mark{\noexpand\splitfirstmark}\hbox{}}\setbox0=\vsplit1 to0pt\relax\splitfirstmark\end",
|
|
Limits {
|
|
tokens: 1000,
|
|
steps: 500,
|
|
..Limits::default()
|
|
},
|
|
"step limit",
|
|
),
|
|
] {
|
|
let source = format!("\\catcode123=1\\catcode125=2 {body}");
|
|
let e = Executor::new(State::initex().with_etex(), limits)
|
|
.run(
|
|
SourceFile {
|
|
name: "capacity.tex".into(),
|
|
data: source.into_bytes(),
|
|
},
|
|
&mut font_world::FontFiles,
|
|
)
|
|
.unwrap_err();
|
|
assert!(e.message.contains(expected), "{e:?}");
|
|
}
|
|
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_extracted_and_remaining_geometry_matches_real_dvi_in_tex_sp() {
|
|
let mut cases = Vec::new();
|
|
for height in [-131072, 0, 1, 7 * 65536, 13 * 65536, 30 * 65536] {
|
|
for depth in [-65536, 0, 65536, 3 * 65536] {
|
|
for kind in ["vbox", "vtop", "vbox to40pt", "vbox spread-2pt"] {
|
|
cases.push(format!(r"\splitmaxdepth={depth}sp\splittopskip=10pt plus1fil minus1pt\setbox1=\{kind}{{\moveright2pt\hbox{{g\vrule}}\mark{{H}}\vskip2pt plus1fil\hbox{{Aj}}\penalty0\hrule height1pt depth2pt\kern2pt\vskip1pt minus1pt\mark{{TAIL}}\hbox{{B}}}}\setbox0=\vsplit1 to{height}sp"));
|
|
}
|
|
}
|
|
}
|
|
for height in [0, 5, 12, 20, 30, 100] {
|
|
for body in [
|
|
r"\hsize=30pt\noindent A\mark{ONE} B C D\mark{TWO} E F G H.\par",
|
|
r"\hsize=60pt\noindent A $$x\mark{DISPLAY}+\raise2pt\hbox{g}$$B\par",
|
|
r"\hsize=5pt\overfullrule=2pt\hfuzz=0pt\noindent gj\mark{BAR} B\par",
|
|
r"\hbox{A\mark{ADJUSTED}}\setbox2=\hbox{g\mark{HIDDEN}\vrule}\copy2\hrule height1pt\hbox{B}",
|
|
] {
|
|
cases.push(format!(r"\splitmaxdepth=2pt\splittopskip=9pt\setbox1=\vbox{{{body}}}\setbox0=\vsplit1 to{height}pt"));
|
|
}
|
|
}
|
|
for repeat in 1..=6 {
|
|
cases.push(format!(r"\splitmaxdepth=1pt\splittopskip=10pt\setbox1=\vbox{{\hsize=22pt\noindent A B C D E F\mark{{M}} G H I J K L\par}}{}",r"\setbox0=\vsplit1 to12pt ".repeat(repeat)));
|
|
}
|
|
let p = directory();
|
|
let mut reference = format!(r"{FONTS}{SETUP}\newlinechar=33\pdfoutput=0 ");
|
|
let mut results = Vec::new();
|
|
for (i, body) in cases.iter().enumerate() {
|
|
let mut job = body.clone();
|
|
for reg in [2, 3] {
|
|
job += &format!(
|
|
r"\setbox{reg}=\hbox{{A\copy{}}}\message{{!D{i}-{reg}=\number\wd{reg},\number\ht{reg},\number\dp{reg};!}}",
|
|
reg - 2
|
|
);
|
|
}
|
|
let e = native(&format!(r"{FONTS}{SETUP}\newlinechar=33 {job}\end"))
|
|
.unwrap_or_else(|e| panic!("case {i}: {body}: {e:?}"));
|
|
results.push(e);
|
|
reference += &format!(r"{{{job}\shipout\box2\shipout\box3}} ");
|
|
}
|
|
reference += r"\end";
|
|
fs::write(p.join("probe.tex"), reference).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:?}: {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();
|
|
assert_eq!(pages.as_array().unwrap().len(), 2 * cases.len());
|
|
for (i, e) in results.iter().enumerate() {
|
|
for reg in [2, 3] {
|
|
let b = e.state.box_register(reg).unwrap();
|
|
let context = format!("{p:?}: {i} reg{reg}: {}", cases[i]);
|
|
let dims: Vec<i64> = log
|
|
.split(&format!("D{i}-{reg}="))
|
|
.nth(1)
|
|
.unwrap()
|
|
.split(';')
|
|
.next()
|
|
.unwrap()
|
|
.split(',')
|
|
.map(|n| n.trim().parse().unwrap())
|
|
.collect();
|
|
for (a, b) in [b.width, b.height, b.depth].into_iter().zip(dims) {
|
|
assert!((a - b).abs() <= 1, "{context}: dimension {a} != {b}");
|
|
}
|
|
let page = &pages[2 * i + reg as usize - 2];
|
|
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<Ink> = 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<Ink> = b
|
|
.geometry()
|
|
.unwrap()
|
|
.items
|
|
.into_iter()
|
|
.map(|p| match p.item {
|
|
MathItem::NativeGlyph {
|
|
font, slot, size, ..
|
|
} => Ink::Glyph(font.name.clone(), size, slot, p.x, p.y),
|
|
MathItem::Rule { width, height } => Ink::Rule(p.x, p.y, width, height),
|
|
_ => panic!("legacy font in original split material"),
|
|
})
|
|
.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]
|
|
.into_iter()
|
|
.all(|n| n.abs() <= 1),
|
|
"{context}: {a:?} != {b:?}"
|
|
),
|
|
_ => panic!("{context}: {a:?} != {b:?}"),
|
|
}
|
|
}
|
|
}
|
|
}
|
|
eprintln!(
|
|
"{} actual extracted/remaining DVI pages matched in TeX sp",
|
|
2 * cases.len()
|
|
);
|
|
fs::remove_dir_all(p).unwrap();
|
|
}
|
|
|
|
#[test]
|
|
fn expanded_split_marks_retain_actual_mark_input_contexts() {
|
|
let p = directory();
|
|
let mut cases = Vec::new();
|
|
for limit in [-2, -1, 0, 1, 2, 100] {
|
|
for class in [0, 32767] {
|
|
cases.push(format!(r"\errorcontextlines={limit}\setbox1=\vbox{{\marks{class}{{\noexpand\bad x}}\hbox{{}}}}\setbox0=\vsplit1 to0pt\relax\splitfirstmarks{class}\end"));
|
|
}
|
|
}
|
|
let prefix = r"\errorcontextlines=100\setbox1=\vbox{\mark{\noexpand\bad x}\hbox{}}\setbox0=\vsplit1 to0pt\relax ";
|
|
for action in [
|
|
r"\splitfirstmark",
|
|
r"\let\K=\splitbotmark\def\A{\K\relax}\A",
|
|
r"\message{\splitfirstmark}",
|
|
r"\edef\A{\splitbotmark}",
|
|
] {
|
|
cases.push(format!(r"{prefix}{action}\end"));
|
|
}
|
|
for body in &cases {
|
|
let source = format!("\\catcode123=1\\catcode125=2\\catcode35=6\n{body}\n");
|
|
let e = native(&source).unwrap_err();
|
|
assert!(
|
|
e.message.contains("undefined native control sequence"),
|
|
"{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));
|
|
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, "{body}: {out}");
|
|
}
|
|
eprintln!(
|
|
"{} actual split mark error contexts matched INITEX",
|
|
cases.len()
|
|
);
|
|
fs::remove_dir_all(p).unwrap();
|
|
}
|