From 8c47d6d9ba9ece3445bf34c88f09d776f3ea3dca Mon Sep 17 00:00:00 2001 From: phiresky Date: Mon, 26 Dec 2022 23:26:20 +0100 Subject: [PATCH] adds test for fixes #106 --- exampledir/test/twoblankpages.pdf | Bin 0 -> 4643 bytes src/adapters/custom.rs | 8 +------- src/adapters/postproc.rs | 28 ++++++++++++++++++++++++++++ src/test_utils.rs | 15 ++++++++++++++- 4 files changed, 43 insertions(+), 8 deletions(-) create mode 100644 exampledir/test/twoblankpages.pdf diff --git a/exampledir/test/twoblankpages.pdf b/exampledir/test/twoblankpages.pdf new file mode 100644 index 0000000000000000000000000000000000000000..464779490715eb9a7b39f5e43c4a998f7f9d92cb GIT binary patch literal 4643 zcmcgv-EP}P7Vb3xy~9BP0|^j`9R7+$5Fobe)Y!OnWuq;s=3+#SB*qj+C8;Rct9`@0 z*f-dHk^Rn)ltnsiY;3Ux#?%bYoZs*K@Z|dZVk{=Ub@K23{PSN{Ko04}d$P~fhb&QV zO8LoBMaoB(-@db6zO?K!o$K;uD-%V0XJ*+KSzfD>=Jsq?yj8`jUZ1N(r|O+$H(T;7 z`{yjJ*CZ_aG^?v?Ri5e1Ru`(MX=>Tuscf~b@%Gg#tEx*SH`Z5Q{e$H6afC?^RNNS@rOVs$XuP`puQB z?uf01qYrNSpY3QP_e2Y(tp#%%*dhB?eXLtgp1nInC_Xl`jlUZmx#xFFfW)EZf3mR< z42RCO^`rHsyh(U|ZOjUYUCaNNX z-ZomzhUIcpW~`lkUFzgU0gs21E0t#QGvXSzT^j_Q>7s`0ir8+$sLLABX?_fv!%G+B zCb~Dyyoj zST&Hso+X@`YA_aINMqLxNH~r|u_sW2nvgRQb1k!NtxI%Exoz`=MWf7g1;FhJz}$_d z`=PYOn1q?0Tn|m$Y;a#>ISt$-9p~4-I^j22& z*;StIL&&P%x`NsC-2ca&#^qDrkc$b%QOV`v*5 zsanciUN`UeJf%%WmI&ZVtWERN!_RzV-SpVjka(xc7nI6stUPVUcw40&Tkey688nOZd2YpI}-bxZr_irZ*k=_UpJyRJol&Cezy$K zg1tCI-x&jdbZ2HapmV}00yw1e5rp9xPqKqE4;^-RCZ_061G*r5$S;IuLptn-c8I`xC}SD} zNdpPdC_q!>r!U9DlL;Fm&Hu zMxpRyC-$P{GL8cg2oWjas6+(5|LP?sylA;txRFdlm89W9IZ5n$OFvOz;-~Q|lk=Dy T%GzMpi}AI7a`NpD7uJ6P1{mI; literal 0 HcmV?d00001 diff --git a/src/adapters/custom.rs b/src/adapters/custom.rs index 54bdca8..ec6cd7e 100644 --- a/src/adapters/custom.rs +++ b/src/adapters/custom.rs @@ -21,7 +21,6 @@ use tokio::io::AsyncReadExt; use tokio::process::Child; use tokio::process::Command; - use tokio_util::io::StreamReader; // mostly the same as AdapterMeta + SpawningFileAdapter #[derive(Debug, Deserialize, Serialize, JsonSchema, Default, PartialEq, Clone)] @@ -307,12 +306,7 @@ mod test { #[tokio::test] async fn poppler() -> Result<()> { - let adapter = BUILTIN_SPAWNING_ADAPTERS - .iter() - .find(|e| e.name == "poppler") - .expect("no poppler adapter"); - - let adapter = adapter.to_adapter(); + let adapter = poppler_adapter(); let filepath = test_data_dir().join("short.pdf"); diff --git a/src/adapters/postproc.rs b/src/adapters/postproc.rs index c178ea0..d318ec3 100644 --- a/src/adapters/postproc.rs +++ b/src/adapters/postproc.rs @@ -221,9 +221,13 @@ pub fn postproc_pagebreaks(input: impl AsyncRead + Send) -> impl AsyncRead + Sen #[cfg(test)] mod tests { + use crate::preproc::loop_adapt; + use crate::test_utils::*; + use super::*; use anyhow::Result; use pretty_assertions::assert_eq; + use tokio::fs::File; use tokio::pin; use tokio_test::io::Builder; use tokio_test::io::Mock; @@ -243,6 +247,30 @@ mod tests { ); } + #[tokio::test] + async fn test_pdf_twoblank() -> Result<()> { + let adapter = poppler_adapter(); + let fname = test_data_dir().join("twoblankpages.pdf"); + let rd = File::open(&fname).await?; + let (a, d) = simple_adapt_info(&fname, Box::pin(rd)); + let res = loop_adapt(&adapter, d, a)?; + + let buf = adapted_to_vec(res).await?; + + assert_eq!( + String::from_utf8(buf)?, + "PREFIX:Page 1: +PREFIX:Page 2: +PREFIX:Page 3: HelloWorld +PREFIX:Page 3: +PREFIX:Page 3: +PREFIX:Page 4: +", + ); + + Ok(()) + } + #[tokio::test] async fn test_postproc_prefix() { let mut output: Vec = Vec::new(); diff --git a/src/test_utils.rs b/src/test_utils.rs index 8f45278..a981fc2 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -1,6 +1,9 @@ use crate::{ adapted_iter::AdaptedFilesIterBox, - adapters::{AdaptInfo, ReadBox}, + adapters::{ + custom::{CustomSpawningFileAdapter, BUILTIN_SPAWNING_ADAPTERS}, + AdaptInfo, ReadBox, + }, config::RgaConfig, matching::{FastFileMatcher, FileMatcher}, recurse::concat_read_streams, @@ -41,3 +44,13 @@ pub async fn adapted_to_vec(adapted: AdaptedFilesIterBox) -> Result> { res.read_to_end(&mut buf).await?; Ok(buf) } + +pub fn poppler_adapter() -> CustomSpawningFileAdapter { + let adapter = BUILTIN_SPAWNING_ADAPTERS + .iter() + .find(|e| e.name == "poppler") + .expect("no poppler adapter"); + + let adapter = adapter.to_adapter(); + adapter +}