forked from mattbaird/jsonpatch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsonpatch_geojson_test.go
More file actions
52 lines (47 loc) · 2.13 KB
/
Copy pathjsonpatch_geojson_test.go
File metadata and controls
52 lines (47 loc) · 2.13 KB
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
package jsonpatch
import (
"sort"
"testing"
"github.com/stretchr/testify/assert"
)
var point = `{"type":"Point", "coordinates":[0.0, 1.0]}`
var lineString = `{"type":"LineString", "coordinates":[[0.0, 1.0], [2.0, 3.0]]}`
var geotestCollections = Collections{
Arrays: []Path{"$.coordinates"},
}
func TestPointLineStringReplace(t *testing.T) {
patch, e := CreatePatch([]byte(point), []byte(lineString), geotestCollections, nil, PatchStrategyExactMatch)
assert.NoError(t, e)
assert.Equal(t, len(patch), 3, "they should be equal")
sort.Sort(ByPath(patch))
change := patch[0]
assert.Equal(t, change.Operation, "replace", "they should be equal")
assert.Equal(t, change.Path, "/coordinates/0", "they should be equal")
assert.Equal(t, change.Value, []any{0.0, 1.0}, "they should be equal")
change = patch[1]
assert.Equal(t, change.Operation, "replace", "they should be equal")
assert.Equal(t, change.Path, "/coordinates/1", "they should be equal")
assert.Equal(t, change.Value, []any{2.0, 3.0}, "they should be equal")
change = patch[2]
assert.Equal(t, change.Operation, "replace", "they should be equal")
assert.Equal(t, change.Path, "/type", "they should be equal")
assert.Equal(t, change.Value, "LineString", "they should be equal")
}
func TestLineStringPointReplace(t *testing.T) {
patch, e := CreatePatch([]byte(lineString), []byte(point), geotestCollections, nil, PatchStrategyExactMatch)
assert.NoError(t, e)
assert.Equal(t, len(patch), 3, "they should be equal")
sort.Sort(ByPath(patch))
change := patch[0]
assert.Equal(t, change.Operation, "replace", "they should be equal")
assert.Equal(t, change.Path, "/coordinates/0", "they should be equal")
assert.Equal(t, change.Value, 0.0, "they should be equal")
change = patch[1]
assert.Equal(t, change.Operation, "replace", "they should be equal")
assert.Equal(t, change.Path, "/coordinates/1", "they should be equal")
assert.Equal(t, change.Value, 1.0, "they should be equal")
change = patch[2]
assert.Equal(t, change.Operation, "replace", "they should be equal")
assert.Equal(t, change.Path, "/type", "they should be equal")
assert.Equal(t, change.Value, "Point", "they should be equal")
}