-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
abode_test.go
155 lines (131 loc) · 3.43 KB
/
abode_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
package abode
import (
"context"
"reflect"
"testing"
"github.com/kylelemons/godebug/pretty"
. "github.com/onsi/gomega"
)
func TestExplode_US(t *testing.T) {
RegisterTestingT(t)
if client == nil {
if err := mapsClient(); err != nil {
t.Errorf("Unexpected error: %s", err)
}
}
var (
line1 = "193 Rogers Avenue"
line2 = "Brooklyn"
state = "New York"
country = "United States"
countryCode = "US"
zip = "11216"
lat = 40.6706252
lng = -73.9530545
formatted = "193 Rogers Ave, Brooklyn, NY 11216, USA"
expected = &Address{
AddressLine1: &line1,
AddressLine2: &line2,
AddressCity: nil,
AddressState: &state,
AddressCountry: &country,
AddressCountryCode: &countryCode,
AddressZip: &zip,
AddressLat: &lat,
AddressLng: &lng,
FormattedAddress: &formatted,
}
)
result, err := ExplodeWithContext(context.Background(), "193 Rogers Ave, Brooklyn, New York")
if err != nil {
t.Errorf("Unexpected error: %s", err)
}
if !reflect.DeepEqual(result, expected) {
t.Errorf("Unexpected Results\n%s", pretty.Compare(result, expected))
}
}
func TestExplode_International(t *testing.T) {
RegisterTestingT(t)
if client == nil {
if err := mapsClient(); err != nil {
t.Errorf("Unexpected error: %s", err)
}
}
var (
line1 = "1 4 Abercrombie Street"
line2 = "Howick"
city = "Auckland"
state = "Auckland"
country = "New Zealand"
countryCode = "NZ"
zip = "2014"
lat = -36.8990751
lng = 174.9334851
formatted = "1/4 Abercrombie Street, Howick, Auckland 2014, New Zealand"
expected = &Address{
AddressLine1: &line1,
AddressLine2: &line2,
AddressCity: &city,
AddressState: &state,
AddressCountry: &country,
AddressCountryCode: &countryCode,
AddressZip: &zip,
AddressLat: &lat,
AddressLng: &lng,
FormattedAddress: &formatted,
}
)
result, err := ExplodeWithContext(context.Background(), "1/4 Abercrombie Street, Auckland")
if err != nil {
t.Errorf("Unexpected error: %s", err)
}
if !reflect.DeepEqual(result, expected) {
t.Errorf("Unexpected Results\n%s", pretty.Compare(result, expected))
}
}
func TestTimezone_US(t *testing.T) {
RegisterTestingT(t)
if client == nil {
if err := mapsClient(); err != nil {
t.Errorf("Unexpected error: %s", err)
}
}
var (
expected = &Location{
DstOffset: 0,
RawOffset: -17762,
TimeZoneId: "America/New_York",
TimeZoneName: "GMT-04:56:02",
}
)
result, err := Timezone(context.Background(), "193 Rogers Ave, Brooklyn, New York")
if err != nil {
t.Errorf("Unexpected error: %s", err)
}
if !reflect.DeepEqual(result, expected) {
t.Errorf("Unexpected Results\n%s", pretty.Compare(result, expected))
}
}
func TestTimezone_International(t *testing.T) {
RegisterTestingT(t)
if client == nil {
if err := mapsClient(); err != nil {
t.Errorf("Unexpected error: %s", err)
}
}
var (
expected = &Location{
DstOffset: 0,
RawOffset: 41944,
TimeZoneId: "Pacific/Auckland",
TimeZoneName: "GMT+11:39:04",
}
)
result, err := Timezone(context.Background(), "1/4 Abercrombie Street, Auckland")
if err != nil {
t.Errorf("Unexpected error: %s", err)
}
if !reflect.DeepEqual(result, expected) {
t.Errorf("Unexpected Results\n%s", pretty.Compare(result, expected))
}
}