Advance native LaTeX execution and preview
This commit is contained in:
1 parent
91f9d76b16
commit
2741546ca8
414 files changed
+99872
-933
No files matched your search
@@ -0,0 +1,169 @@
|
||||
#[path = "support/dvi_shipout.rs"]
|
||||
mod dvi_shipout;
|
||||
#[path = "support/font_world.rs"]
|
||||
mod font_world;
|
||||
|
||||
use std::{fs, path::Path, process::Command};
|
||||
use texrra_tex_core::execution::*;
|
||||
|
||||
#[test]
|
||||
fn shaped_paragraphs_match_pdftex_box_lists_and_raw_paint() {
|
||||
let fixtures = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/parshape");
|
||||
let output = std::env::temp_dir().join(format!("texrra-parshape-{}", std::process::id()));
|
||||
fs::create_dir(&output).unwrap();
|
||||
let mut comparisons = Vec::new();
|
||||
let mut failures = Vec::new();
|
||||
for name in [
|
||||
"repeat-final-entry",
|
||||
"shape-over-hanging-indent",
|
||||
"global-and-scoped",
|
||||
"display-and-resumed-paragraph",
|
||||
"late-size-and-indent",
|
||||
"automatic-breaks",
|
||||
"signed-width",
|
||||
"typed-quantities",
|
||||
] {
|
||||
let case = output.join(name);
|
||||
let source = fs::read_to_string(fixtures.join(format!("{name}.tex"))).unwrap();
|
||||
let reference = dvi_shipout::run_reference(&case, &source, false);
|
||||
let result = Executor::new(State::initex().with_etex(), Limits::default())
|
||||
.with_native_pages()
|
||||
.run(
|
||||
SourceFile {
|
||||
name: "probe.tex".into(),
|
||||
data: source.into_bytes(),
|
||||
},
|
||||
&mut font_world::FontFiles,
|
||||
);
|
||||
let execution = match result {
|
||||
Ok(run) => run,
|
||||
Err(error) => {
|
||||
failures.push(format!("{name}: {error}"));
|
||||
continue;
|
||||
}
|
||||
};
|
||||
assert!(execution.reads.contains(&Dependency::ParagraphShape));
|
||||
let report = execution.events.iter().find_map(|event| match event {
|
||||
Event::ShowBox(report) => Some(report.text.as_str()),
|
||||
_ => None,
|
||||
});
|
||||
let list = report.unwrap_or("");
|
||||
fs::write(case.join("native-box.txt"), list).unwrap();
|
||||
if list.is_empty() || !reference.contains(list) {
|
||||
failures.push(format!("{name}: native box list differs"));
|
||||
}
|
||||
let expected: Vec<_> = reference
|
||||
.match_indices('[')
|
||||
.filter_map(|(start, _)| {
|
||||
let end = start + reference[start..].find(']')?;
|
||||
let message = &reference[start..=end];
|
||||
message.contains('=').then_some(message)
|
||||
})
|
||||
.collect();
|
||||
let actual: Vec<_> = execution
|
||||
.events
|
||||
.iter()
|
||||
.filter_map(|event| match event {
|
||||
Event::Message { text, .. } => Some(text.as_str()),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
if actual != expected {
|
||||
failures.push(format!(
|
||||
"{name}: native messages {actual:?}, expected {expected:?}"
|
||||
));
|
||||
}
|
||||
match dvi_shipout::compare_shipout(&case, execution) {
|
||||
Ok(comparison) => comparisons.push(comparison),
|
||||
Err(error) => failures.push(format!("{name}: {error}")),
|
||||
}
|
||||
}
|
||||
fs::write(
|
||||
output.join("dvi-comparison.json"),
|
||||
serde_json::to_vec_pretty(&comparisons).unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
assert!(failures.is_empty(), "{failures:#?}");
|
||||
assert_eq!(comparisons.len(), 8);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serialized_shape_survives_real_format_reload() {
|
||||
let output =
|
||||
std::env::temp_dir().join(format!("texrra-parshape-format-{}", std::process::id()));
|
||||
fs::create_dir(&output).unwrap();
|
||||
let seed = b"\\catcode123=1\\catcode125=2\n\\parshape2 3pt 33pt -5pt 42pt \\dump\n";
|
||||
let use_shape = concat!(
|
||||
"\\message{[loaded=\\the\\parshape,\\the\\parshapeindent2,\\the\\parshapelength2]}\n",
|
||||
"\\par\\message{[cleared=\\the\\parshape]}\\end\n",
|
||||
)
|
||||
.as_bytes();
|
||||
fs::write(output.join("seed.tex"), seed).unwrap();
|
||||
fs::write(output.join("use.tex"), use_shape).unwrap();
|
||||
for args in [
|
||||
&["-ini", "-etex", "seed.tex"][..],
|
||||
&["-fmt=./seed.fmt", "use.tex"][..],
|
||||
] {
|
||||
let result = Command::new("pdftex")
|
||||
.current_dir(&output)
|
||||
.env_remove("TEXINPUTS")
|
||||
.args([
|
||||
"-interaction=nonstopmode",
|
||||
"-halt-on-error",
|
||||
"-no-shell-escape",
|
||||
])
|
||||
.args(args)
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(
|
||||
result.status.success(),
|
||||
"{}",
|
||||
String::from_utf8_lossy(&result.stdout)
|
||||
);
|
||||
}
|
||||
|
||||
let state = State::initex().with_etex();
|
||||
let bootstrap = Executor::new(state.clone(), Limits::default())
|
||||
.run(
|
||||
SourceFile {
|
||||
name: "seed.tex".into(),
|
||||
data: seed.to_vec(),
|
||||
},
|
||||
&mut NoFiles,
|
||||
)
|
||||
.unwrap();
|
||||
let image = FormatImage::from_dump(bootstrap, Vec::new(), Vec::new())
|
||||
.unwrap()
|
||||
.encode()
|
||||
.unwrap();
|
||||
let job = FormatImage::decode(&image)
|
||||
.unwrap()
|
||||
.new_job(
|
||||
state.profile(),
|
||||
state.input_profile(),
|
||||
JobTime::new(2026, 11, 18, 0).unwrap(),
|
||||
Limits::default(),
|
||||
|_| Ok(seed.to_vec()),
|
||||
)
|
||||
.unwrap()
|
||||
.run(
|
||||
SourceFile {
|
||||
name: "use.tex".into(),
|
||||
data: use_shape.to_vec(),
|
||||
},
|
||||
&mut NoFiles,
|
||||
)
|
||||
.unwrap();
|
||||
let expected = ["[loaded=2,-5.0pt,42.0pt]", "[cleared=0]"];
|
||||
let reference = fs::read_to_string(output.join("use.log")).unwrap();
|
||||
assert!(expected.iter().all(|message| reference.contains(message)));
|
||||
let actual: Vec<_> = job
|
||||
.events
|
||||
.iter()
|
||||
.filter_map(|event| match event {
|
||||
Event::Message { text, .. } => Some(text.as_str()),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
Reference in new issue
Block a user