Skip to content

A fast, helpful, and open-source document parser

chore: some perfs for tests and clippy fixes

Clelia (Astra) Bertelli9f2662405839
diff --git a/crates/liteparse/src/conversion.rs b/crates/liteparse/src/conversion.rs
index c988081..4df6b27 100644
--- a/crates/liteparse/src/conversion.rs
+++ b/crates/liteparse/src/conversion.rs
@@ -518,10 +518,10 @@ mod tests {
fn test_is_windows_system_convert() {
// SAFETY: tests run single-threaded for env modification scope
unsafe { std::env::set_var("SystemRoot", "C:\\Windows") };
- assert!(is_windows_system_convert("C:\\Windows\\System32\\convert.exe"));
assert!(is_windows_system_convert(
- "C:/Windows/System32/convert.exe"
+ "C:\\Windows\\System32\\convert.exe"
));
+ assert!(is_windows_system_convert("C:/Windows/System32/convert.exe"));
assert!(!is_windows_system_convert(
"C:\\Program Files\\ImageMagick\\convert.exe"
));
@@ -530,7 +530,10 @@ mod tests {
#[test]
fn test_guess_extension_from_data_png() {
let png_header = [0x89, b'P', b'N', b'G', 0x0D, 0x0A, 0x1A, 0x0A];
- assert_eq!(guess_extension_from_data(&png_header).as_deref(), Some("png"));
+ assert_eq!(
+ guess_extension_from_data(&png_header).as_deref(),
+ Some("png")
+ );
}
#[test]
diff --git a/crates/liteparse/src/extract.rs b/crates/liteparse/src/extract.rs
index 37bdca4..016ec1b 100644
--- a/crates/liteparse/src/extract.rs
+++ b/crates/liteparse/src/extract.rs
@@ -715,7 +715,10 @@ mod tests {
#[test]
fn dedup_drops_earlier_exact_duplicate() {
- let mut items = vec![ti("hello", 0.0, 0.0, 10.0, 5.0), ti("hello", 1.0, 0.0, 10.0, 5.0)];
+ let mut items = vec![
+ ti("hello", 0.0, 0.0, 10.0, 5.0),
+ ti("hello", 1.0, 0.0, 10.0, 5.0),
+ ];
dedup_overlapping_items(&mut items);
assert_eq!(items.len(), 1);
assert_eq!(items[0].x, 1.0);
@@ -730,7 +733,10 @@ mod tests {
#[test]
fn dedup_drops_earlier_when_different_text_overlaps_heavily() {
- let mut items = vec![ti("old", 0.0, 0.0, 10.0, 5.0), ti("new", 0.0, 0.0, 10.0, 5.0)];
+ let mut items = vec![
+ ti("old", 0.0, 0.0, 10.0, 5.0),
+ ti("new", 0.0, 0.0, 10.0, 5.0),
+ ];
dedup_overlapping_items(&mut items);
assert_eq!(items.len(), 1);
assert_eq!(items[0].text, "new");
@@ -738,7 +744,10 @@ mod tests {
#[test]
fn dedup_keeps_both_when_different_text_overlaps_lightly() {
- let mut items = vec![ti("aaa", 0.0, 0.0, 10.0, 5.0), ti("bbb", 9.0, 0.0, 10.0, 5.0)];
+ let mut items = vec![
+ ti("aaa", 0.0, 0.0, 10.0, 5.0),
+ ti("bbb", 9.0, 0.0, 10.0, 5.0),
+ ];
dedup_overlapping_items(&mut items);
assert_eq!(items.len(), 2);
}
@@ -767,12 +776,19 @@ mod tests {
#[test]
fn adjust_angle_wraps_into_0_2pi() {
let r = adjust_angle_for_rotation(0.0, 1);
- assert!(r >= 0.0 && r < 2.0 * PI);
+ assert!((0.0..2.0 * PI).contains(&r));
}
#[test]
fn decompose_scale_identity() {
- let m = pdfium::Matrix { a: 1.0, b: 0.0, c: 0.0, d: 1.0, e: 0.0, f: 0.0 };
+ let m = pdfium::Matrix {
+ a: 1.0,
+ b: 0.0,
+ c: 0.0,
+ d: 1.0,
+ e: 0.0,
+ f: 0.0,
+ };
let (sx, sy) = decompose_scale(&m);
assert!((sx - 1.0).abs() < 1e-5);
assert!((sy - 1.0).abs() < 1e-5);
@@ -780,7 +796,14 @@ mod tests {
#[test]
fn decompose_scale_uniform() {
- let m = pdfium::Matrix { a: 2.0, b: 0.0, c: 0.0, d: 2.0, e: 0.0, f: 0.0 };
+ let m = pdfium::Matrix {
+ a: 2.0,
+ b: 0.0,
+ c: 0.0,
+ d: 2.0,
+ e: 0.0,
+ f: 0.0,
+ };
let (sx, sy) = decompose_scale(&m);
assert!((sx - 2.0).abs() < 1e-4);
assert!((sy - 2.0).abs() < 1e-4);
@@ -813,9 +836,19 @@ mod tests {
#[test]
fn color_to_argb_hex_formats() {
- let c = pdfium::Color { r: 0xAB, g: 0xCD, b: 0xEF, a: 0x12 };
+ let c = pdfium::Color {
+ r: 0xAB,
+ g: 0xCD,
+ b: 0xEF,
+ a: 0x12,
+ };
assert_eq!(color_to_argb_hex(&c), "12abcdef");
- let z = pdfium::Color { r: 0, g: 0, b: 0, a: 0 };
+ let z = pdfium::Color {
+ r: 0,
+ g: 0,
+ b: 0,
+ a: 0,
+ };
assert_eq!(color_to_argb_hex(&z), "00000000");
}
diff --git a/crates/liteparse/src/ocr/mod.rs b/crates/liteparse/src/ocr/mod.rs
index 4deea01..94db421 100644
--- a/crates/liteparse/src/ocr/mod.rs
+++ b/crates/liteparse/src/ocr/mod.rs
@@ -63,16 +63,4 @@ mod tests {
assert_eq!(r[0].bbox, [0.0, 0.0, 10.0, 10.0]);
assert!((r[0].confidence - 0.9).abs() < 1e-6);
}
-
- #[test]
- fn test_ocr_result_clone() {
- let r = OcrResult {
- text: "hi".into(),
- bbox: [1.0, 2.0, 3.0, 4.0],
- confidence: 0.5,
- };
- let c = r.clone();
- assert_eq!(c.text, "hi");
- assert_eq!(c.bbox, [1.0, 2.0, 3.0, 4.0]);
- }
}
diff --git a/crates/liteparse/src/parser.rs b/crates/liteparse/src/parser.rs
index 0f3516a..34b016c 100644
--- a/crates/liteparse/src/parser.rs
+++ b/crates/liteparse/src/parser.rs
@@ -134,6 +134,7 @@ mod tests {
use crate::types::ParsedPage;
#[test]
+ #[allow(clippy::field_reassign_with_default)]
fn test_new_stores_config() {
let mut cfg = LiteParseConfig::default();
cfg.ocr_enabled = false;
@@ -157,6 +158,7 @@ mod tests {
}
#[test]
+ #[allow(clippy::field_reassign_with_default)]
fn test_format_json() {
let mut cfg = LiteParseConfig::default();
cfg.output_format = OutputFormat::Json;
@@ -167,6 +169,7 @@ mod tests {
}
#[test]
+ #[allow(clippy::field_reassign_with_default)]
fn test_format_text() {
let mut cfg = LiteParseConfig::default();
cfg.output_format = OutputFormat::Text;
diff --git a/crates/liteparse/src/render.rs b/crates/liteparse/src/render.rs
index 642b1bf..82548c6 100644
--- a/crates/liteparse/src/render.rs
+++ b/crates/liteparse/src/render.rs
@@ -118,7 +118,12 @@ mod tests {
#[test]
fn test_screenshot_missing_file_errors() {
- let r = screenshot("/nonexistent/path/does_not_exist.pdf", 1, 72.0, "/tmp/out.png");
+ let r = screenshot(
+ "/nonexistent/path/does_not_exist.pdf",
+ 1,
+ 72.0,
+ "/tmp/out.png",
+ );
assert!(r.is_err());
}
diff --git a/crates/liteparse/src/types.rs b/crates/liteparse/src/types.rs
index 8407c83..5f01b28 100644
--- a/crates/liteparse/src/types.rs
+++ b/crates/liteparse/src/types.rs
@@ -144,8 +144,14 @@ mod tests {
#[test]
fn output_format_serializes() {
- assert_eq!(serde_json::to_string(&OutputFormat::Json).unwrap(), "\"Json\"");
- assert_eq!(serde_json::to_string(&OutputFormat::Text).unwrap(), "\"Text\"");
+ assert_eq!(
+ serde_json::to_string(&OutputFormat::Json).unwrap(),
+ "\"Json\""
+ );
+ assert_eq!(
+ serde_json::to_string(&OutputFormat::Text).unwrap(),
+ "\"Text\""
+ );
}
#[test]
diff --git a/crates/pdfium/src/bitmap.rs b/crates/pdfium/src/bitmap.rs
index 1f96bd3..2039197 100644
--- a/crates/pdfium/src/bitmap.rs
+++ b/crates/pdfium/src/bitmap.rs
@@ -56,6 +56,7 @@ impl Bitmap {
width,
height,
// necessary for windows -> expected `u32`, found `u64`
+ #[allow(clippy::useless_conversion)]
color.try_into().unwrap(),
);
}