Centralize daypart key canonicalization

This commit is contained in:
2026-08-13 01:00:54 +00:00
parent daf0c7efd7
commit 13829cc65c
4 changed files with 46 additions and 40 deletions

View File

@@ -658,3 +658,26 @@ func assertTimedValueClose(t *testing.T, name string, got *TimedValue, want floa
t.Fatalf("%s = %#v, want %v", name, got, want)
}
}
func TestCanonicalDaypartKey(t *testing.T) {
for _, tt := range []struct {
name string
value string
want string
}{
{name: "blank", value: " \t ", want: ""},
{name: "casing", value: "MORNING", want: "morning"},
{name: "punctuation runs", value: " Morning--Commute / School ", want: "morning_commute_school"},
{name: "Unicode", value: "Déjà Vu", want: "déjà_vu"},
{name: "letters and digits", value: "Day 1 Outlook", want: "day_1_outlook"},
} {
t.Run(tt.name, func(t *testing.T) {
if got := CanonicalDaypartKey(tt.value); got != tt.want {
t.Fatalf("CanonicalDaypartKey(%q) = %q, want %q", tt.value, got, tt.want)
}
})
}
if CanonicalDaypartKey("Morning commute") != CanonicalDaypartKey("MORNING--COMMUTE") {
t.Fatal("equivalent configured names must have the same canonical daypart key")
}
}