-
Notifications
You must be signed in to change notification settings - Fork 1
/
collection_test.go
78 lines (72 loc) · 1.47 KB
/
collection_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
package geojson_test
import (
"encoding/json"
"testing"
geojson "github.com/everystreet/go-geojson/v3"
"github.com/stretchr/testify/require"
)
func TestGeometryCollection(t *testing.T) {
feature := geojson.NewFeature(
geojson.NewGeometryCollection(
geojson.NewPoint(9, 45),
geojson.NewMultiLineString(
[]geojson.Position{
geojson.MakePosition(12, 34),
geojson.MakePosition(56, 78),
geojson.MakePosition(90, 12),
},
[]geojson.Position{
geojson.MakePosition(23, 45),
geojson.MakePosition(67, 89),
},
),
geojson.NewGeometryCollection(
geojson.NewPoint(37, 12),
),
),
)
err := feature.Validate()
require.NoError(t, err)
data, err := json.Marshal(feature)
require.NoError(t, err)
require.JSONEq(t, `
{
"type": "Feature",
"geometry": {
"type": "GeometryCollection",
"geometries": [
{
"type": "Point",
"coordinates": [45, 9]
},
{
"type": "MultiLineString",
"coordinates": [
[
[34, 12],
[78, 56],
[12, 90]
],
[
[45, 23],
[89, 67]
]
]
},
{
"type": "GeometryCollection",
"geometries": [
{
"type": "Point",
"coordinates": [12, 37]
}
]
}
]
}
}`, string(data))
var unmarshalled geojson.Feature[*geojson.GeometryCollection]
err = json.Unmarshal(data, &unmarshalled)
require.NoError(t, err)
require.Equal(t, feature, unmarshalled)
}