Download this file
| 1 | package updatewords |
| 2 | |
| 3 | import ( |
| 4 | "sort" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | ) |
| 8 | |
| 9 | func TestDraftsAreWellFormed(t *testing.T) { |
| 10 | all := All() |
| 11 | if len(all) == 0 { |
| 12 | t.Fatal("no drafts registered") |
| 13 | } |
| 14 | if !sort.SliceIsSorted(all, func(i, j int) bool { return all[i].ID < all[j].ID }) { |
| 15 | t.Fatal("All is not sorted by ID") |
| 16 | } |
| 17 | for _, d := range all { |
| 18 | if !strings.HasPrefix(d.ID, "settings.") || d.Text == "" || d.Context == "" { |
| 19 | t.Errorf("%q: every draft needs a settings.* ID, a text and a context", d.ID) |
| 20 | } |
| 21 | if strings.ContainsRune(d.Text, '—') { |
| 22 | t.Errorf("%s: no em dashes in member-facing text", d.ID) |
| 23 | } |
| 24 | if Text(d.ID) != d.Text { |
| 25 | t.Errorf("%s: Text disagrees with All", d.ID) |
| 26 | } |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | func TestUnknownIDPanics(t *testing.T) { |
| 31 | defer func() { |
| 32 | if recover() == nil { |
| 33 | t.Fatal("an unknown ID did not panic") |
| 34 | } |
| 35 | }() |
| 36 | Text("settings.no.such.string") |
| 37 | } |
| 38 | |
| 39 | func TestDuplicateIDPanics(t *testing.T) { |
| 40 | defer func() { |
| 41 | if recover() == nil { |
| 42 | t.Fatal("a duplicate ID did not panic") |
| 43 | } |
| 44 | }() |
| 45 | add(Draft{ID: "settings.authorize.done", Text: "x", Context: "y"}) |
| 46 | } |
| 47 | |