test case for deletes + fix
This commit is contained in:
parent
47221c26c4
commit
d8868c47e1
@ -96,11 +96,14 @@ export const logUpdate = update => logUpdateV2(update, UpdateDecoderV1)
|
|||||||
*/
|
*/
|
||||||
export const logUpdateV2 = (update, YDecoder = UpdateDecoderV2) => {
|
export const logUpdateV2 = (update, YDecoder = UpdateDecoderV2) => {
|
||||||
const structs = []
|
const structs = []
|
||||||
const lazyDecoder = new LazyStructReader(new YDecoder(decoding.createDecoder(update)))
|
const updateDecoder = new YDecoder(decoding.createDecoder(update))
|
||||||
|
const lazyDecoder = new LazyStructReader(updateDecoder)
|
||||||
for (let curr = lazyDecoder.curr; curr !== null; curr = lazyDecoder.next()) {
|
for (let curr = lazyDecoder.curr; curr !== null; curr = lazyDecoder.next()) {
|
||||||
structs.push(curr)
|
structs.push(curr)
|
||||||
}
|
}
|
||||||
logging.print(structs)
|
logging.print('Structs: ', structs)
|
||||||
|
const ds = readDeleteSet(updateDecoder)
|
||||||
|
logging.print('DeleteSet: ', ds)
|
||||||
}
|
}
|
||||||
|
|
||||||
export class LazyStructWriter {
|
export class LazyStructWriter {
|
||||||
|
@ -37,19 +37,10 @@ export const testMergeUpdates = tc => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {t.TestCase} tc
|
* @param {Y.Doc} ydoc
|
||||||
|
* @param {Array<Uint8Array>} updates - expecting at least 4 updates
|
||||||
*/
|
*/
|
||||||
export const testMergeUpdatesWrongOrder = tc => {
|
const checkUpdateCases = (ydoc, updates) => {
|
||||||
const ydoc = new Y.Doc()
|
|
||||||
const updates = /** @type {Array<Uint8Array>} */ ([])
|
|
||||||
ydoc.on(updateEventName, update => { updates.push(update) })
|
|
||||||
|
|
||||||
const array = ydoc.getArray()
|
|
||||||
array.insert(0, [1])
|
|
||||||
array.insert(0, [2])
|
|
||||||
array.insert(0, [3])
|
|
||||||
array.insert(0, [4])
|
|
||||||
|
|
||||||
const cases = []
|
const cases = []
|
||||||
|
|
||||||
// Case 1: Simple case, simply merge everything
|
// Case 1: Simple case, simply merge everything
|
||||||
@ -71,7 +62,8 @@ export const testMergeUpdatesWrongOrder = tc => {
|
|||||||
// Case 4: Separated updates (containing skips)
|
// Case 4: Separated updates (containing skips)
|
||||||
cases.push(mergeUpdates([
|
cases.push(mergeUpdates([
|
||||||
mergeUpdates([updates[0], updates[2]]),
|
mergeUpdates([updates[0], updates[2]]),
|
||||||
mergeUpdates([updates[1], updates[3]])
|
mergeUpdates([updates[1], updates[3]]),
|
||||||
|
mergeUpdates(updates.slice(4))
|
||||||
]))
|
]))
|
||||||
|
|
||||||
// Case 5: overlapping with many duplicates
|
// Case 5: overlapping with many duplicates
|
||||||
@ -86,11 +78,44 @@ export const testMergeUpdatesWrongOrder = tc => {
|
|||||||
logUpdate(updates)
|
logUpdate(updates)
|
||||||
const merged = new Y.Doc()
|
const merged = new Y.Doc()
|
||||||
applyUpdate(merged, updates)
|
applyUpdate(merged, updates)
|
||||||
t.compareArrays(merged.getArray().toArray(), array.toArray())
|
t.compareArrays(merged.getArray().toArray(), ydoc.getArray().toArray())
|
||||||
t.compare(updates, targetState)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {t.TestCase} tc
|
||||||
|
*/
|
||||||
|
export const testMergeUpdates1 = tc => {
|
||||||
|
const ydoc = new Y.Doc({ gc: false })
|
||||||
|
const updates = /** @type {Array<Uint8Array>} */ ([])
|
||||||
|
ydoc.on(updateEventName, update => { updates.push(update) })
|
||||||
|
|
||||||
|
const array = ydoc.getArray()
|
||||||
|
array.insert(0, [1])
|
||||||
|
array.insert(0, [2])
|
||||||
|
array.insert(0, [3])
|
||||||
|
array.insert(0, [4])
|
||||||
|
|
||||||
|
checkUpdateCases(ydoc, updates)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {t.TestCase} tc
|
||||||
|
*/
|
||||||
|
export const testMergeUpdates2 = tc => {
|
||||||
|
const ydoc = new Y.Doc({ gc: false })
|
||||||
|
const updates = /** @type {Array<Uint8Array>} */ ([])
|
||||||
|
ydoc.on(updateEventName, update => { updates.push(update) })
|
||||||
|
|
||||||
|
const array = ydoc.getArray()
|
||||||
|
array.insert(0, [1, 2])
|
||||||
|
array.delete(1, 1)
|
||||||
|
array.insert(0, [3, 4])
|
||||||
|
array.delete(1, 2)
|
||||||
|
|
||||||
|
checkUpdateCases(ydoc, updates)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @todo be able to apply Skip structs to Yjs docs
|
* @todo be able to apply Skip structs to Yjs docs
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user