refix array tests and switch to lib0

This commit is contained in:
Kevin Jahns 2019-03-10 23:26:53 +01:00
parent 0a5753c191
commit 39cee7c6e7
25 changed files with 80 additions and 81 deletions

View File

@ -3,8 +3,8 @@ import { Plugin } from 'prosemirror-state'
import crel from 'crel' import crel from 'crel'
import * as Y from '../src/index.js' import * as Y from '../src/index.js'
import { prosemirrorPluginKey } from 'y-prosemirror' import { prosemirrorPluginKey } from 'y-prosemirror'
import * as encoding from 'funlib/encoding.js' import * as encoding from 'lib0/encoding.js'
import * as decoding from 'funlib/decoding.js' import * as decoding from 'lib0/decoding.js'
import * as historyProtocol from 'y-protocols/history.js' import * as historyProtocol from 'y-protocols/history.js'
const niceColors = ['#3cb44b', '#4363d8', '#f58231', '#911eb4', '#46f0f0', '#f032e6', '#bcf60c', '#008080', '#9a6324', '#800000', '#808000', '#000075', '#808080'] const niceColors = ['#3cb44b', '#4363d8', '#f58231', '#911eb4', '#46f0f0', '#f032e6', '#bcf60c', '#008080', '#9a6324', '#800000', '#808000', '#000075', '#808080']

View File

