-
Notifications
You must be signed in to change notification settings - Fork 28
/
simplepoint_test.go
62 lines (52 loc) · 2.49 KB
/
simplepoint_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
package geojson
import "testing"
func TestSimplePointNotSimple(t *testing.T) {
p := expectJSONOpts(t, `{"type":"Point","coordinates":[1,2,3]}`, nil, &ParseOptions{AllowSimplePoints: true})
expect(t, p.Center() == P(1, 2))
expectJSONOpts(t, `{"type":"Point","coordinates":[1,"hello"]}`, errCoordinatesInvalid, &ParseOptions{AllowSimplePoints: true})
expectJSONOpts(t, `{"type":"Point","coordinates":[1,null]}`, `{"type":"Point","coordinates":[1,null]}`, &ParseOptions{AllowSimplePoints: true})
expectJSONOpts(t, `{"type":"Point","coordinates":[1,2],"bbox":null}`, nil, &ParseOptions{AllowSimplePoints: true})
expectJSONOpts(t, `{"type":"Point"}`, errCoordinatesMissing, &ParseOptions{AllowSimplePoints: true})
expectJSONOpts(t, `{"type":"Point","coordinates":null}`, errCoordinatesInvalid, &ParseOptions{AllowSimplePoints: true})
expectJSONOpts(t, `{"type":"Point","coordinates":[1,2,3,4,5]}`, `{"type":"Point","coordinates":[1,2,3,4]}`, &ParseOptions{AllowSimplePoints: true})
expectJSONOpts(t, `{"type":"Point","coordinates":[1]}`, errCoordinatesInvalid, &ParseOptions{AllowSimplePoints: true})
expectJSONOpts(t, `{"type":"Point","coordinates":[1,2,3],"bbox":[1,2,3,4]}`, `{"type":"Point","coordinates":[1,2,3],"bbox":[1,2,3,4]}`, &ParseOptions{AllowSimplePoints: true})
}
func TestSimplePointParseValid(t *testing.T) {
json := `{"type":"Point","coordinates":[190,90]}`
p := expectJSONOpts(t, json, nil, &ParseOptions{AllowSimplePoints: true})
expect(t, !p.(*SimplePoint).Empty())
p = expectJSONOpts(t, json, nil, &ParseOptions{AllowSimplePoints: false})
expect(t, !p.(*Point).Empty())
p = expectJSONOpts(t, json, errCoordinatesInvalid, &ParseOptions{RequireValid: true, AllowSimplePoints: true})
expect(t, p == nil)
}
func TestSimplePointVarious(t *testing.T) {
var g Object = PO(10, 20)
expect(t, string(g.AppendJSON(nil)) == `{"type":"Point","coordinates":[10,20]}`)
expect(t, g.Rect() == R(10, 20, 10, 20))
expect(t, g.Center() == P(10, 20))
expect(t, !g.Empty())
}
func TestSimplePointValid(t *testing.T) {
var g Object = PO(0, 20)
expect(t, g.Valid())
var g1 Object = PO(10, 20)
expect(t, g1.Valid())
}
func TestSimplePointInvalidLargeX(t *testing.T) {
var g Object = PO(10, 91)
expect(t, !g.Valid())
}
func TestSimplePointInvalidLargeY(t *testing.T) {
var g Object = PO(181, 20)
expect(t, !g.Valid())
}
func TestSimplePointValidLargeX(t *testing.T) {
var g Object = PO(180, 20)
expect(t, g.Valid())
}
func TestSimplePointValidLargeY(t *testing.T) {
var g Object = PO(180, 90)
expect(t, g.Valid())
}