1 // Copyright 2020 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
15 "America/Los_Angeles",
18 func TestEmbeddedTZData(t *testing.T) {
19 for _, zone := range zones {
20 ref, err := time.LoadLocation(zone)
22 t.Errorf("LoadLocation(%q): %v", zone, err)
26 embedded, err := loadFromEmbeddedTZData(zone)
28 t.Errorf("loadFromEmbeddedTZData(%q): %v", zone, err)
31 sample, err := time.LoadLocationFromTZData(zone, []byte(embedded))
33 t.Errorf("LoadLocationFromTZData failed for %q: %v", zone, err)
37 // Compare the name and zone fields of ref and sample.
38 // The tx field changes faster as tzdata is updated.
39 // The cache fields are expected to differ.
40 v1 := reflect.ValueOf(ref).Elem()
41 v2 := reflect.ValueOf(sample).Elem()
45 for i := 0; i < nf; i++ {
47 if ft.Name != "name" && ft.Name != "zone" {
51 if !equal(t, v1.Field(i), v2.Field(i)) {
52 t.Errorf("zone %s: system and embedded tzdata field %s differs", zone, ft.Name)
56 t.Errorf("test must be updated for change to time.Location struct")
61 // equal is a small version of reflect.DeepEqual that we use to
62 // compare the values of zoneinfo unexported fields.
63 func equal(t *testing.T, f1, f2 reflect.Value) bool {
64 switch f1.Type().Kind() {
66 if f1.Len() != f2.Len() {
69 for i := 0; i < f1.Len(); i++ {
70 if !equal(t, f1.Index(i), f2.Index(i)) {
76 nf := f1.Type().NumField()
77 for i := 0; i < nf; i++ {
78 if !equal(t, f1.Field(i), f2.Field(i)) {
84 return f1.String() == f2.String()
86 return f1.Bool() == f2.Bool()
87 case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
88 return f1.Int() == f2.Int()
89 case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
90 return f1.Uint() == f2.Uint()
92 t.Errorf("test internal error: unsupported kind %v", f1.Type().Kind())