Skip to content

Commit 3cb1eb0

Browse files
committed
geojson: add test coverage
1 parent 1bf7f83 commit 3cb1eb0

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

Diff for: geojson/bbox_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
package geojson
22

33
import (
4+
"reflect"
45
"testing"
56

67
"github.com/paulmach/orb"
78
)
89

10+
func TestBBox(t *testing.T) {
11+
ls := orb.LineString{{1, 3}, {0, 4}}
12+
b := ls.Bound()
13+
14+
bbox := NewBBox(b)
15+
expected := BBox{0, 3, 1, 4}
16+
if !reflect.DeepEqual(bbox, expected) {
17+
t.Errorf("incorrect result: %v != %v", bbox, expected)
18+
}
19+
}
20+
921
func TestBBoxValid(t *testing.T) {
1022
cases := []struct {
1123
name string

Diff for: geojson/feature_collection_test.go

+49
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,55 @@ func TestUnmarshalFeatureCollection(t *testing.T) {
122122
}
123123
}
124124

125+
func TestUnmarshalFeatureCollection_errors(t *testing.T) {
126+
t.Run("type not a string", func(t *testing.T) {
127+
rawJSON := `
128+
{ "type": { "foo":"bar" },
129+
"features": [
130+
{ "type": "Feature",
131+
"geometry": {"type": "Point", "coordinates": [102.0, 0.5]},
132+
"properties": {"prop0": "value0"}
133+
}
134+
]
135+
}`
136+
137+
_, err := UnmarshalFeatureCollection([]byte(rawJSON))
138+
if _, ok := err.(*json.UnmarshalTypeError); !ok {
139+
t.Fatalf("wrong error: %T: %v", err, err)
140+
}
141+
})
142+
143+
t.Run("bbox invalid", func(t *testing.T) {
144+
rawJSON := `
145+
{ "type": "FeatureCollection",
146+
"bbox": { "foo":"bar" },
147+
"features": [
148+
{ "type": "Feature",
149+
"geometry": {"type": "Point", "coordinates": [102.0, 0.5]},
150+
"properties": {"prop0": "value0"}
151+
}
152+
]
153+
}`
154+
155+
_, err := UnmarshalFeatureCollection([]byte(rawJSON))
156+
if _, ok := err.(*json.UnmarshalTypeError); !ok {
157+
t.Fatalf("wrong error: %T: %v", err, err)
158+
}
159+
})
160+
161+
t.Run("features invalid", func(t *testing.T) {
162+
rawJSON := `
163+
{ "type": "FeatureCollection",
164+
"features": { "foo":"bar" }
165+
}`
166+
167+
_, err := UnmarshalFeatureCollection([]byte(rawJSON))
168+
if _, ok := err.(*json.UnmarshalTypeError); !ok {
169+
t.Fatalf("wrong error: %T: %v", err, err)
170+
}
171+
})
172+
}
173+
125174
func TestFeatureCollectionMarshalJSON(t *testing.T) {
126175
fc := NewFeatureCollection()
127176
blob, err := fc.MarshalJSON()

0 commit comments

Comments
 (0)