Add SPC provider parsing helpers
This commit is contained in:
90
internal/providers/spc/discussion_test.go
Normal file
90
internal/providers/spc/discussion_test.go
Normal file
@@ -0,0 +1,90 @@
|
||||
package spc
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestExtractProductTextCleansPreBlock(t *testing.T) {
|
||||
raw := string(readTestFile(t, "day1_prt.html"))
|
||||
|
||||
got, err := ExtractProductText(raw)
|
||||
if err != nil {
|
||||
t.Fatalf("ExtractProductText() error = %v", err)
|
||||
}
|
||||
if strings.Contains(got, "<script") || strings.Contains(got, "<pre") {
|
||||
t.Fatalf("ExtractProductText() retained HTML: %q", got)
|
||||
}
|
||||
if strings.Contains(got, "ignore me") {
|
||||
t.Fatalf("ExtractProductText() retained script content: %q", got)
|
||||
}
|
||||
if !strings.Contains(got, "Day 1 Convective Outlook") {
|
||||
t.Fatalf("ExtractProductText() missing headline: %q", got)
|
||||
}
|
||||
if strings.HasPrefix(got, "\n") || strings.HasSuffix(got, "\n") {
|
||||
t.Fatalf("ExtractProductText() retained surrounding blank lines: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseDiscussionTextExtractsHeadlineSummaryAndUpdated(t *testing.T) {
|
||||
text, err := ExtractProductText(string(readTestFile(t, "day1_prt.html")))
|
||||
if err != nil {
|
||||
t.Fatalf("ExtractProductText() error = %v", err)
|
||||
}
|
||||
|
||||
got := ParseDiscussionText(text)
|
||||
if got.ProductTitle != "Day 1 Convective Outlook" {
|
||||
t.Fatalf("ProductTitle = %q", got.ProductTitle)
|
||||
}
|
||||
if got.Headline != "Day 1 Convective Outlook" {
|
||||
t.Fatalf("Headline = %q", got.Headline)
|
||||
}
|
||||
wantSummary := "Severe thunderstorms are possible across parts of the central Plains\nand mid Mississippi Valley this afternoon and evening."
|
||||
if got.Summary != wantSummary {
|
||||
t.Fatalf("Summary = %q, want %q", got.Summary, wantSummary)
|
||||
}
|
||||
if !strings.Contains(got.Discussion, "...DISCUSSION...") {
|
||||
t.Fatalf("Discussion missing full text: %q", got.Discussion)
|
||||
}
|
||||
wantUpdated := time.Date(2026, 6, 11, 12, 45, 0, 0, time.UTC)
|
||||
if got.UpdatedAt == nil || !got.UpdatedAt.Equal(wantUpdated) {
|
||||
t.Fatalf("UpdatedAt = %v, want %s", got.UpdatedAt, wantUpdated)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseDiscussionTextPreservesCorrectionMarker(t *testing.T) {
|
||||
text, err := ExtractProductText(string(readTestFile(t, "day2_prt_corr.html")))
|
||||
if err != nil {
|
||||
t.Fatalf("ExtractProductText() error = %v", err)
|
||||
}
|
||||
|
||||
got := ParseDiscussionText(text)
|
||||
if !strings.Contains(got.Headline, "CORR 1") {
|
||||
t.Fatalf("Headline = %q, want correction marker", got.Headline)
|
||||
}
|
||||
if !strings.Contains(got.Discussion, "CORR 1") {
|
||||
t.Fatalf("Discussion = %q, want correction marker", got.Discussion)
|
||||
}
|
||||
if got.UpdatedAt != nil {
|
||||
t.Fatalf("UpdatedAt = %v, want nil", got.UpdatedAt)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseUpdatedTimestampReturnsNilWhenAbsent(t *testing.T) {
|
||||
text, err := ExtractProductText(string(readTestFile(t, "day2_prt_corr.html")))
|
||||
if err != nil {
|
||||
t.Fatalf("ExtractProductText() error = %v", err)
|
||||
}
|
||||
if got := ParseUpdatedTimestamp(text); got != nil {
|
||||
t.Fatalf("ParseUpdatedTimestamp() = %v, want nil", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseUpdatedTimestampAcceptsSPCUTCFormat(t *testing.T) {
|
||||
got := ParseUpdatedTimestamp("Updated: 1945 UTC Thu Jun 11 2026")
|
||||
want := time.Date(2026, 6, 11, 19, 45, 0, 0, time.UTC)
|
||||
if got == nil || !got.Equal(want) {
|
||||
t.Fatalf("ParseUpdatedTimestamp() = %v, want %s", got, want)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user