use pter::convert; #[test] fn empty_string() { assert_eq!(convert(""), ""); } #[test] fn whitespace_only() { assert_eq!(convert(" \n\t "), ""); } #[test] fn just_tags_no_content() { assert_eq!(convert("
"); } html.push_str("very deep"); for _ in 0..20 { html.push_str(""); } let md = convert(&html); assert!(md.contains("very deep")); // Should have many > prefixes assert!(md.contains("> > > > >")); } #[test] fn deeply_nested_lists() { let mut html = String::new(); for _ in 0..10 { html.push_str("
unclosed paragraph
another one");
assert!(md.contains("unclosed paragraph"));
assert!(md.contains("another one"));
}
#[test]
fn malformed_mismatched_tags() {
let md = convert("crossed");
assert!(md.contains("crossed"));
}
#[test]
fn only_script_content() {
assert_eq!(convert(""), "");
}
#[test]
fn only_style_content() {
assert_eq!(convert(""), "");
}
#[test]
fn only_tracking_pixels() {
let html = r#"
"#;
assert_eq!(convert(html), "");
}
#[test]
fn unicode_content() {
let md = convert("
日本語テスト 🎉 émojis café
"); assert!(md.contains("日本語テスト")); assert!(md.contains("🎉")); assert!(md.contains("café")); } #[test] fn html_entities_numeric() { let md = convert("© — ’
"); assert!(md.contains("©")); assert!(md.contains("—")); } #[test] fn large_input_doesnt_blow_up() { let para = "Hello world. This is a test paragraph with some content.
"; let html: String = para.repeat(1000); let md = convert(&html); assert!(md.contains("Hello world")); // Should be proportional, not quadratic assert!(md.len() < html.len()); } #[test] fn link_with_nested_formatting() { let html = r#"bold link"#; let md = convert(html); assert!(md.contains("[**bold link**](https://example.com)")); } #[test] fn image_with_no_alt() { let md = convert(r#"
"#);
assert!(md.contains(""));
}
#[test]
fn consecutive_inline_elements() {
let md = convert("bolditaliccode");
assert_eq!(md, "**bold***italic*`code`");
}
#[test]
fn table_with_empty_cells() {
let html = "| A | B |
|---|---|
| val |
<div>not a tag</div>"; let md = convert(html); assert!(md.contains("```")); assert!(md.contains("
word1 word2 word3
"); assert_eq!(md, "word1 word2 word3"); } #[test] fn newlines_in_source_collapsed() { let md = convert("line1\n\n\nline2
"); assert_eq!(md, "line1 line2"); } #[test] fn full_html_document() { let html = r#"Hello!
"#; let md = convert(html); assert_eq!(md, "Hello!"); } #[test] fn data_uri_image_not_tracking_pixel() { // A data URI image that's not 1x1 should render let html = r#""; let md = convert(html); assert!(md.contains("> First para")); assert!(md.contains("> ")); assert!(md.contains("> Second para")); }First para
Second para