@ -6,7 +6,8 @@
"module": "./dist/yjs.mjs'", "module": "./dist/yjs.mjs'",
"sideEffects": false, "sideEffects": false,
"scripts": { "scripts": {
"test": "npm run lint && npm run dist && node ./dist/tests.js --repitition-time 10000", "test": "npm run lint && npm run dist && node ./dist/tests.js --repitition-time 50",
"test-exhaustive": "npm run lint && npm run dist && node ./dist/tests.js --repitition-time 10000",
"dist": "rm -rf dist examples/build && PRODUCTION=1 rollup -c", "dist": "rm -rf dist examples/build && PRODUCTION=1 rollup -c",
"watch": "rollup -wc", "watch": "rollup -wc",
"lint": "standard", "lint": "standard",

View File

@ -56,7 +56,7 @@ export default [{
sourcemap: true, sourcemap: true,
paths: path => { paths: path => {
if (/^funlib\//.test(path)) { if (/^funlib\//.test(path)) {
return `funlib/dist${path.slice(6)}` return `lib0/dist${path.slice(6)}`
} }
return path return path
} }

View File

@ -5,8 +5,8 @@
import { getStructReference } from 'y-protocols/sync.js' import { getStructReference } from 'y-protocols/sync.js'
import * as ID from '../utils/ID.js' import * as ID from '../utils/ID.js'
import { writeStructToTransaction } from '../utils/structEncoding.js' import { writeStructToTransaction } from '../utils/structEncoding.js'
import * as decoding from 'funlib/decoding.js' import * as decoding from 'lib0/decoding.js'
import * as encoding from 'funlib/encoding.js' import * as encoding from 'lib0/encoding.js'
// import { Item } from './Item.js' // eslint-disable-line // import { Item } from './Item.js' // eslint-disable-line
// import { Y } from '../utils/Y.js' // eslint-disable-line // import { Y } from '../utils/Y.js' // eslint-disable-line
import { deleteItemRange } from '../utils/structManipulation.js' import { deleteItemRange } from '../utils/structManipulation.js'

View File

@ -5,8 +5,8 @@
import { getStructReference } from 'y-protocols/sync.js' import { getStructReference } from 'y-protocols/sync.js'
import * as ID from '../utils/ID.js' import * as ID from '../utils/ID.js'
import { writeStructToTransaction } from '../utils/structEncoding.js' import { writeStructToTransaction } from '../utils/structEncoding.js'
import * as decoding from 'funlib/decoding.js' import * as decoding from 'lib0/decoding.js'
import * as encoding from 'funlib/encoding.js' import * as encoding from 'lib0/encoding.js'
// import { Y } from '../utils/Y.js' // eslint-disable-line // import { Y } from '../utils/Y.js' // eslint-disable-line
// TODO should have the same base class as Item // TODO should have the same base class as Item

View File

@ -7,8 +7,8 @@ import * as ID from '../utils/ID.js'
import { Delete } from './Delete.js' import { Delete } from './Delete.js'
import { writeStructToTransaction } from '../utils/structEncoding.js' import { writeStructToTransaction } from '../utils/structEncoding.js'
import { GC } from './GC.js' import { GC } from './GC.js'
import * as encoding from 'funlib/encoding.js' import * as encoding from 'lib0/encoding.js'
import * as decoding from 'funlib/decoding.js' import * as decoding from 'lib0/decoding.js'
/** /**
* @private * @private

View File

@ -6,8 +6,8 @@
import { Item } from './Item.js' import { Item } from './Item.js'
import * as stringify from 'y-protocols/utils/structStringify.js' import * as stringify from 'y-protocols/utils/structStringify.js'
import * as encoding from 'funlib/encoding.js' import * as encoding from 'lib0/encoding.js'
import * as decoding from 'funlib/decoding.js' import * as decoding from 'lib0/decoding.js'
import { Y } from '../utils/Y.js' // eslint-disable-line import { Y } from '../utils/Y.js' // eslint-disable-line
export class ItemBinary extends Item { export class ItemBinary extends Item {

View File

@ -4,8 +4,8 @@
import { Item } from './Item.js' import { Item } from './Item.js'
import * as stringify from 'y-protocols/utils/structStringify.js' import * as stringify from 'y-protocols/utils/structStringify.js'
import * as encoding from 'funlib/encoding.js' import * as encoding from 'lib0/encoding.js'
import * as decoding from 'funlib/decoding.js' import * as decoding from 'lib0/decoding.js'
import { Y } from '../utils/Y.js' // eslint-disable-line import { Y } from '../utils/Y.js' // eslint-disable-line
export class ItemEmbed extends Item { export class ItemEmbed extends Item {

View File

@ -4,8 +4,8 @@
import { Item } from './Item.js' import { Item } from './Item.js'
import * as stringify from 'y-protocols/utils/structStringify.js' import * as stringify from 'y-protocols/utils/structStringify.js'
import * as encoding from 'funlib/encoding.js' import * as encoding from 'lib0/encoding.js'
import * as decoding from 'funlib/decoding.js' import * as decoding from 'lib0/decoding.js'
import { Y } from '../utils/Y.js' // eslint-disable-line import { Y } from '../utils/Y.js' // eslint-disable-line
export class ItemFormat extends Item { export class ItemFormat extends Item {

View File

@ -4,8 +4,8 @@
import { Item, splitHelper } from './Item.js' import { Item, splitHelper } from './Item.js'
import * as stringify from 'y-protocols/utils/structStringify.js' import * as stringify from 'y-protocols/utils/structStringify.js'
import * as encoding from 'funlib/encoding.js' import * as encoding from 'lib0/encoding.js'
import * as decoding from 'funlib/decoding.js' import * as decoding from 'lib0/decoding.js'
import { Y } from '../utils/Y.js' // eslint-disable-line import { Y } from '../utils/Y.js' // eslint-disable-line
export class ItemJSON extends Item { export class ItemJSON extends Item {

View File

@ -4,8 +4,8 @@
import { Item, splitHelper } from './Item.js' import { Item, splitHelper } from './Item.js'
import * as stringify from 'y-protocols/utils/structStringify.js' import * as stringify from 'y-protocols/utils/structStringify.js'
import * as encoding from 'funlib/encoding.js' import * as encoding from 'lib0/encoding.js'
import * as decoding from 'funlib/decoding.js' import * as decoding from 'lib0/decoding.js'
import { Y } from '../utils/Y.js' // eslint-disable-line import { Y } from '../utils/Y.js' // eslint-disable-line
export class ItemString extends Item { export class ItemString extends Item {

View File

@ -3,8 +3,8 @@
*/ */
import { YMap } from './YMap.js' import { YMap } from './YMap.js'
import * as encoding from 'funlib/encoding.js' import * as encoding from 'lib0/encoding.js'
import * as decoding from 'funlib/decoding.js' import * as decoding from 'lib0/decoding.js'
import { Y } from '../utils/Y.js' // eslint-disable-line import { Y } from '../utils/Y.js' // eslint-disable-line
import { YArray } from './YArray.js' import { YArray } from './YArray.js'
import { YXmlEvent } from './YXmlEvent.js' import { YXmlEvent } from './YXmlEvent.js'

View File

@ -3,8 +3,8 @@
*/ */
import { YMap } from './YMap.js' import { YMap } from './YMap.js'
import * as encoding from 'funlib/encoding.js' import * as encoding from 'lib0/encoding.js'
import * as decoding from 'funlib/decoding.js' import * as decoding from 'lib0/decoding.js'
import { Y } from '../utils/Y.js' // eslint-disable-line import { Y } from '../utils/Y.js' // eslint-disable-line
/** /**

View File

@ -2,7 +2,7 @@
* @module utils * @module utils
*/ */
import { Tree } from 'funlib/tree.js' import { Tree } from 'lib0/tree.js'
import * as ID from './ID.js' import * as ID from './ID.js'
export class DSNode { export class DSNode {

View File

@ -3,8 +3,8 @@
*/ */
import { getStructReference } from 'y-protocols/sync.js' import { getStructReference } from 'y-protocols/sync.js'
import * as decoding from 'funlib/decoding.js' import * as decoding from 'lib0/decoding.js'
import * as encoding from 'funlib/encoding.js' import * as encoding from 'lib0/encoding.js'
export class ID { export class ID {
constructor (user, clock) { constructor (user, clock) {

View File

@ -2,7 +2,7 @@
* @module utils * @module utils
*/ */
import { Tree } from 'funlib/tree.js' import { Tree } from 'lib0/tree.js'
import * as ID from '../utils/ID.js' import * as ID from '../utils/ID.js'
import { getStruct } from 'y-protocols/sync.js' import { getStruct } from 'y-protocols/sync.js'
import { GC } from '../structs/GC.js' import { GC } from '../structs/GC.js'

View File

@ -2,7 +2,7 @@
* @module utils * @module utils
*/ */
import * as encoding from 'funlib/encoding.js' import * as encoding from 'lib0/encoding.js'
/** /**
* A transaction is created for every change on the Yjs model. It is possible * A transaction is created for every change on the Yjs model. It is possible

View File

@ -1,9 +1,9 @@
import { DeleteStore } from './DeleteStore.js' import { DeleteStore } from './DeleteStore.js'
import { OperationStore } from './OperationStore.js' import { OperationStore } from './OperationStore.js'
import { StateStore } from './StateStore.js' import { StateStore } from './StateStore.js'
import * as random from 'funlib/random.js' import * as random from 'lib0/random.js'
import { createRootID } from './ID.js' import { createRootID } from './ID.js'
import { Observable } from 'funlib/observable.js' import { Observable } from 'lib0/observable.js'
import { Transaction } from './Transaction.js' import { Transaction } from './Transaction.js'
/** /**

View File

@ -3,7 +3,7 @@
*/ */
import { getStruct } from 'y-protocols/sync.js' import { getStruct } from 'y-protocols/sync.js'
import * as decoding from 'funlib/decoding.js' import * as decoding from 'lib0/decoding.js'
import { GC } from '../structs/GC.js' import { GC } from '../structs/GC.js'
import { Y } from '../utils/Y.js' // eslint-disable-line import { Y } from '../utils/Y.js' // eslint-disable-line
import { Item } from '../structs/Item.js' // eslint-disable-line import { Item } from '../structs/Item.js' // eslint-disable-line

View File

@ -1,5 +1,5 @@
import * as prng from 'funlib/prng.js' import * as prng from 'lib0/prng.js'
import * as t from 'funlib/testing.js' import * as t from 'lib0/testing.js'
import { DeleteStore } from '../src/utils/DeleteStore.js' import { DeleteStore } from '../src/utils/DeleteStore.js'
import * as ID from '../src/utils/ID.js' import * as ID from '../src/utils/ID.js'
@ -58,8 +58,8 @@ export const testRepeatDeleteStoreTests = tc => {
const ds = new DeleteStore() const ds = new DeleteStore()
const dsArray = [] const dsArray = []
for (let i = 0; i < 200; i++) { for (let i = 0; i < 200; i++) {
const pos = prng.int32(gen, 0, 10) const pos = prng.int31(gen, 0, 10)
const len = prng.int32(gen, 0, 4) const len = prng.int31(gen, 0, 4)
const gc = prng.bool(gen) const gc = prng.bool(gen)
ds.mark(ID.createID(0, pos), len, gc) ds.mark(ID.createID(0, pos), len, gc)
for (let j = 0; j < len; j++) { for (let j = 0; j < len; j++) {
@ -72,7 +72,7 @@ export const testRepeatDeleteStoreTests = tc => {
dsArray[i] = null dsArray[i] = null
} }
} }
t.compareArrays(dsToArray(ds), dsArray, 'Expected DS result') t.compareArrays(dsToArray(ds), dsArray)
let size = 0 let size = 0
let lastEl = null let lastEl = null
for (let i = 0; i < dsArray.length; i++) { for (let i = 0; i < dsArray.length; i++) {
@ -82,5 +82,5 @@ export const testRepeatDeleteStoreTests = tc => {
} }
lastEl = el lastEl = el
} }
t.assert(size === ds.length, 'DS sizes match') t.assert(size === ds.length)
} }

View File

@ -5,11 +5,11 @@ import { ItemString } from '../src/structs/ItemString.js'
import { defragmentItemContent } from '../src/utils/defragmentItemContent.js' import { defragmentItemContent } from '../src/utils/defragmentItemContent.js'
import Quill from 'quill' import Quill from 'quill'
import { GC } from '../src/structs/GC.js' import { GC } from '../src/structs/GC.js'
import * as random from 'funlib/prng.js' import * as random from 'lib0/prng.js'
import * as syncProtocol from 'y-protocols/sync.js' import * as syncProtocol from 'y-protocols/sync.js'
import * as encoding from 'funlib/encoding.js' import * as encoding from 'lib0/encoding.js'
import * as decoding from 'funlib/decoding.js' import * as decoding from 'lib0/decoding.js'
import { createMutex } from 'funlib/mutex.js' import { createMutex } from 'lib0/mutex.js'
import { QuillBinding } from 'y-quill' import { QuillBinding } from 'y-quill'
import { DomBinding } from 'y-dom' import { DomBinding } from 'y-dom'

View File

@ -1,7 +1,7 @@
import { runTests } from 'funlib/testing.js' import { runTests } from 'lib0/testing.js'
import { isBrowser } from 'funlib/environment.js' import { isBrowser } from 'lib0/environment.js'
import * as log from 'funlib/logging.js' import * as log from 'lib0/logging.js'
import * as deleteStore from './DeleteStore.tests.js' import * as deleteStore from './DeleteStore.tests.js'
import * as array from './y-array.tests.js' import * as array from './y-array.tests.js'

View File

@ -1,9 +1,9 @@
import * as Y from '../src/index.js' import * as Y from '../src/index.js'
import * as t from 'funlib/testing.js' import * as t from 'lib0/testing.js'
import * as prng from 'funlib/prng.js' import * as prng from 'lib0/prng.js'
import { createMutex } from 'funlib/mutex.js' import { createMutex } from 'lib0/mutex.js'
import * as encoding from 'funlib/encoding.js' import * as encoding from 'lib0/encoding.js'
import * as decoding from 'funlib/decoding.js' import * as decoding from 'lib0/decoding.js'
import * as syncProtocol from 'y-protocols/sync.js' import * as syncProtocol from 'y-protocols/sync.js'
import { defragmentItemContent } from '../src/utils/defragmentItemContent.js' import { defragmentItemContent } from '../src/utils/defragmentItemContent.js'
@ -331,21 +331,19 @@ export const compare = users => {
}) })
for (var i = 0; i < data.length - 1; i++) { for (var i = 0; i < data.length - 1; i++) {
// t.describe(`Comparing user${i} with user${i + 1}`) // t.describe(`Comparing user${i} with user${i + 1}`)
t.compare(userArrayValues[i].length, users[i].get('array').length, 'array length correctly computed') t.compare(userArrayValues[i].length, users[i].get('array').length)
t.compare(userArrayValues[i], userArrayValues[i + 1], 'array types') t.compare(userArrayValues[i], userArrayValues[i + 1])
t.compare(userMapValues[i], userMapValues[i + 1], 'map types') t.compare(userMapValues[i], userMapValues[i + 1])
t.compare(userXmlValues[i], userXmlValues[i + 1], 'xml types') t.compare(userXmlValues[i], userXmlValues[i + 1])
t.compare(userTextValues[i].map(a => a.insert).join('').length, users[i].get('text').length, 'text length correctly computed') t.compare(userTextValues[i].map(a => a.insert).join('').length, users[i].get('text').length)
t.compare(userTextValues[i], userTextValues[i + 1], 'text types') t.compare(userTextValues[i], userTextValues[i + 1])
t.compare(data[i].os, data[i + 1].os, 'os', customOSCompare) t.compare(data[i].os, data[i + 1].os, null, customOSCompare)
t.compare(data[i].ds, data[i + 1].ds, 'ds', customOSCompare) t.compare(data[i].ds, data[i + 1].ds, null, customOSCompare)
t.compare(data[i].ss, data[i + 1].ss, 'ss', customOSCompare) t.compare(data[i].ss, data[i + 1].ss, null, customOSCompare)
} }
users.forEach(user => { users.forEach(user =>
if (user._missingStructs.size !== 0) { t.assert(user._missingStructs.size === 0)
t.fail('missing structs should be empty!') )
}
})
users.map(u => u.destroy()) users.map(u => u.destroy())
} }
@ -354,20 +352,20 @@ export const applyRandomTests = (tc, mods, iterations) => {
const result = init({ users: 5, prng: gen }) const result = init({ users: 5, prng: gen })
const { testConnector, users } = result const { testConnector, users } = result
for (var i = 0; i < iterations; i++) { for (var i = 0; i < iterations; i++) {
if (prng.int32(gen, 0, 100) <= 2) { if (prng.int31(gen, 0, 100) <= 2) {
// 2% chance to disconnect/reconnect a random user // 2% chance to disconnect/reconnect a random user
if (prng.bool(gen)) { if (prng.bool(gen)) {
testConnector.disconnectRandom() testConnector.disconnectRandom()
} else { } else {
testConnector.reconnectRandom() testConnector.reconnectRandom()
} }
} else if (prng.int32(gen, 0, 100) <= 1) { } else if (prng.int31(gen, 0, 100) <= 1) {
// 1% chance to flush all & garbagecollect // 1% chance to flush all & garbagecollect
// TODO: We do not gc all users as this does not work yet // TODO: We do not gc all users as this does not work yet
// await garbageCollectUsers(t, users) // await garbageCollectUsers(t, users)
testConnector.flushAllMessages() testConnector.flushAllMessages()
// await users[0].db.emptyGarbageCollector() // TODO: reintroduce GC tests! // await users[0].db.emptyGarbageCollector() // TODO: reintroduce GC tests!
} else if (prng.int32(gen, 0, 100) <= 50) { } else if (prng.int31(gen, 0, 100) <= 50) {
// 50% chance to flush a random message // 50% chance to flush a random message
testConnector.flushRandomMessage() testConnector.flushRandomMessage()
} }

View File

@ -1,18 +1,18 @@
import { init, compare, applyRandomTests } from './testHelper.js' import { init, compare, applyRandomTests } from './testHelper.js'
import * as Y from '../src/index.js' import * as Y from '../src/index.js'
import * as t from 'funlib/testing.js' import * as t from 'lib0/testing.js'
import * as prng from 'funlib/prng.js' import * as prng from 'lib0/prng.js'
export const testDeleteInsert = tc => { export const testDeleteInsert = tc => {
const { users, array0 } = init(tc, { users: 2 }) const { users, array0 } = init(tc, { users: 2 })
array0.delete(0, 0) array0.delete(0, 0)
t.assert(true, 'Does not throw when deleting zero elements with position 0') t.describe('Does not throw when deleting zero elements with position 0')
t.fails(() => { t.fails(() => {
array0.delete(1, 1) array0.delete(1, 1)
}, 'Throws when deleting with an invalid position') })
array0.insert(0, ['A']) array0.insert(0, ['A'])
array0.delete(1, 0) array0.delete(1, 0)
t.assert(true, 'Does not throw when deleting zero elements with valid position 1') t.describe('Does not throw when deleting zero elements with valid position 1')
compare(users) compare(users)
} }
@ -229,23 +229,23 @@ let arrayTransactions = [
const yarray = user.define('array', Y.Array) const yarray = user.define('array', Y.Array)
var uniqueNumber = getUniqueNumber() var uniqueNumber = getUniqueNumber()
var content = [] var content = []
var len = prng.int32(gen, 1, 4) var len = prng.int31(gen, 1, 4)
for (var i = 0; i < len; i++) { for (var i = 0; i < len; i++) {
content.push(uniqueNumber) content.push(uniqueNumber)
} }
var pos = prng.int32(gen, 0, yarray.length) var pos = prng.int31(gen, 0, yarray.length)
yarray.insert(pos, content) yarray.insert(pos, content)
}, },
function insertTypeArray (t, user, gen) { function insertTypeArray (t, user, gen) {
const yarray = user.define('array', Y.Array) const yarray = user.define('array', Y.Array)
var pos = prng.int32(gen, 0, yarray.length) var pos = prng.int31(gen, 0, yarray.length)
yarray.insert(pos, [Y.Array]) yarray.insert(pos, [Y.Array])
var array2 = yarray.get(pos) var array2 = yarray.get(pos)
array2.insert(0, [1, 2, 3, 4]) array2.insert(0, [1, 2, 3, 4])
}, },
function insertTypeMap (t, user, gen) { function insertTypeMap (t, user, gen) {
const yarray = user.define('array', Y.Array) const yarray = user.define('array', Y.Array)
var pos = prng.int32(gen, 0, yarray.length) var pos = prng.int31(gen, 0, yarray.length)
yarray.insert(pos, [Y.Map]) yarray.insert(pos, [Y.Map])
var map = yarray.get(pos) var map = yarray.get(pos)
map.set('someprop', 42) map.set('someprop', 42)
@ -256,14 +256,14 @@ let arrayTransactions = [
const yarray = user.define('array', Y.Array) const yarray = user.define('array', Y.Array)
var length = yarray.length var length = yarray.length
if (length > 0) { if (length > 0) {
var somePos = prng.int32(gen, 0, length - 1) var somePos = prng.int31(gen, 0, length - 1)
var delLength = prng.int32(gen, 1, Math.min(2, length - somePos)) var delLength = prng.int31(gen, 1, Math.min(2, length - somePos))
if (yarray instanceof Y.Array) { if (yarray instanceof Y.Array) {
if (prng.bool(gen)) { if (prng.bool(gen)) {
var type = yarray.get(somePos) var type = yarray.get(somePos)
if (type.length > 0) { if (type.length > 0) {
somePos = prng.int32(gen, 0, type.length - 1) somePos = prng.int31(gen, 0, type.length - 1)
delLength = prng.int32(gen, 0, Math.min(2, type.length - somePos)) delLength = prng.int31(gen, 0, Math.min(2, type.length - somePos))
type.delete(somePos, delLength) type.delete(somePos, delLength)
} }
} else { } else {

View File

@ -1,7 +1,7 @@
import { initArrays, compareUsers, applyRandomTests } from './helper.js' import { initArrays, compareUsers, applyRandomTests } from './helper.js'
import * as Y from '../src/index.js' import * as Y from '../src/index.js'
import { test, proxyConsole } from 'cutest' import { test, proxyConsole } from 'cutest'
import * as random from 'funlib/prng/prng.js' import * as random from 'lib0/prng/prng.js'
proxyConsole() proxyConsole()