#![cfg(feature = "ml")]
#[test]
fn text_layer_matches_no_ocr() {
let bytes = std::fs::read(concat!(
env!("CARGO_MANIFEST_DIR"),
"/../../tests/data/pdf/sources/code_and_formula.pdf"
))
.expect("corpus pdf");
if std::env::var("PDFIUM_DYNAMIC_LIB_PATH").is_err() {
std::env::set_var(
"PDFIUM_DYNAMIC_LIB_PATH",
concat!(env!("CARGO_MANIFEST_DIR"), "/../../.pdfium/lib"),
);
}
let text_layer = docling_pdf::convert_text_layer(&bytes, "code_and_formula.pdf")
.expect("text-layer conversion");
let no_ocr = match docling_pdf::convert_with_options(
&bytes,
None,
"code_and_formula.pdf",
true, true, false, docling_pdf::EnrichmentOptions::default(),
None,
None,
) {
Ok(doc) => doc,
Err(docling_pdf::PdfError::Pdfium(e)) if e.contains("LoadLibraryError") => {
eprintln!("skipping equivalence check: pdfium unavailable ({e})");
return;
}
Err(e) => panic!("no_ocr conversion: {e:?}"),
};
let a = text_layer.export_to_markdown();
assert!(!a.trim().is_empty(), "text layer should extract");
assert_eq!(a, no_ocr.export_to_markdown());
}
#[test]
fn scanned_pdf_yields_empty_document() {
let doc = docling_pdf::convert_text_layer(b"%PDF-1.4\n%%EOF", "scan.pdf").expect("no error");
assert!(doc.nodes.is_empty());
}