// internal/geo/tz_test.go package geo import ( "strings" "testing" ) func TestZonePoint(t *testing.T) { mapped := []string{ "Europe/London", "Europe/Dublin", "Europe/Amsterdam", "Asia/Kolkata", "Asia/Calcutta", "America/Argentina/Buenos_Aires", "europe/london", } for _, z := range mapped { if _, ok := ZonePoint(z); !ok { t.Errorf("ZonePoint(%q) unmapped, want a point", z) } } a, _ := ZonePoint("Asia/Calcutta") b, _ := ZonePoint("Asia/Kolkata") if a != b { t.Errorf("Asia/Calcutta %v != Asia/Kolkata %v; the link must resolve to one point", a, b) } // Amsterdam is a link to Brussels in tzdata 2026b, but zone.tab gives it // its own row: zone.tab wins over links (spec §6.2). am, _ := ZonePoint("Europe/Amsterdam") br, _ := ZonePoint("Europe/Brussels") if am == br { t.Errorf("Europe/Amsterdam = Europe/Brussels = %v; a zone.tab row must win over a link", am) } unmapped := []string{ "", "UTC", "Etc/UTC", "Etc/GMT+5", "GMT", "UCT", "Universal", "Zulu", "Factory", "Local", "localtime", "posixrules", "../etc/passwd", "Europe/London/Extra/Deep", strings.Repeat("A", 65), "Nowhere/Atlantis", } for _, z := range unmapped { if p, ok := ZonePoint(z); ok { t.Errorf("ZonePoint(%q) = %v, want unmappable", z, p) } } l, _ := ZonePoint("Europe/London") if l.Lat < 51 || l.Lat > 52 || l.Lon > 0.5 || l.Lon < -0.5 { t.Errorf("Europe/London = %v, want about 51.5, -0.12", l) } } // A link cycle must terminate (at most 4 hops) rather than hang. func TestZonePointLinkLoopTerminates(t *testing.T) { links := map[string]string{"a/x": "a/y", "a/y": "a/x"} if _, ok := resolveLinks("a/x", links, map[string]Point{}); ok { t.Fatal("a link loop resolved to a point") } } // Every country with more than one zone.tab row needs an override naming // its principal zone: a tzdata refresh that gives a country a second row // fails here instead of silently averaging a continent (spec §6.2). func TestCountryOverridesCoverEveryMultiZoneCountry(t *testing.T) { for cc, n := range zoneRowsPerCountry() { if n < 2 { continue } zone, ok := countryOverride[cc] if !ok { t.Errorf("country %s has %d zone.tab rows and no override", cc, n) continue } if _, ok := ZonePoint(zone); !ok { t.Errorf("override for %s names %q, which is not in zone.tab", cc, zone) } } for cc := range countryOverride { if zoneRowsPerCountry()[cc] < 2 { t.Errorf("override for %s is unused: it has fewer than two rows", cc) } } } func TestCountryPoint(t *testing.T) { for _, cc := range []string{"GB", "IE", "US", "AU", "IN", "gb"} { if _, ok := CountryPoint(cc); !ok { t.Errorf("CountryPoint(%q) unmapped", cc) } } us, _ := CountryPoint("US") ny, _ := ZonePoint("America/New_York") if us != ny { t.Errorf("US = %v, want its principal zone New York %v", us, ny) } if _, ok := CountryPoint("ZZ"); ok { t.Error("CountryPoint(ZZ) mapped") } } func TestTZDataVersion(t *testing.T) { if v := TZDataVersion(); v == "" || strings.ContainsAny(v, " \n") { t.Fatalf("TZDataVersion = %q", v) } }