@@ -83,6 +83,18 @@ func TestGeo_JSONRoundtrip( t *testing.T ) {
8383 if decoded .CountryName () != "United States" {
8484 t .Errorf ( "CountryName() = %q, want United States" , decoded .CountryName () )
8585 }
86+ if decoded .RegionCode () != "CA" {
87+ t .Errorf ( "RegionCode() = %q, want CA" , decoded .RegionCode () )
88+ }
89+ if decoded .Lat () != 37.386 {
90+ t .Errorf ( "Lat() = %f, want 37.386" , decoded .Lat () )
91+ }
92+ if decoded .Lng () != - 122.084 {
93+ t .Errorf ( "Lng() = %f, want -122.084" , decoded .Lng () )
94+ }
95+ if ! decoded .HasCoordinates () {
96+ t .Error ( "HasCoordinates() should be true for full geo" )
97+ }
8698}
8799
88100func TestGeo_NilSafety ( t * testing.T ) {
@@ -112,6 +124,18 @@ func TestGeo_NilSafety( t *testing.T ) {
112124 if g .Org () != "" {
113125 t .Error ( "nil Geo.Org() should be empty" )
114126 }
127+ if g .RegionCode () != "" {
128+ t .Error ( "nil Geo.RegionCode() should be empty" )
129+ }
130+ if g .Lat () != 0 {
131+ t .Error ( "nil Geo.Lat() should be 0" )
132+ }
133+ if g .Lng () != 0 {
134+ t .Error ( "nil Geo.Lng() should be 0" )
135+ }
136+ if g .HasCoordinates () {
137+ t .Error ( "nil Geo.HasCoordinates() should be false" )
138+ }
115139
116140 // Partial Geo with nil sub-structs.
117141 partial := & Geo {}
@@ -121,6 +145,18 @@ func TestGeo_NilSafety( t *testing.T ) {
121145 if partial .CityName () != "" {
122146 t .Error ( "empty Geo.CityName() should be empty" )
123147 }
148+ if partial .RegionCode () != "" {
149+ t .Error ( "empty Geo.RegionCode() should be empty" )
150+ }
151+ if partial .Lat () != 0 {
152+ t .Error ( "empty Geo.Lat() should be 0" )
153+ }
154+ if partial .Lng () != 0 {
155+ t .Error ( "empty Geo.Lng() should be 0" )
156+ }
157+ if partial .HasCoordinates () {
158+ t .Error ( "empty Geo.HasCoordinates() should be false" )
159+ }
124160}
125161
126162func TestGeo_ParseAPIResponse ( t * testing.T ) {
@@ -276,20 +312,20 @@ func TestGeoFromPlatformHeaders( t *testing.T ) {
276312 if geo .CountryCode () != "US" {
277313 t .Errorf ( "CountryCode() = %q, want US" , geo .CountryCode () )
278314 }
279- if geo .Location . Region . Code != "CA" {
280- t .Errorf ( "Region.Code = %q, want CA" , geo .Location . Region . Code )
315+ if geo .RegionCode () != "CA" {
316+ t .Errorf ( "RegionCode() = %q, want CA" , geo .RegionCode () )
281317 }
282318 if geo .CityName () != "Mountain View" {
283319 t .Errorf ( "CityName() = %q, want Mountain View" , geo .CityName () )
284320 }
285321 if geo .TZ () != "America/Los_Angeles" {
286322 t .Errorf ( "TZ() = %q, want America/Los_Angeles" , geo .TZ () )
287323 }
288- if geo .Location . Coordinates . Latitude != 37.386 {
289- t .Errorf ( "Latitude = %f, want 37.386" , geo .Location . Coordinates . Latitude )
324+ if geo .Lat () != 37.386 {
325+ t .Errorf ( "Lat() = %f, want 37.386" , geo .Lat () )
290326 }
291- if geo .Location . Coordinates . Longitude != - 122.084 {
292- t .Errorf ( "Longitude = %f, want -122.084" , geo .Location . Coordinates . Longitude )
327+ if geo .Lng () != - 122.084 {
328+ t .Errorf ( "Lng() = %f, want -122.084" , geo .Lng () )
293329 }
294330 })
295331
0 commit comments