-
Notifications
You must be signed in to change notification settings - Fork 0
/
states_test.go
106 lines (101 loc) · 2.35 KB
/
states_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
package usps
import "testing"
func TestStateByShort(t *testing.T) {
t.Parallel()
tests := []struct {
name string
short string
want string
}{
{"ny", "NY", "New York"},
{"ca", "CA", "California"},
{"tx", "TX", "Texas"},
{"il", "IL", "Illinois"},
{"fl", "FL", "Florida"},
{"wa", "WA", "Washington"},
{"or", "OR", "Oregon"},
{"az", "AZ", "Arizona"},
{"nv", "NV", "Nevada"},
{"invalid", "XX", ""},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := StateByShort(tt.short); got.State != tt.want {
t.Errorf("StateByShort() = %v, want %v", got, tt.want)
}
})
}
}
func TestStateByLong(t *testing.T) {
t.Parallel()
tests := []struct {
name string
long string
want string
}{
{"ny", "New York", "NY"},
{"ny", "New-York", "NY"},
{"ny", "NeW yOrK", "NY"},
{"ca", "California", "CA"},
{"tx", "Texas", "TX"},
{"il", "Illinois", "IL"},
{"fl", "Florida", "FL"},
{"wa", "Washington", "WA"},
{"or", "Oregon", "OR"},
{"az", "Arizona", "AZ"},
{"nv", "Nevada", "NV"},
{"invalid", "Invalid", ""},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := StateByLong(tt.long); got.Short != tt.want {
t.Errorf("StateByLong() = %v, want %v", got, tt.want)
}
})
}
}
func TestStateList(t *testing.T) {
t.Parallel()
longList := StateListLong()
shortList := StateListShort()
list := StateList()
// codeList := StateListCode()
if len(longList) != len(shortList) || len(list) != len(shortList) || len(shortList) != 51 {
t.Errorf("StateList() = %v, want %v", len(longList), len(shortList))
}
}
func TestStateToShort(t *testing.T) {
t.Parallel()
tests := []struct {
name string
long string
want string
}{
{"ny", "New York", "NY"},
{"ny2", "NY", "NY"},
{"ca", "California", "CA"},
{"ca2", "CA", "CA"},
{"tx", "Texas", "TX"},
{"tx2", "TX", "TX"},
{"il", "Illinois", "IL"},
{"il2", "IL", "IL"},
{"fl", "Florida", "FL"},
{"fl2", "FL", "FL"},
{"wa", "Washington", "WA"},
{"wa2", "WA", "WA"},
{"or", "Oregon", "OR"},
{"or2", "OR", "OR"},
{"az", "Arizona", "AZ"},
{"az2", "AZ", "AZ"},
{"nv", "Nevada", "NV"},
{"nv2", "NV", "NV"},
{"bogus", "Yeet", ""},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := StateToShort(tt.long); got != tt.want {
t.Errorf("StateToShort() = %v, want %v", got, tt.want)
}
})
}
}