-
-
Notifications
You must be signed in to change notification settings - Fork 76
/
subdivisions_test.go
179 lines (151 loc) · 3.81 KB
/
subdivisions_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
package countries
import (
"encoding/json"
"testing"
)
// Test Subdivisions
//nolint:gocyclo
func TestSubdivisionsCount(t *testing.T) {
got := TotalSubdivisions()
want := len(AllSubdivisions())
if got != want {
t.Errorf("Test AllSubdivisions() err, want %v, got %v", want, got)
}
want = len(AllSubdivisionsInfo())
if got != want {
t.Errorf("Test AllSubdivisionsInfo() err, want %v, got %v", want, got)
}
}
//nolint:gocyclo
func TestSubdivisionsCode(t *testing.T) {
for _, s := range AllSubdivisions() {
if s == SubdivisionUnknown {
continue
}
if info := s.Info(); info.Country == Unknown {
t.Errorf("Test info.Country err, s: %v", *info)
}
}
}
//nolint:gocyclo
func TestSubdivisionsIsValid(t *testing.T) {
for _, s := range AllSubdivisions() {
if s == SubdivisionUnknown {
continue
}
if !s.IsValid() && s != SubdivisionUnknown {
t.Errorf("Test SubdivisionCode.IsValid() err")
}
}
}
//nolint:gocyclo
func TestSubdivisionsString(t *testing.T) {
for _, s := range AllSubdivisions() {
if s == SubdivisionUnknown {
continue
}
if s.String() == "" || s.String() == UnknownMsg {
t.Errorf("Test SubdivisionCode.String() err, s: %v", s)
}
}
}
//nolint:gocyclo
func TestSubdivisionsType(t *testing.T) {
for _, s := range AllSubdivisions() {
if s.Type() != TypeSubdivisionCode {
t.Errorf("Test SubdivisionCode.String() err, s: %v", s)
}
}
}
//nolint:gocyclo
func TestSubdivisionsCountry(t *testing.T) { //nolint:gocyclo
for _, s := range AllSubdivisions() {
if s == SubdivisionUnknown {
continue
}
if s.Country() == Unknown {
t.Errorf("Test SubdivisionCountry.String() err, s: %v", s)
}
}
}
//nolint:gocyclo
func TestSubdivisionsInfo(t *testing.T) {
for _, s := range AllSubdivisions() {
if s == SubdivisionUnknown {
continue
}
if got := s.Info().Code; got != s {
t.Errorf("Test AllSubdivisions() err, want %v, got %v", s, got)
}
}
for _, c := range getAllCountries(t) {
for _, s := range c.Subdivisions() {
if got := s.Info().Code; got != s {
t.Errorf("Test c.Subdivision[*].Info() err, want %v, got %v for c: %v", s, got, c)
}
}
}
}
//nolint:gocyclo
func TestSubdivisionsInfoValue(t *testing.T) {
for _, s := range AllSubdivisionsInfo() {
if _, err := s.Value(); err != nil {
t.Errorf("Test SubdivisionCode.String() Value err, s: %v", s)
}
if _, err := json.Marshal(s); err != nil {
t.Errorf("Test SubdivisionCode.String() Marshal err, s: %v", s)
}
}
}
//nolint:gocyclo
func TestSubdivisionsInfoType(t *testing.T) {
for _, s := range AllSubdivisionsInfo() {
if out := s.Type(); out != TypeSubdivision {
t.Errorf("Test AllSubdivisionsInfo.Type() err, want %v, got %v", TypeCallCodeInfo, out)
}
}
}
//nolint:gocyclo
func TestSubdivisionsInfoScan(t *testing.T) {
for _, s := range AllSubdivisionsInfo() {
err := s.Scan(s)
if err != nil {
t.Errorf("Test AllSubdivisionsInfo.Scan() err")
}
s2 := *s
err = s.Scan(s2)
if err != nil {
t.Errorf("Test AllSubdivisionsInfo.Scan() err")
}
if s.Name != s2.Name || s.Code != s2.Code || s.Country != s2.Country {
t.Errorf("Test AllSubdivisionsInfo.Scan() err")
}
err = s.Scan(nil)
if err == nil {
t.Errorf("Test AllSubdivisionsInfo.Scan() err")
}
s = nil
err = s.Scan(s)
if err == nil {
t.Errorf("Test AllSubdivisionsInfo.Scan() err")
}
}
}
//nolint:gocyclo
func TestSubdivisionSubdivisionType(t *testing.T) { //nolint:gocyclo
for _, s := range AllSubdivisions() {
if s == SubdivisionUnknown {
continue
}
if s.SubdivisionType() == SubdivisionTypeUnknown {
t.Errorf("Test SubdivisionType.String() err, s: %v", s)
}
}
}
//nolint:gocyclo
func TestSubdivisionsByCountryCode(t *testing.T) {
got := SubdivisionsByCountryCode(ByName("AU"))
if count := len(got); count != 8 {
t.Errorf("Australia has 8 subdivisions but got %d", count)
}
}