carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1// internal/geo/tz_test.go
2package geo
3
4import (
5 "strings"
6 "testing"
7)
8
9func TestZonePoint(t *testing.T) {
10 mapped := []string{
11 "Europe/London", "Europe/Dublin", "Europe/Amsterdam",
12 "Asia/Kolkata", "Asia/Calcutta",
13 "America/Argentina/Buenos_Aires", "europe/london",
14 }
15 for _, z := range mapped {
16 if _, ok := ZonePoint(z); !ok {
17 t.Errorf("ZonePoint(%q) unmapped, want a point", z)
18 }
19 }
20 a, _ := ZonePoint("Asia/Calcutta")
21 b, _ := ZonePoint("Asia/Kolkata")
22 if a != b {
23 t.Errorf("Asia/Calcutta %v != Asia/Kolkata %v; the link must resolve to one point", a, b)
24 }
25 // Amsterdam is a link to Brussels in tzdata 2026b, but zone.tab gives it
26 // its own row: zone.tab wins over links (spec §6.2).
27 am, _ := ZonePoint("Europe/Amsterdam")
28 br, _ := ZonePoint("Europe/Brussels")
29 if am == br {
30 t.Errorf("Europe/Amsterdam = Europe/Brussels = %v; a zone.tab row must win over a link", am)
31 }
32 unmapped := []string{
33 "", "UTC", "Etc/UTC", "Etc/GMT+5", "GMT", "UCT", "Universal", "Zulu",
34 "Factory", "Local", "localtime", "posixrules", "../etc/passwd",
35 "Europe/London/Extra/Deep", strings.Repeat("A", 65), "Nowhere/Atlantis",
36 }
37 for _, z := range unmapped {
38 if p, ok := ZonePoint(z); ok {
39 t.Errorf("ZonePoint(%q) = %v, want unmappable", z, p)
40 }
41 }
42 l, _ := ZonePoint("Europe/London")
43 if l.Lat < 51 || l.Lat > 52 || l.Lon > 0.5 || l.Lon < -0.5 {
44 t.Errorf("Europe/London = %v, want about 51.5, -0.12", l)
45 }
46}
47
48// A link cycle must terminate (at most 4 hops) rather than hang.
49func TestZonePointLinkLoopTerminates(t *testing.T) {
50 links := map[string]string{"a/x": "a/y", "a/y": "a/x"}
51 if _, ok := resolveLinks("a/x", links, map[string]Point{}); ok {
52 t.Fatal("a link loop resolved to a point")
53 }
54}
55
56// Every country with more than one zone.tab row needs an override naming
57// its principal zone: a tzdata refresh that gives a country a second row
58// fails here instead of silently averaging a continent (spec §6.2).
59func TestCountryOverridesCoverEveryMultiZoneCountry(t *testing.T) {
60 for cc, n := range zoneRowsPerCountry() {
61 if n < 2 {
62 continue
63 }
64 zone, ok := countryOverride[cc]
65 if !ok {
66 t.Errorf("country %s has %d zone.tab rows and no override", cc, n)
67 continue
68 }
69 if _, ok := ZonePoint(zone); !ok {
70 t.Errorf("override for %s names %q, which is not in zone.tab", cc, zone)
71 }
72 }
73 for cc := range countryOverride {
74 if zoneRowsPerCountry()[cc] < 2 {
75 t.Errorf("override for %s is unused: it has fewer than two rows", cc)
76 }
77 }
78}
79
80func TestCountryPoint(t *testing.T) {
81 for _, cc := range []string{"GB", "IE", "US", "AU", "IN", "gb"} {
82 if _, ok := CountryPoint(cc); !ok {
83 t.Errorf("CountryPoint(%q) unmapped", cc)
84 }
85 }
86 us, _ := CountryPoint("US")
87 ny, _ := ZonePoint("America/New_York")
88 if us != ny {
89 t.Errorf("US = %v, want its principal zone New York %v", us, ny)
90 }
91 if _, ok := CountryPoint("ZZ"); ok {
92 t.Error("CountryPoint(ZZ) mapped")
93 }
94}
95
96func TestTZDataVersion(t *testing.T) {
97 if v := TZDataVersion(); v == "" || strings.ContainsAny(v, " \n") {
98 t.Fatalf("TZDataVersion = %q", v)
99 }
100}
101