11import test from 'ava'
2- import { applyPatch , encode , decode , TYPE } from '../'
2+ import { applyPatch , encode , decode , addType } from '../'
3+ import Splice from '../src/types/splice'
34import { getNewPlain } from '../src/util/get'
45import { isPlainObject } from '../src/util/is'
56
7+ addType ( Splice )
8+
69function testBasic ( t , patch , expected ) {
710 const encoded = encode ( patch )
811 const decoded = decode ( encoded )
@@ -29,7 +32,7 @@ function testUnpatch(t, target, patch, expected, reverse = true) {
2932}
3033
3134test ( 'Valid type' , function ( t ) {
32- const patch = { convert : TYPE . Splice ( 0 , 1 , 'world' ) }
35+ const patch = { convert : Splice ( 0 , 1 , 'world' ) }
3336 const expected = { convert : { $s : [ 0 , 1 , 'world' ] } }
3437 testBasic ( t , patch , expected )
3538} )
@@ -48,35 +51,35 @@ test('Ignore', function(t) {
4851
4952test ( 'removing and adding' , function ( t ) {
5053 const target = { array : [ 'a' , 'b' , 'c' ] }
51- const patch = { array : TYPE . Splice ( 0 , 1 , 'd' ) }
54+ const patch = { array : Splice ( 0 , 1 , 'd' ) }
5255 const expected = { array : [ 'd' , 'b' , 'c' ] }
5356 testUnpatch ( t , target , patch , expected )
5457} )
5558
5659test ( 'removing' , function ( t ) {
5760 const target = { array : [ 'a' , 'b' , 'c' ] }
58- const patch = { array : TYPE . Splice ( 0 , 1 ) }
61+ const patch = { array : Splice ( 0 , 1 ) }
5962 const expected = { array : [ 'b' , 'c' ] }
6063 testUnpatch ( t , target , patch , expected )
6164} )
6265
6366test ( 'removing middle' , function ( t ) {
6467 const target = { array : [ 'a' , 'b' , 'c' ] }
65- const patch = { array : TYPE . Splice ( 1 , 1 ) }
68+ const patch = { array : Splice ( 1 , 1 ) }
6669 const expected = { array : [ 'a' , 'c' ] }
6770 testUnpatch ( t , target , patch , expected )
6871} )
6972
7073test ( 'adding' , function ( t ) {
7174 const target = { array : [ 'a' , 'b' , 'c' ] }
72- const patch = { array : TYPE . Splice ( 3 , 0 , 'd' ) }
75+ const patch = { array : Splice ( 3 , 0 , 'd' ) }
7376 const expected = { array : [ 'a' , 'b' , 'c' , 'd' ] }
7477 testUnpatch ( t , target , patch , expected )
7578} )
7679
7780// test('negative (not supported yet)', function(t) {
7881// const target = { array: ['angel', 'clown', 'mandarin', 'sturgeon'] }
79- // const patch = { array: TYPE. Splice(-2, 1) }
82+ // const patch = { array: Splice(-2, 1) }
8083// const expected = { array: ['angel', 'clown', 'sturgeon'] }
8184// testUnpatch(t, target, patch, expected, false)
8285// })
0 commit comments