#![cfg(feature = "html")]
use std::collections::BTreeMap;
use printpdf::{GeneratePdfOptions, PdfDocument};
#[test]
fn text_with_characters_xml_excludes_gives_pages_or_an_error() {
for bad in ["\u{0}", "\u{8}", "\u{B}", "\u{C}", "\u{1F}", "\u{FFFE}", "\u{FFFF}"] {
let html = format!("<html><body><p>before{bad}after</p></body></html>");
let mut warnings = Vec::new();
match PdfDocument::from_html(
&html,
&BTreeMap::new(),
&BTreeMap::new(),
&GeneratePdfOptions::default(),
&mut warnings,
) {
Ok(doc) => assert!(
!doc.pages.is_empty(),
"{bad:?}: Ok with no pages (warnings: {warnings:?})"
),
Err(msg) => assert!(!msg.is_empty(), "{bad:?}: an Err with no message"),
}
}
}
#[test]
fn plain_html_still_gives_a_page() {
let mut warnings = Vec::new();
let doc = PdfDocument::from_html(
"<html><body><p>hello</p></body></html>",
&BTreeMap::new(),
&BTreeMap::new(),
&GeneratePdfOptions::default(),
&mut warnings,
)
.expect("from_html");
assert!(!doc.pages.is_empty());
}