package ingestion import ( "strings" "testing" ) func TestExtractLede(t *testing.T) { tests := []struct { name string input string want string }{ { "plain text verbatim", "The president signed a new bill. More details followed in the afternoon session.", "The president signed a new bill. More details followed in the afternoon session.", }, { "single sentence", "Breaking news from the capital.", "Breaking news from the capital.", }, { "empty", "", "", }, { "html stripped", "
The company announced a major acquisition. Shares rose 5%.
", "The company announced a major acquisition. Shares rose 5%.", }, { "nested html", "Apple revealed the iPhone 16. It features a new chip.
...end of moments
Clarence B Jones, a former...
", "...end of moments Clarence B Jones, a former...", }, { "tags and entities combined", "Oil prices rose & gas fell by >5%.
", "Oil prices rose & gas fell by >5%.", }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got := extractLede(tt.input) if got != tt.want { t.Errorf("extractLede(%q) = %q, want %q", tt.input, got, tt.want) } }) } } func TestExtractContentText(t *testing.T) { if got := extractContentText(""); got != "" { t.Errorf("empty input = %q, want empty", got) } if got := extractContentText(" \n "); got != "" { t.Errorf("whitespace-only input = %q, want empty", got) } in := `First paragraph with a link & entity.
` + `Second line one.
line two.
" + strings.Repeat("x", maxContentChars+500) + "
" if n := len(extractContentText(long)); n > maxContentChars { t.Errorf("capped length = %d, want <= %d", n, maxContentChars) } }