diff --git a/table_test.go b/table_test.go index 9cf0326..21e3b72 100644 --- a/table_test.go +++ b/table_test.go @@ -6,6 +6,7 @@ import ( "reflect" "regexp" "slices" + "strconv" "strings" "testing" ) @@ -783,6 +784,21 @@ func TestEveryUserAgentColumnAgreesWithItsString(t *testing.T) { } } +// TestEveryTimezoneRowIsWellFormed scans the file rather than drawing: the draw is +// population-weighted, so it samples the populous head and leaves most rows unrendered. +func TestEveryTimezoneRowIsWellFormed(t *testing.T) { + head, rows := shippedRows(t, "timezone.tsv", "offset", "territory", "weight", "zone") + offset := regexp.MustCompile(`^[+-](0\d|1[0-4]):[0-5]\d$`) + for i, r := range rows { + if !offset.MatchString(r[head["offset"]]) { + t.Errorf("timezone.tsv line %d: offset %q is no ±HH:MM", i+2, r[head["offset"]]) + } + if w, err := strconv.Atoi(r[head["weight"]]); err != nil || w < 1 { + t.Errorf("timezone.tsv line %d: weight %q is not a positive number", i+2, r[head["weight"]]) + } + } +} + // shippedRows reads a shipped misc TSV as the loader does, proving it names the // columns asked for and that every row fills them. func shippedRows(t *testing.T, file string, want ...string) (map[string]int, [][]string) {