Read misc.territory, timezone, useragent and car as tables, and state the data rules behind them #23
+7
-2
@@ -105,14 +105,19 @@ func TestShippedMiscReferenceData(t *testing.T) {
|
||||
"language": regexp.MustCompile(`\p{L}`),
|
||||
"language.code": regexp.MustCompile(`^[a-z]{2}$`),
|
||||
"language.code3": regexp.MustCompile(`^[a-z]{3}$`),
|
||||
"timezone": regexp.MustCompile(`^([A-Za-z_]+(/[A-Za-z_]+)+|UTC)$`),
|
||||
"timezone": regexp.MustCompile(`^[A-Za-z]+(/[A-Za-z0-9_+-]+)+$`),
|
||||
"timezone.offset": regexp.MustCompile(`^[+-](0\d|1[0-4]):[0-5]\d$`),
|
||||
"timezone.territory": regexp.MustCompile(`^[A-Z]{2}$`),
|
||||
"mimetype": regexp.MustCompile(`^[a-z]+/[a-z0-9.+-]+$`),
|
||||
"mimetype.ext": regexp.MustCompile(`^\.[a-z0-9_-]+$`),
|
||||
"httpstatus": regexp.MustCompile(`^[1-5]\d{2} \S.*$`),
|
||||
"httpstatus.code": regexp.MustCompile(`^[1-5]\d{2}$`),
|
||||
"useragent": regexp.MustCompile(`^Mozilla/5\.0 .+`),
|
||||
"useragent.browser": regexp.MustCompile(`^(Chrome|Edge|Firefox|Opera|Safari|Samsung Internet)$`),
|
||||
"useragent.device": regexp.MustCompile(`^(desktop|mobile)$`),
|
||||
"useragent.os": regexp.MustCompile(`^(Android|ChromeOS|Linux|Windows|iOS|macOS)$`),
|
||||
"car": regexp.MustCompile(`^\S.* \S`),
|
||||
"car.maker": regexp.MustCompile(`^\S`),
|
||||
"car.make": regexp.MustCompile(`^\S`),
|
||||
}
|
||||
for i := 0; i < 100; i++ {
|
||||
for p, rx := range re {
|
||||
|
||||
+1
-1
@@ -154,7 +154,7 @@ func TestListedPathsAllRender(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, p := range []string{"misc.car.maker", "misc.territory.alpha2", "misc.territory.numeric", "misc.currency.symbol", "misc.httpstatus.code", "misc.mimetype.ext"} {
|
||||
for _, p := range []string{"misc.car.make", "misc.territory.alpha2", "misc.territory.numeric", "misc.currency.symbol", "misc.httpstatus.code", "misc.mimetype.ext"} {
|
||||
if !slices.Contains(paths, p) {
|
||||
t.Errorf("List() omits %q, which the README advertises and Fake renders", p)
|
||||
}
|
||||
|
||||
+11
-5
@@ -644,17 +644,17 @@ func TestTableRowsAreAlternatives(t *testing.T) {
|
||||
|
||||
func TestTableOverridesByLayering(t *testing.T) {
|
||||
mine := writeFiles(t, map[string]string{
|
||||
"misc/territory.json": `{"format":"{name}","rows":"territory.tsv","key":"alpha2"}`,
|
||||
"misc/territory.tsv": "alpha2\tname\nXX\tNowhere\nYY\tElsewhere\n",
|
||||
"misc/language.json": `{"format":"{name}","rows":"language.tsv","key":"code"}`,
|
||||
"misc/language.tsv": "code\tname\nxx\tNowhere\nyy\tElsewhere\n",
|
||||
})
|
||||
f, err := New(WithDataPath(mine), WithSeed(1))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if v := fake(t, f, "misc.territory[XX]"); v != "Nowhere" {
|
||||
t.Fatalf("misc.territory[XX] = %q, want the layered table", v)
|
||||
if v := fake(t, f, "misc.language[xx]"); v != "Nowhere" {
|
||||
t.Fatalf("misc.language[xx] = %q, want the layered table", v)
|
||||
}
|
||||
if paths := f.List(); slices.Contains(paths, "misc.territory.alpha3") {
|
||||
if paths := f.List(); slices.Contains(paths, "misc.language.code3") {
|
||||
t.Fatal("List() still offers the shipped table's columns under an overridden category")
|
||||
}
|
||||
}
|
||||
@@ -695,6 +695,12 @@ func TestShippedTables(t *testing.T) {
|
||||
"mimetype[.mp3]": "audio/mpeg",
|
||||
"mimetype[.mp4]": "video/mp4",
|
||||
"mimetype[.ogg]": "audio/ogg",
|
||||
"timezone[Europe/Stockholm]": "Europe/Stockholm",
|
||||
"timezone[Europe/Stockholm].offset": "+01:00",
|
||||
"timezone[Asia/Kathmandu].offset": "+05:45",
|
||||
"timezone[America/New_York].offset": "-05:00",
|
||||
"territory[SE].timezone": "Europe/Stockholm",
|
||||
"territory[NP].timezone.offset": "+05:45",
|
||||
} {
|
||||
if got := fake(t, f, path); got != want {
|
||||
t.Errorf("Fake(%q) = %q, want %q", path, got, want)
|
||||
|
||||
Reference in New Issue
Block a user