diff --git a/geojson/bbox_test.go b/geojson/bbox_test.go index 7d18d7a..695320d 100644 --- a/geojson/bbox_test.go +++ b/geojson/bbox_test.go @@ -1,11 +1,23 @@ package geojson import ( + "reflect" "testing" "github.com/paulmach/orb" ) +func TestBBox(t *testing.T) { + ls := orb.LineString{{1, 3}, {0, 4}} + b := ls.Bound() + + bbox := NewBBox(b) + expected := BBox{0, 3, 1, 4} + if !reflect.DeepEqual(bbox, expected) { + t.Errorf("incorrect result: %v != %v", bbox, expected) + } +} + func TestBBoxValid(t *testing.T) { cases := []struct { name string diff --git a/geojson/feature_collection_test.go b/geojson/feature_collection_test.go index fe2cfe6..ecef31a 100644 --- a/geojson/feature_collection_test.go +++ b/geojson/feature_collection_test.go @@ -122,6 +122,55 @@ func TestUnmarshalFeatureCollection(t *testing.T) { } } +func TestUnmarshalFeatureCollection_errors(t *testing.T) { + t.Run("type not a string", func(t *testing.T) { + rawJSON := ` + { "type": { "foo":"bar" }, + "features": [ + { "type": "Feature", + "geometry": {"type": "Point", "coordinates": [102.0, 0.5]}, + "properties": {"prop0": "value0"} + } + ] + }` + + _, err := UnmarshalFeatureCollection([]byte(rawJSON)) + if _, ok := err.(*json.UnmarshalTypeError); !ok { + t.Fatalf("wrong error: %T: %v", err, err) + } + }) + + t.Run("bbox invalid", func(t *testing.T) { + rawJSON := ` + { "type": "FeatureCollection", + "bbox": { "foo":"bar" }, + "features": [ + { "type": "Feature", + "geometry": {"type": "Point", "coordinates": [102.0, 0.5]}, + "properties": {"prop0": "value0"} + } + ] + }` + + _, err := UnmarshalFeatureCollection([]byte(rawJSON)) + if _, ok := err.(*json.UnmarshalTypeError); !ok { + t.Fatalf("wrong error: %T: %v", err, err) + } + }) + + t.Run("features invalid", func(t *testing.T) { + rawJSON := ` + { "type": "FeatureCollection", + "features": { "foo":"bar" } + }` + + _, err := UnmarshalFeatureCollection([]byte(rawJSON)) + if _, ok := err.(*json.UnmarshalTypeError); !ok { + t.Fatalf("wrong error: %T: %v", err, err) + } + }) +} + func TestFeatureCollectionMarshalJSON(t *testing.T) { fc := NewFeatureCollection() blob, err := fc.MarshalJSON()