Scan every timezone row, which a weighted draw no longer reaches

This commit is contained in:
2026-09-18 23:40:46 +02:00
parent 29e471ef0f
commit d98571dfb3
+16
View File
@@ -6,6 +6,7 @@ import (
"reflect" "reflect"
"regexp" "regexp"
"slices" "slices"
"strconv"
"strings" "strings"
"testing" "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 // shippedRows reads a shipped misc TSV as the loader does, proving it names the
// columns asked for and that every row fills them. // columns asked for and that every row fills them.
func shippedRows(t *testing.T, file string, want ...string) (map[string]int, [][]string) { func shippedRows(t *testing.T, file string, want ...string) (map[string]int, [][]string) {