Implement native PDF links and vertical discard lists
This commit is contained in:
1 parent
b6567f67e2
commit
a53d9c9bf9
29 files changed
+980
-109
No files matched your search
@@ -246,7 +246,7 @@ fn genuine_fraction_primitives_and_retained_boxes_survive_format_roundtrip() {
|
||||
let envelope: serde_json::Value = serde_json::from_slice(&bytes).unwrap();
|
||||
let payload: serde_json::Value =
|
||||
serde_json::from_str(envelope["payload"].as_str().unwrap()).unwrap();
|
||||
assert_eq!(payload["schema"], 20);
|
||||
assert_eq!(payload["schema"], 22);
|
||||
let state = State::initex().with_etex();
|
||||
let loaded = FormatImage::decode(&bytes)
|
||||
.unwrap()
|
||||
|
||||
@@ -334,7 +334,7 @@ fn old_schema_and_missing_unicode_state_are_rejected_even_with_valid_checksums()
|
||||
let envelope: serde_json::Value = serde_json::from_slice(&encoded).unwrap();
|
||||
let original: serde_json::Value =
|
||||
serde_json::from_str(envelope["payload"].as_str().unwrap()).unwrap();
|
||||
assert_eq!(original["schema"], 20);
|
||||
assert_eq!(original["schema"], 22);
|
||||
for (schema, expected) in [
|
||||
(1, "incompatible native format"),
|
||||
(2, "incompatible native format"),
|
||||
@@ -355,7 +355,9 @@ fn old_schema_and_missing_unicode_state_are_rejected_even_with_valid_checksums()
|
||||
(17, "incompatible native format"),
|
||||
(18, "incompatible native format"),
|
||||
(19, "incompatible native format"),
|
||||
(20, "glyph_unicode"),
|
||||
(20, "incompatible native format"),
|
||||
(21, "incompatible native format"),
|
||||
(22, "glyph_unicode"),
|
||||
] {
|
||||
let mut payload = original.clone();
|
||||
payload["schema"] = schema.into();
|
||||
|
||||
@@ -77,6 +77,35 @@ fn quantity_scopes_aliases_state_reads_and_snapshot_restore() {
|
||||
assert_eq!(messages(&e), ["0.0pt"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shorthand_definition_binds_relax_during_the_operand_scan() {
|
||||
let source = include_str!("fixtures/shorthand/self-referencing.tex");
|
||||
let native = run(source);
|
||||
let directory = std::env::temp_dir().join(format!("texrra-shorthand-{}", std::process::id()));
|
||||
fs::create_dir_all(&directory).unwrap();
|
||||
fs::write(directory.join("probe.tex"), source).unwrap();
|
||||
let output = Command::new("pdftex")
|
||||
.args([
|
||||
"-ini",
|
||||
"-etex",
|
||||
"-interaction=nonstopmode",
|
||||
"-halt-on-error",
|
||||
"probe.tex",
|
||||
])
|
||||
.current_dir(&directory)
|
||||
.output()
|
||||
.unwrap();
|
||||
let reference = fs::read_to_string(directory.join("probe.log")).unwrap();
|
||||
assert!(output.status.success(), "{reference}");
|
||||
let expected: Vec<_> = reference
|
||||
.match_indices("SHORTHAND-")
|
||||
.map(|(start, _)| reference[start..].split_inclusive(']').next().unwrap())
|
||||
.collect();
|
||||
assert_eq!(expected.len(), 6, "{reference}");
|
||||
assert_eq!(messages(&native), expected);
|
||||
fs::remove_dir_all(directory).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_quantities_overflows_units_and_readonly_positions_fail() {
|
||||
let relative = run(r"\dimen0=1em");
|
||||
|
||||
@@ -164,7 +164,7 @@ fn new_format_owns_vcenter_and_boxed_math_without_reinjecting_old_meanings() {
|
||||
let envelope: serde_json::Value = serde_json::from_slice(&bytes).unwrap();
|
||||
let payload: serde_json::Value =
|
||||
serde_json::from_str(envelope["payload"].as_str().unwrap()).unwrap();
|
||||
assert_eq!(payload["schema"], 20);
|
||||
assert_eq!(payload["schema"], 22);
|
||||
let executor = FormatImage::decode(&bytes)
|
||||
.unwrap()
|
||||
.new_job(
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
//! 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();
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
\catcode123=1 \catcode125=2
|
||||
\toksdef\slot=0\slot={FIRST}
|
||||
\message{SHORTHAND-FIRST=[\the\slot]}
|
||||
{\toksdef\slot=1\slot={LOCAL}\message{SHORTHAND-LOCAL=[\the\slot]}}
|
||||
\message{SHORTHAND-RESTORED=[\the\slot]}
|
||||
\def\slot{8}
|
||||
\toksdef\slot=9\slot={REBOUND}
|
||||
\message{SHORTHAND-REBOUND=[\the\slot|\the\toks9]}
|
||||
{\global\toksdef\slot=32767\global\slot={EXTENDED}}
|
||||
\message{SHORTHAND-GLOBAL=[\the\slot|\the\toks32767]}
|
||||
\countdef\amount=7\amount=37
|
||||
\dimendef\length=8\length=3pt
|
||||
\skipdef\spaceamount=9\spaceamount=1pt plus2fil
|
||||
\muskipdef\mathspace=10\mathspace=2mu
|
||||
\message{SHORTHAND-REGS=[\the\amount|\the\length|\the\spaceamount|\the\mathspace]}
|
||||
\end
|
||||
Reference in new issue
Block a user