Expand input files in project PDF exports
This commit is contained in:
1 parent
a5da5c9521
commit
6a4483cf4d
5 files changed
+65
-13
No files matched your search
@@ -276,6 +276,53 @@ fn project_preview_expands_included_files() {
|
||||
assert!(svg.contains(">B</text>"), "{svg}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn project_pdf_expands_included_files() {
|
||||
let server = TestServer::start("route-d-input-pdf");
|
||||
let section = server.request(
|
||||
"PUT",
|
||||
"/api/projects/hello/file?path=section.tex",
|
||||
b"ZXQ included.",
|
||||
"text/plain; charset=utf-8",
|
||||
);
|
||||
assert_eq!(section.status, 200, "{}", section.text());
|
||||
let main = "\\documentclass{article}\n\\begin{document}\nBefore.\n\\input{section}\nAfter.\n\\end{document}\n";
|
||||
let put = server.request(
|
||||
"PUT",
|
||||
"/api/projects/hello/file?path=hello.tex",
|
||||
main.as_bytes(),
|
||||
"text/plain; charset=utf-8",
|
||||
);
|
||||
assert_eq!(put.status, 200, "{}", put.text());
|
||||
let pdf = server.request(
|
||||
"POST",
|
||||
"/api/projects/hello/pdf?engine=route-d",
|
||||
&[],
|
||||
"application/pdf",
|
||||
);
|
||||
assert_eq!(pdf.status, 200, "{}", String::from_utf8_lossy(&pdf.body));
|
||||
assert!(pdf.body.starts_with(b"%PDF-"), "missing PDF header");
|
||||
|
||||
let path = std::env::temp_dir().join(format!("texrra-input-{}.pdf", std::process::id()));
|
||||
if std::fs::write(&path, &pdf.body).is_err() {
|
||||
return;
|
||||
}
|
||||
let output = std::process::Command::new("pdftotext")
|
||||
.arg(&path)
|
||||
.arg("-")
|
||||
.output();
|
||||
let _ = std::fs::remove_file(&path);
|
||||
let Ok(output) = output else {
|
||||
return;
|
||||
};
|
||||
if !output.status.success() {
|
||||
return;
|
||||
}
|
||||
let text = String::from_utf8_lossy(&output.stdout);
|
||||
assert!(text.contains("ZXQ"), "{text}");
|
||||
assert!(text.contains("Before."), "{text}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn serves_project_api_preview_and_pdf() {
|
||||
let server = TestServer::start("api");
|
||||
|
||||
Reference in new issue
Block a user