chore: refactor ahead of supporting more conversion types
All checks were successful
Checking Renovate configuration / validate (pull_request) Successful in 1m5s
Build and test / Clippy (pull_request) Successful in 3m25s
Checking yaml / Run yamllint (pull_request) Successful in 11s
Build and test / Tests (pull_request) Successful in 4m12s
Build and test / Build AMD64 (pull_request) Successful in 4m12s
Build and test / Generate Documentation (pull_request) Successful in 3m52s

This commit is contained in:
Marc Plano-Lesay 2025-10-10 16:34:52 +11:00
parent 48b560d85e
commit 034f0b142c
Signed by: kernald
GPG key ID: 66A41B08CC62A6CF
12 changed files with 468 additions and 150 deletions

View file

@ -0,0 +1,40 @@
use std::path::PathBuf;
use cbz2pdf::formats::FormatId;
use cbz2pdf::job::Job;
#[test]
fn detect_from_path_recognizes_extensions() {
let cbz = PathBuf::from("/tmp/book.cbz");
let pdf = PathBuf::from("/tmp/book.pdf");
assert_eq!(FormatId::detect_from_path(&cbz), Some(FormatId::Cbz));
assert_eq!(FormatId::detect_from_path(&pdf), Some(FormatId::Pdf));
assert_eq!(
FormatId::detect_from_path(&PathBuf::from("/tmp/book.txt")),
None
);
}
#[test]
fn job_new_sets_output_extension() {
let input = PathBuf::from("/tmp/book.cbz");
let outdir = PathBuf::from("/tmp");
let job = Job::new(input.clone(), outdir.clone(), FormatId::Cbz, FormatId::Pdf);
assert!(job.output_path.ends_with("book.pdf"));
let job2 = Job::new(
PathBuf::from("/tmp/book.pdf"),
outdir,
FormatId::Pdf,
FormatId::Cbz,
);
assert!(job2.output_path.ends_with("book.cbz"));
}
#[test]
fn format_capabilities_consistent() {
assert!(FormatId::Cbz.can_read());
assert!(!FormatId::Cbz.can_write());
assert!(FormatId::Pdf.can_write());
assert!(!FormatId::Pdf.can_read());
}