Files
texrra-engine/crates/texrra-tex-core/tests/execution_vertical_discards.rs
T

112 lines
4.0 KiB
Rust

//! Compare discarded vertical lists and their lifetime with independent INITEX.
use std::{fs, process::Command};
use texrra_tex_core::execution::*;
const PROBE: &str = r#"
\catcode123=1 \catcode125=2 \catcode35=6
\tracingonline=1 \showboxbreadth=100 \showboxdepth=20
\topskip=0pt \splittopskip=0pt \vsize=40pt \vbadness=10000
\def\observe#1{\setbox5=\vbox{#1}\showbox5}
\def\cut{\hrule width7pt height12pt\penalty-10000\relax}
\def\prepare{\setbox1=\vbox{\hrule width1pt height8pt
\penalty-10000 \vskip3pt plus2fil minus1pt \kern5pt
\mark{KEEP} \penalty71 \hrule width2pt height9pt}}
\message{DISCARD-DEFAULT=\the\savingvdiscards}
\savingvdiscards=1
\prepare\setbox2=\vsplit1 to8pt
\showbox1
{\savingvdiscards=0 \observe\splitdiscards}
\observe\splitdiscards
\prepare\setbox2=\vsplit1 to8pt
\setbox2=\vsplit3 to8pt
\observe\splitdiscards
\prepare\setbox2=\vsplit1 to8pt
\savingvdiscards=-1
\prepare\setbox2=\vsplit1 to8pt
\observe\splitdiscards
\savingvdiscards=1
\output{\observe\pagediscards \observe\pagediscards \shipout\box255}
\vskip4pt plus1fil minus2pt \kern5pt \penalty59 \cut
\vskip6pt \cut
\output{\shipout\box255}
\vskip7pt \cut
\observe\pagediscards
\output={}
\vskip8pt \cut
\observe\pagediscards
\prepare\setbox2=\vsplit1 to8pt
\output{\observe\pagediscards \observe\splitdiscards \shipout\box255}
\vskip9pt \cut
\observe\splitdiscards
\end
"#;
struct NoFiles;
impl SourceProvider for NoFiles {
fn read(&mut self, name: &str, _: &str) -> Result<SourceFile, String> {
Err(format!("unexpected input {name}"))
}
}
#[test]
fn vertical_discards_transfer_once_and_expire_at_the_reference_boundaries() {
let dir = std::env::temp_dir().join(format!("texrra-vertical-discards-{}", std::process::id()));
fs::create_dir_all(&dir).unwrap();
fs::write(dir.join("probe.tex"), PROBE).unwrap();
let reference = Command::new("pdftex")
.args(["-ini", "-etex", "-interaction=nonstopmode", "probe.tex"])
.current_dir(&dir)
.output()
.unwrap();
let log = fs::read_to_string(dir.join("probe.log")).unwrap();
assert_eq!(reference.status.code(), Some(1), "{log}");
for line in log.lines().filter(|line| line.starts_with("! ")) {
assert_eq!(line, "! OK.", "{log}");
}
assert!(log.contains("DISCARD-DEFAULT=0"), "{log}");
let expected: Vec<_> = log
.split("> \\box")
.skip(1)
.map(|text| format!("> \\box{}", text.split("! OK.").next().unwrap().trim_end()))
.collect();
assert_eq!(expected.len(), 14, "{log}");
assert!(expected[1].contains("glue 3.0 plus 2.0fil minus 1.0"));
assert!(expected[1].contains("kern 5.0") && expected[1].contains("penalty 71"));
assert!(expected[5].contains("glue 4.0 plus 1.0fil minus 2.0"));
assert!(expected[5].contains("kern 5.0") && expected[5].contains("penalty 59"));
for profile in [InputProfile::TeX8Bit, InputProfile::UnicodeScalar] {
let state = State::initex().with_etex().with_input_profile(profile);
let native = Executor::new(state, Limits::default())
.with_native_pages()
.run(
SourceFile {
name: "probe.tex".into(),
data: PROBE.as_bytes().to_vec(),
},
&mut NoFiles,
)
.unwrap();
let actual: Vec<_> = native
.events
.iter()
.filter_map(|event| match event {
Event::ShowBox(report) => Some(report.text.trim_end()),
_ => None,
})
.collect();
assert_eq!(actual, expected, "{profile:?}");
assert!(native.events.iter().any(|event| {
matches!(event, Event::Message { text, .. } if text == "DISCARD-DEFAULT=0")
}));
assert!(
native
.reads
.contains(&Dependency::Parameter(Parameter::Savingvdiscards))
);
assert!(native.reads.contains(&Dependency::SplitDiscards));
assert!(native.reads.contains(&Dependency::PageState));
}
fs::remove_dir_all(dir).unwrap();
}