mirror of
https://github.com/priyanshujain/margin.git
synced 2026-10-02 19:17:03 +00:00
chore: remove in-code tests
This commit is contained in:
1 parent
7464665d08
commit
be252c6b21
2 files changed
-115
No files matched your search
@@ -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");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user