mirror of
https://github.com/FliegendeWurst/ripgrep-all.git
synced 2024-11-24 12:24:56 +00:00
adds test for fixes #106
This commit is contained in:
parent
82b303bb3d
commit
8c47d6d9ba
BIN
exampledir/test/twoblankpages.pdf
Normal file
BIN
exampledir/test/twoblankpages.pdf
Normal file
Binary file not shown.
@ -21,7 +21,6 @@ use tokio::io::AsyncReadExt;
|
|||||||
use tokio::process::Child;
|
use tokio::process::Child;
|
||||||
use tokio::process::Command;
|
use tokio::process::Command;
|
||||||
|
|
||||||
|
|
||||||
use tokio_util::io::StreamReader;
|
use tokio_util::io::StreamReader;
|
||||||
// mostly the same as AdapterMeta + SpawningFileAdapter
|
// mostly the same as AdapterMeta + SpawningFileAdapter
|
||||||
#[derive(Debug, Deserialize, Serialize, JsonSchema, Default, PartialEq, Clone)]
|
#[derive(Debug, Deserialize, Serialize, JsonSchema, Default, PartialEq, Clone)]
|
||||||
@ -307,12 +306,7 @@ mod test {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn poppler() -> Result<()> {
|
async fn poppler() -> Result<()> {
|
||||||
let adapter = BUILTIN_SPAWNING_ADAPTERS
|
let adapter = poppler_adapter();
|
||||||
.iter()
|
|
||||||
.find(|e| e.name == "poppler")
|
|
||||||
.expect("no poppler adapter");
|
|
||||||
|
|
||||||
let adapter = adapter.to_adapter();
|
|
||||||
|
|
||||||
let filepath = test_data_dir().join("short.pdf");
|
let filepath = test_data_dir().join("short.pdf");
|
||||||
|
|
||||||
|
@ -221,9 +221,13 @@ pub fn postproc_pagebreaks(input: impl AsyncRead + Send) -> impl AsyncRead + Sen
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
|
use crate::preproc::loop_adapt;
|
||||||
|
use crate::test_utils::*;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
|
use tokio::fs::File;
|
||||||
use tokio::pin;
|
use tokio::pin;
|
||||||
use tokio_test::io::Builder;
|
use tokio_test::io::Builder;
|
||||||
use tokio_test::io::Mock;
|
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]
|
#[tokio::test]
|
||||||
async fn test_postproc_prefix() {
|
async fn test_postproc_prefix() {
|
||||||
let mut output: Vec<u8> = Vec::new();
|
let mut output: Vec<u8> = Vec::new();
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
adapted_iter::AdaptedFilesIterBox,
|
adapted_iter::AdaptedFilesIterBox,
|
||||||
adapters::{AdaptInfo, ReadBox},
|
adapters::{
|
||||||
|
custom::{CustomSpawningFileAdapter, BUILTIN_SPAWNING_ADAPTERS},
|
||||||
|
AdaptInfo, ReadBox,
|
||||||
|
},
|
||||||
config::RgaConfig,
|
config::RgaConfig,
|
||||||
matching::{FastFileMatcher, FileMatcher},
|
matching::{FastFileMatcher, FileMatcher},
|
||||||
recurse::concat_read_streams,
|
recurse::concat_read_streams,
|
||||||
@ -41,3 +44,13 @@ pub async fn adapted_to_vec(adapted: AdaptedFilesIterBox) -> Result<Vec<u8>> {
|
|||||||
res.read_to_end(&mut buf).await?;
|
res.read_to_end(&mut buf).await?;
|
||||||
Ok(buf)
|
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user