This commit is contained in:
Kevin Jahns
2022-07-11 18:35:16 +02:00
parent 3b31764b6e
commit 100e436e2c
15 changed files with 106 additions and 324 deletions

View File

@@ -10,6 +10,7 @@ import * as doc from './doc.tests.js'
import * as snapshot from './snapshot.tests.js'
import * as updates from './updates.tests.js'
import * as relativePositions from './relativePositions.tests.js'
import * as Y from './testHelper.js'
import { runTests } from 'lib0/testing'
import { isBrowser, isNode } from 'lib0/environment'
@@ -17,6 +18,8 @@ import * as log from 'lib0/logging'
if (isBrowser) {
log.createVConsole(document.body)
// @ts-ignore
window.Y = Y
}
runTests({
doc, map, array, text, xml, encoding, undoredo, compatibility, snapshot, updates, relativePositions

View File

@@ -373,33 +373,6 @@ export const compare = users => {
t.compare(Y.encodeStateVector(users[i]), Y.encodeStateVector(users[i + 1]))
compareDS(Y.createDeleteSetFromStructStore(users[i].store), Y.createDeleteSetFromStructStore(users[i + 1].store))
compareStructStores(users[i].store, users[i + 1].store)
// @todo
// test list-iterator
// console.log('dutiraneduiaentdr', users[0].getArray('array')._searchMarker)
/*
{
const user = users[0]
user.transact(tr => {
const type = user.getArray('array')
Y.useSearchMarker(tr, type, type.length, walker => {
for (let i = type.length; i >= 0; i--) {
const otherWalker = new Y.ListIterator(type)
otherWalker.forward(tr, walker.index)
otherWalker.forward(tr, 0)
walker.forward(tr, 0)
t.assert(walker.index === i)
t.assert(walker.left === otherWalker.left)
t.assert(walker.right === otherWalker.right)
t.assert(walker.nextItem === otherWalker.nextItem)
t.assert(walker.reachedEnd === otherWalker.reachedEnd)
if (i > 0) {
walker.backward(tr, 1)
}
}
})
})
}
*/
}
users.map(u => u.destroy())
}

View File

@@ -534,6 +534,32 @@ export const testMoveSingleItemRemovesPrev = tc => {
t.assert(items.filter(item => !item.deleted).length === 3)
}
/**
* Check that the searchMarker is reused correctly.
*
* @param {t.TestCase} tc
*/
export const testListWalkerReusesSearchMarker = tc => {
const ydoc = new Y.Doc()
const yarray = ydoc.getArray()
const iterations = 100
for (let i = 0; i < iterations; i++) {
yarray.insert(0, [i])
}
/**
* @type {any}
*/
let prevSm = null
for (let i = 0; i < iterations; i++) {
const v = yarray.get(i)
t.assert(v === iterations - i - 1)
t.assert(yarray._searchMarker.length <= 1)
const sm = yarray._searchMarker[0]
t.assert(prevSm == null || sm === prevSm)
prevSm = sm
}
}
/**
* @param {t.TestCase} tc
*/
@@ -617,8 +643,6 @@ const getUniqueNumber = () => _uniqueNumber++
/**
* @type {Array<function(Doc,prng.PRNG,any):void>}
*
* @todo to replace content to a separate data structure so we know that insert & returns work as expected!!!
*/
const arrayTransactions = [
function move (user, gen) {
@@ -732,6 +756,7 @@ const compareTestobjects = cmp => {
for (let i = 0; i < arrs.length; i++) {
const type = cmp.users[i].getArray('array')
t.compareArrays(arrs[i], type.toArray())
t.compareArrays(arrs[i], Array.from(type))
}
}