package updatewords import ( "sort" "strings" "testing" ) func TestDraftsAreWellFormed(t *testing.T) { all := All() if len(all) == 0 { t.Fatal("no drafts registered") } if !sort.SliceIsSorted(all, func(i, j int) bool { return all[i].ID < all[j].ID }) { t.Fatal("All is not sorted by ID") } for _, d := range all { if !strings.HasPrefix(d.ID, "settings.") || d.Text == "" || d.Context == "" { t.Errorf("%q: every draft needs a settings.* ID, a text and a context", d.ID) } if strings.ContainsRune(d.Text, '—') { t.Errorf("%s: no em dashes in member-facing text", d.ID) } if Text(d.ID) != d.Text { t.Errorf("%s: Text disagrees with All", d.ID) } } } func TestUnknownIDPanics(t *testing.T) { defer func() { if recover() == nil { t.Fatal("an unknown ID did not panic") } }() Text("settings.no.such.string") } func TestDuplicateIDPanics(t *testing.T) { defer func() { if recover() == nil { t.Fatal("a duplicate ID did not panic") } }() add(Draft{ID: "settings.authorize.done", Text: "x", Context: "y"}) }