test(pdf): cover single-chapter preview compile

This commit is contained in:
pj committed 2026-06-20 19:03:46 -04:00
1 parent bfba86a01b
commit 7464665d08
1 file changed
+50
+50
View File
@@ -65,3 +65,53 @@ fn format_source_diagnostics(diagnostics: &[SourceDiagnostic]) -> String {
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join("\n") .join("\n")
} }
#[cfg(test)]
mod tests {
use super::*;
// A faithful single-chapter preview source produced by chapterToPdfInputs
// (preamble #let macros + page numbering reset + opener + body).
const CHAPTER_PREVIEW: &str = r##"#set document(title: "The Lighthouse", author: "")
#set page(
width: 6in + 0.125in,
height: 9in + 0.125in * 2,
margin: (inside: 0.875in, outside: 0.625in + 0.125in, top: 0.8in + 0.125in, bottom: 0.8in + 0.125in),
binding: left,
)
#set text(font: "Literata", size: 11pt, lang: "en", hyphenate: true)
#set par(justify: true, leading: 0.72em, spacing: 0.72em, first-line-indent: (amount: 1.3em, all: false))
#show heading: set text(font: "Literata", weight: "medium")
#show heading.where(level: 1): set text(size: 22pt)
#let scenebreak = align(center)[#v(0.5em) #line(length: 13%, stroke: 0.5pt + rgb("#d6cfbd")) #v(0.5em)]
#let blockquote(body) = pad(left: 1.2em)[#set text(style: "italic", fill: rgb("#6b6458")); #body]
#let chapteropener(num, title) = {
pagebreak(weak: true)
v(2.1in)
align(center)[
#text(font: "Hanken Grotesk", size: 8.5pt, weight: "semibold", tracking: 0.28em)[#upper("Chapter " + num)]
#v(0.7em)
#heading(level: 1, numbering: none, outlined: true)[#title]
]
v(1.5em)
}
#set page(numbering: "1")
#counter(page).update(1)
#chapteropener("1", [The Lighthouse])
The lamp had not been lit in thirty years.
#scenebreak
Morning came the color of pewter.
"##;
#[test]
fn compiles_a_single_chapter_preview() {
let pdf = compile(CHAPTER_PREVIEW.to_string(), &[]).expect("chapter preview should compile");
assert!(pdf.starts_with(b"%PDF"), "output should be a PDF");
}
}