Centralize NWS forecast discussion section headings
This commit is contained in:
@@ -8,6 +8,135 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestParseForecastDiscussionSectionHeading(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
line string
|
||||
wantSection string
|
||||
wantQualifier string
|
||||
wantOK bool
|
||||
}{
|
||||
{
|
||||
name: "ellipsis-first key messages",
|
||||
line: ".KEY MESSAGES... (Through Tonight)",
|
||||
wantSection: forecastDiscussionSectionKeyMessages,
|
||||
wantQualifier: "(Through Tonight)",
|
||||
wantOK: true,
|
||||
},
|
||||
{
|
||||
name: "ellipsis-first short term",
|
||||
line: ".SHORT TERM... (Sunday)",
|
||||
wantSection: forecastDiscussionSectionShortTerm,
|
||||
wantQualifier: "(Sunday)",
|
||||
wantOK: true,
|
||||
},
|
||||
{
|
||||
name: "ellipsis-first long term",
|
||||
line: ".LONG TERM... (Monday Through Friday)",
|
||||
wantSection: forecastDiscussionSectionLongTerm,
|
||||
wantQualifier: "(Monday Through Friday)",
|
||||
wantOK: true,
|
||||
},
|
||||
{
|
||||
name: "ellipsis-first aviation without qualifier",
|
||||
line: ".AVIATION...",
|
||||
wantSection: forecastDiscussionSectionAviation,
|
||||
wantOK: true,
|
||||
},
|
||||
{
|
||||
name: "slash-qualified key messages",
|
||||
line: ".KEY MESSAGES /Tonight/...",
|
||||
wantSection: forecastDiscussionSectionKeyMessages,
|
||||
wantQualifier: "Tonight",
|
||||
wantOK: true,
|
||||
},
|
||||
{
|
||||
name: "slash-qualified short term with outer whitespace",
|
||||
line: " .SHORT TERM /Through Late Sunday Night/... ",
|
||||
wantSection: forecastDiscussionSectionShortTerm,
|
||||
wantQualifier: "Through Late Sunday Night",
|
||||
wantOK: true,
|
||||
},
|
||||
{
|
||||
name: "slash-qualified long term",
|
||||
line: ".LONG TERM /Monday through Next Saturday/...",
|
||||
wantSection: forecastDiscussionSectionLongTerm,
|
||||
wantQualifier: "Monday through Next Saturday",
|
||||
wantOK: true,
|
||||
},
|
||||
{
|
||||
name: "slash-qualified aviation",
|
||||
line: ".AVIATION /18Z TAFS/...",
|
||||
wantSection: forecastDiscussionSectionAviation,
|
||||
wantQualifier: "18Z TAFS",
|
||||
wantOK: true,
|
||||
},
|
||||
{
|
||||
name: "unknown identity",
|
||||
line: ".SYNOPSIS... Overview",
|
||||
wantOK: false,
|
||||
},
|
||||
{
|
||||
name: "slash qualifier missing opening slash",
|
||||
line: ".SHORT TERM Through Tonight/...",
|
||||
wantOK: false,
|
||||
},
|
||||
{
|
||||
name: "slash qualifier missing closing slash",
|
||||
line: ".SHORT TERM /Through Tonight...",
|
||||
wantOK: false,
|
||||
},
|
||||
{
|
||||
name: "slash qualifier contains embedded slash",
|
||||
line: ".SHORT TERM /Tonight/Sunday/...",
|
||||
wantOK: false,
|
||||
},
|
||||
{
|
||||
name: "slash qualifier whitespace only",
|
||||
line: ".SHORT TERM / /...",
|
||||
wantOK: false,
|
||||
},
|
||||
{
|
||||
name: "slash qualifier missing required whitespace",
|
||||
line: ".SHORT TERM/Through Tonight/...",
|
||||
wantOK: false,
|
||||
},
|
||||
{
|
||||
name: "slash qualifier missing final ellipsis",
|
||||
line: ".SHORT TERM /Through Tonight/..",
|
||||
wantOK: false,
|
||||
},
|
||||
{
|
||||
name: "slash qualifier has trailing text",
|
||||
line: ".SHORT TERM /Through Tonight/... more",
|
||||
wantOK: false,
|
||||
},
|
||||
{
|
||||
name: "lowercase identity",
|
||||
line: ".short term... (Tonight)",
|
||||
wantOK: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, ok := parseForecastDiscussionSectionHeading(tt.line)
|
||||
if ok != tt.wantOK {
|
||||
t.Fatalf("parseForecastDiscussionSectionHeading(%q) ok = %t, want %t", tt.line, ok, tt.wantOK)
|
||||
}
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if got.section != tt.wantSection {
|
||||
t.Fatalf("section = %q, want %q", got.section, tt.wantSection)
|
||||
}
|
||||
if got.qualifier != tt.wantQualifier {
|
||||
t.Fatalf("qualifier = %q, want %q", got.qualifier, tt.wantQualifier)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseForecastDiscussionHTMLParsesExpectedFields(t *testing.T) {
|
||||
raw := loadForecastDiscussionSampleHTML(t)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user