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("

"), ""); } #[test] fn deeply_nested_divs() { let mut html = String::new(); for _ in 0..100 { html.push_str("
"); } html.push_str("deep content"); for _ in 0..100 { html.push_str("
"); } let md = convert(&html); assert!(md.contains("deep content")); } #[test] fn deeply_nested_blockquotes() { let mut html = String::new(); for _ in 0..20 { html.push_str("
"); } 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(""); } let md = convert(&html); assert!(md.contains("deep item")); } #[test] fn malformed_unclosed_tags() { // html5ever auto-corrects these let md = convert("

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("![](photo.jpg)")); } #[test] fn consecutive_inline_elements() { let md = convert("bolditaliccode"); assert_eq!(md, "**bold***italic*`code`"); } #[test] fn table_with_empty_cells() { let html = "\
AB
val
"; let md = convert(html); assert!(md.contains("| A | B |")); assert!(md.contains("| | val |")); } #[test] fn pre_with_html_inside() { let html = "
<div>not a tag</div>
"; let md = convert(html); assert!(md.contains("```")); assert!(md.contains("
not a tag
")); } #[test] fn multiple_spaces_in_source() { let md = convert("

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#" Test Email

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#"inline"#; let md = convert(html); assert!(md.contains("![inline]")); } #[test] fn blockquote_with_paragraphs() { let html = "

First para

Second para

"; let md = convert(html); assert!(md.contains("> First para")); assert!(md.contains("> ")); assert!(md.contains("> Second para")); }