@@ -122,6 +122,55 @@ func TestUnmarshalFeatureCollection(t *testing.T) {
122
122
}
123
123
}
124
124
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
+
125
174
func TestFeatureCollectionMarshalJSON (t * testing.T ) {
126
175
fc := NewFeatureCollection ()
127
176
blob , err := fc .MarshalJSON ()
0 commit comments