chore: remove in-code tests

This commit is contained in:
pj committed 2026-06-20 19:06:10 -04:00
1 parent 7464665d08
commit be252c6b21
2 files changed
-115

No files matched your search

-65
View File
@@ -97,68 +97,3 @@ pub fn unzip_epub(path: String) -> Result<Vec<EpubFile>, String> {
let bytes = std::fs::read(&path).map_err(|e| format!("failed to read \"{path}\": {e}"))?;
unzip(&bytes)
}
#[cfg(test)]
mod tests {
use super::*;
fn text(path: &str, data: &str) -> EpubFile {
EpubFile {
path: path.into(),
data: data.into(),
encoding: "utf8".into(),
}
}
#[test]
fn round_trips_through_build_and_unzip() {
let png = STANDARD.encode([0x89, 0x50, 0x4e, 0x47]);
let input = vec![
text("mimetype", "application/epub+zip"),
text("META-INF/container.xml", "<container/>"),
text("OEBPS/chapter-1.xhtml", "<html>café</html>"),
EpubFile {
path: "OEBPS/assets/figure-1.png".into(),
data: png.clone(),
encoding: "base64".into(),
},
];
let zipped = build(&input).expect("build");
let out = unzip(&zipped).expect("unzip");
let find = |p: &str| out.iter().find(|f| f.path == p).expect(p);
assert_eq!(find("mimetype").data, "application/epub+zip");
let chapter = find("OEBPS/chapter-1.xhtml");
assert_eq!(chapter.encoding, "utf8");
assert_eq!(chapter.data, "<html>café</html>");
let figure = find("OEBPS/assets/figure-1.png");
assert_eq!(figure.encoding, "base64");
assert_eq!(figure.data, png);
// Fonts are embedded by build() and must come back as base64 binary.
assert_eq!(find("OEBPS/fonts/Literata-VF.ttf").encoding, "base64");
}
#[test]
fn unzip_epub_reads_a_file_from_disk() {
let zipped = build(&[
text("mimetype", "application/epub+zip"),
text("OEBPS/chapter-1.xhtml", "<p>hi</p>"),
])
.expect("build");
let mut path = std::env::temp_dir();
path.push("margin-unzip-test.epub");
std::fs::write(&path, &zipped).expect("write");
let out = unzip_epub(path.to_string_lossy().to_string()).expect("unzip_epub");
let _ = std::fs::remove_file(&path);
let chapter = out
.iter()
.find(|f| f.path == "OEBPS/chapter-1.xhtml")
.expect("chapter present");
assert_eq!(chapter.data, "<p>hi</p>");
assert_eq!(chapter.encoding, "utf8");
}
}
-50
View File
@@ -65,53 +65,3 @@ fn format_source_diagnostics(diagnostics: &[SourceDiagnostic]) -> String {
.collect::<Vec<_>>()
.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");
}
}