use std::fs;
use std::io::Read;
use dom_content_extraction::DensityTree;
use scraper::Html;
fn read_page_from_zip(zip_path: &str, entry: &str) -> String {
let zipfile = fs::File::open(zip_path).expect("html/pages.zip must exist");
let mut archive = zip::ZipArchive::new(zipfile).expect("zip must be valid");
let mut buf = String::new();
let mut file = archive
.by_name(entry)
.unwrap_or_else(|e| panic!("zip entry {entry} must exist: {e}"));
file.read_to_string(&mut buf)
.unwrap_or_else(|e| panic!("reading {entry} failed: {e}"));
buf
}
#[test]
fn theblock_article_excludes_ticker() {
let html = read_page_from_zip(
"html/pages.zip",
"pages/theblock.co-post-402971-scott-bessent-reiterates-no-cbdc.html",
);
let document = Html::parse_document(&html);
let mut dtree = DensityTree::from_document(&document).expect("dtree builds");
dtree.calculate_density_sum().expect("density sum computes");
let article = dtree
.extract_article(&document)
.expect("extract_article succeeds");
assert!(!article.trim().is_empty(), "extracted article is empty");
assert!(
article.contains("Scott Bessent"),
"article body missing 'Scott Bessent':\n{article}"
);
assert!(
article.contains("CBDC"),
"article body missing 'CBDC':\n{article}"
);
assert!(
!article.contains("Latest Crypto News"),
"ticker leaked into extract_article:\n{article}"
);
assert!(
!article.contains("Securitize becomes first to debut shares on NYSE"),
"ticker headline leaked into extract_article:\n{article}"
);
}