@@ -20,7 +20,7 @@ var empty = `{}`
20
20
var collection = `[{"created":1564944548180294000,"updated":0,"index":"15b7ccc66f7878a8","data":"eyJuYW1lIjoibmFtZTEifQ=="},{"created":1564944548172292600,"updated":0,"index":"15b7ccc66efe6194","data":"eyJuYW1lIjoibmFtZTAifQ=="}]`
21
21
var emptyCollection = `[]`
22
22
23
- var collectionWindowBefore = `[{
23
+ var collectionWindowAscBefore = `[{
24
24
"test":"1"
25
25
},
26
26
{
@@ -30,7 +30,7 @@ var collectionWindowBefore = `[{
30
30
"test":"3"
31
31
}]`
32
32
33
- var collectionWindowAfter = `[{
33
+ var collectionWindowAscAfter = `[{
34
34
"test":"2"
35
35
},
36
36
{
@@ -40,15 +40,35 @@ var collectionWindowAfter = `[{
40
40
"test":"4"
41
41
}]`
42
42
43
+ var collectionWindowDscBefore = `[{
44
+ "test":"3"
45
+ },
46
+ {
47
+ "test":"2"
48
+ },
49
+ {
50
+ "test":"1"
51
+ }]`
52
+
53
+ var collectionWindowDscAfter = `[{
54
+ "test":"4"
55
+ },
56
+ {
57
+ "test":"3"
58
+ },
59
+ {
60
+ "test":"2"
61
+ }]`
62
+
43
63
func TestMultipleRemove (t * testing.T ) {
44
64
patch , e := CreatePatch ([]byte (collection ), []byte (emptyCollection ))
45
65
assert .NoError (t , e )
46
66
assert .Equal (t , len (patch ), 2 , "the patch should be the same lenght as the collection" )
47
67
assert .Equal (t , patch [0 ].Path , "/1" , "the patch should have descending order by path" )
48
68
}
49
69
50
- func TestCollectionWindowMove (t * testing.T ) {
51
- patch , e := CreatePatch ([]byte (collectionWindowBefore ), []byte (collectionWindowAfter ))
70
+ func TestCollectionWindowAscMove (t * testing.T ) {
71
+ patch , e := CreatePatch ([]byte (collectionWindowAscBefore ), []byte (collectionWindowAscAfter ))
52
72
assert .NoError (t , e )
53
73
assert .Equal (t , 2 , len (patch ), "the patch should have one insert and one remove" )
54
74
assert .Equal (t , "remove" , patch [0 ].Operation , "the patch should remove the first position" )
@@ -57,6 +77,16 @@ func TestCollectionWindowMove(t *testing.T) {
57
77
assert .Equal (t , "/2" , patch [1 ].Path , "the patch should have descending order by path" )
58
78
}
59
79
80
+ func TestCollectionWindowDscMove (t * testing.T ) {
81
+ patch , e := CreatePatch ([]byte (collectionWindowDscBefore ), []byte (collectionWindowDscAfter ))
82
+ assert .NoError (t , e )
83
+ assert .Equal (t , 2 , len (patch ), "the patch should have one insert and one remove" )
84
+ assert .Equal (t , "add" , patch [0 ].Operation , "the patch should remove the first position" )
85
+ assert .Equal (t , "/0" , patch [0 ].Path , "the patch should have descending order by path" )
86
+ assert .Equal (t , "remove" , patch [1 ].Operation , "the patch should add on the last position" )
87
+ assert .Equal (t , "/3" , patch [1 ].Path , "the patch should have descending order by path" )
88
+ }
89
+
60
90
func TestOneNullReplace (t * testing.T ) {
61
91
patch , e := CreatePatch ([]byte (simplef ), []byte (simpleG ))
62
92
assert .NoError (t , e )
0 commit comments