package articlecontent import ( "fmt" "strings" "testing" "github.com/tradarr/backend/internal/scraper" ) func TestCandidateLengthUnicodeBucketsAndExcludedText(t *testing.T) { for _, source := range []string{"yahoo_finance", "cnbc_business"} { pages := map[string]string{} root, base := "caas-body", "https://finance.yahoo.com/news/fixture-" if source == "cnbc_business" { root = "ArticleBody-articleBody" base = "https://www.cnbc.com/2026/02/01/fixture-" } for i, n := range []int{0, 1, 500, 501, 2000, 2001} { target := fmt.Sprintf("%s%d.html", base, i) pages[target] = `

` + strings.Repeat("界", n) + `

Excluded skeleton
Excluded placeholder

Excluded outside text

` } m := fetchMetricsForFixturePages(t, source, pages) if !m.CandidateBodySupported || m.CandidateLength != (scraper.LengthCounts{Zero: 1, Small: 2, Medium: 2, Large: 1}) || m.Length.Zero != 6 || m.Content.Unavailable != 6 { t.Fatal("candidate Unicode/exclusion buckets changed article results") } } } func TestCandidateLengthNormalizesEditorialWhitespaceWithoutRetainingContent(t *testing.T) { const target = "https://finance.yahoo.com/news/fixture.html" pages := map[string]string{target: `

Synthetic heading

A Unicode 界 body
text.

`} m := fetchMetricsForFixturePages(t, "yahoo_finance", pages) if m.CandidateLength.Small != 1 || m.Length.Small != 1 || m.Content.Complete != 1 { t.Fatal("candidate length changed valid extraction") } } func TestCandidateLengthDoesNotInventAnEditorialRoot(t *testing.T) { const target = "https://finance.yahoo.com/news/fixture.html" for _, raw := range []string{ `

Synthetic generic page text.

`, `

First ambiguous root.

Second ambiguous root.

`, ``, } { m := fetchMetricsForFixturePages(t, "yahoo_finance", map[string]string{target: raw}) if m.CandidateLength.Zero != 1 || m.Content.Unavailable != 1 { t.Fatal("unknown/ambiguous/excluded root was measured as editorial body") } } }