-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpoint_test.go
50 lines (42 loc) · 1.05 KB
/
point_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
// Copyright (c) Omlox Client Go Contributors
// SPDX-License-Identifier: MIT
package omlox
import (
"encoding/json"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/nsf/jsondiff"
"github.com/tidwall/geojson/geometry"
)
var pointJSONTestCases = []struct {
point *Point
json []byte
}{
{
point: NewPoint(geometry.Point{X: 7.815694, Y: 48.13021599999995}),
json: []byte(`{"type":"Point","coordinates":[7.815694,48.13021599999995]}`),
},
}
func TestPointMarshal(t *testing.T) {
for _, tc := range pointJSONTestCases {
output, err := json.Marshal(tc.point)
if err != nil {
t.Fatal(err)
}
opts := jsondiff.DefaultConsoleOptions()
if r, diff := jsondiff.Compare(tc.json, output, &opts); r != jsondiff.FullMatch {
t.Errorf("%s", diff)
}
}
}
func TestPointUnmarshal(t *testing.T) {
for _, tc := range pointJSONTestCases {
var point Point
if err := json.Unmarshal(tc.json, &point); err != nil {
t.Fatal(err)
}
if diff := cmp.Diff(tc.point, &point); diff != "" {
t.Errorf("Polygon() mismatch (-want +got):\n%s", diff)
}
}
}