Read misc.territory, timezone, useragent and car as tables, and state the data rules behind them #23
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user