forked from paulmach/orb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
json_test.go
63 lines (50 loc) · 1.15 KB
/
json_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
package orb
import (
"encoding/json"
"testing"
)
func TestPointJSON(t *testing.T) {
p1 := Point{1, 2.1}
data, err := json.Marshal(p1)
if err != nil {
t.Errorf("should marshal just fine: %v", err)
}
if string(data) != "[1,2.1]" {
t.Errorf("incorrect json: %v", string(data))
}
var p2 Point
err = json.Unmarshal(data, &p2)
if err != nil {
t.Errorf("should unmarshal just fine: %v", err)
}
if !p1.Equal(p2) {
t.Errorf("not equal: %v", p2)
}
}
func TestLineStringJSON(t *testing.T) {
ls1 := LineString{{1.5, 2.5}, {3.5, 4.5}, {5.5, 6.5}}
data, err := json.Marshal(ls1)
if err != nil {
t.Fatalf("should marshal just fine: %v", err)
}
if string(data) != "[[1.5,2.5],[3.5,4.5],[5.5,6.5]]" {
t.Errorf("incorrect data: %v", string(data))
}
var ls2 LineString
err = json.Unmarshal(data, &ls2)
if err != nil {
t.Fatalf("should unmarshal just fine: %v", err)
}
if !ls1.Equal(ls2) {
t.Errorf("unmarshal not equal: %v", ls2)
}
// empty line
ls1 = LineString{}
data, err = json.Marshal(ls1)
if err != nil {
t.Errorf("should marshal just fine: %v", err)
}
if string(data) != "[]" {
t.Errorf("incorrect json: %v", string(data))
}
}