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 * as Y from '../src/index.js'
import { prosemirrorPluginKey } from 'y-prosemirror'
import * as encoding from 'funlib/encoding.js'
import * as decoding from 'funlib/decoding.js'
import * as encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.js'
import * as historyProtocol from 'y-protocols/history.js'
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'",
"sideEffects": false,
"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",
"watch": "rollup -wc",
"lint": "standard",

View File

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

View File

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

View File

@ -5,8 +5,8 @@
import { getStructReference } from 'y-protocols/sync.js'
import * as ID from '../utils/ID.js'
import { writeStructToTransaction } from '../utils/structEncoding.js'
import * as decoding from 'funlib/decoding.js'
import * as encoding from 'funlib/encoding.js'
import * as decoding from 'lib0/decoding.js'
import * as encoding from 'lib0/encoding.js'
// import { Y } from '../utils/Y.js' // eslint-disable-line
// 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 { writeStructToTransaction } from '../utils/structEncoding.js'
import { GC } from './GC.js'
import * as encoding from 'funlib/encoding.js'
import * as decoding from 'funlib/decoding.js'
import * as encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.js'
/**
* @private

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@
* @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

View File

@ -1,9 +1,9 @@
import { DeleteStore } from './DeleteStore.js'
import { OperationStore } from './OperationStore.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 { Observable } from 'funlib/observable.js'
import { Observable } from 'lib0/observable.js'
import { Transaction } from './Transaction.js'
/**

View File

@ -3,7 +3,7 @@
*/
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 { Y } from '../utils/Y.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 t from 'funlib/testing.js'
import * as prng from 'lib0/prng.js'
import * as t from 'lib0/testing.js'
import { DeleteStore } from '../src/utils/DeleteStore.js'
import * as ID from '../src/utils/ID.js'
@ -58,8 +58,8 @@ export const testRepeatDeleteStoreTests = tc => {
const ds = new DeleteStore()
const dsArray = []
for (let i = 0; i < 200; i++) {
const pos = prng.int32(gen, 0, 10)
const len = prng.int32(gen, 0, 4)
const pos = prng.int31(gen, 0, 10)
const len = prng.int31(gen, 0, 4)
const gc = prng.bool(gen)
ds.mark(ID.createID(0, pos), len, gc)
for (let j = 0; j < len; j++) {
@ -72,7 +72,7 @@ export const testRepeatDeleteStoreTests = tc => {
dsArray[i] = null
}
}
t.compareArrays(dsToArray(ds), dsArray, 'Expected DS result')
t.compareArrays(dsToArray(ds), dsArray)
let size = 0
let lastEl = null
for (let i = 0; i < dsArray.length; i++) {
@ -82,5 +82,5 @@ export const testRepeatDeleteStoreTests = tc => {
}
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 Quill from 'quill'
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 encoding from 'funlib/encoding.js'
import * as decoding from 'funlib/decoding.js'
import { createMutex } from 'funlib/mutex.js'
import * as encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.js'
import { createMutex } from 'lib0/mutex.js'
import { QuillBinding } from 'y-quill'
import { DomBinding } from 'y-dom'

View File

@ -1,7 +1,7 @@
import { runTests } from 'funlib/testing.js'
import { isBrowser } from 'funlib/environment.js'
import * as log from 'funlib/logging.js'
import { runTests } from 'lib0/testing.js'
import { isBrowser } from 'lib0/environment.js'
import * as log from 'lib0/logging.js'
import * as deleteStore from './DeleteStore.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 t from 'funlib/testing.js'
import * as prng from 'funlib/prng.js'
import { createMutex } from 'funlib/mutex.js'
import * as encoding from 'funlib/encoding.js'
import * as decoding from 'funlib/decoding.js'
import * as t from 'lib0/testing.js'
import * as prng from 'lib0/prng.js'
import { createMutex } from 'lib0/mutex.js'
import * as encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.js'
import * as syncProtocol from 'y-protocols/sync.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++) {
// 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], userArrayValues[i + 1], 'array types')
t.compare(userMapValues[i], userMapValues[i + 1], 'map types')
t.compare(userXmlValues[i], userXmlValues[i + 1], 'xml types')
t.compare(userTextValues[i].map(a => a.insert).join('').length, users[i].get('text').length, 'text length correctly computed')
t.compare(userTextValues[i], userTextValues[i + 1], 'text types')
t.compare(data[i].os, data[i + 1].os, 'os', customOSCompare)
t.compare(data[i].ds, data[i + 1].ds, 'ds', customOSCompare)
t.compare(data[i].ss, data[i + 1].ss, 'ss', customOSCompare)
t.compare(userArrayValues[i].length, users[i].get('array').length)
t.compare(userArrayValues[i], userArrayValues[i + 1])
t.compare(userMapValues[i], userMapValues[i + 1])
t.compare(userXmlValues[i], userXmlValues[i + 1])
t.compare(userTextValues[i].map(a => a.insert).join('').length, users[i].get('text').length)
t.compare(userTextValues[i], userTextValues[i + 1])
t.compare(data[i].os, data[i + 1].os, null, customOSCompare)
t.compare(data[i].ds, data[i + 1].ds, null, customOSCompare)
t.compare(data[i].ss, data[i + 1].ss, null, customOSCompare)
}
users.forEach(user => {
if (user._missingStructs.size !== 0) {
t.fail('missing structs should be empty!')
}
})
users.forEach(user =>
t.assert(user._missingStructs.size === 0)
)
users.map(u => u.destroy())
}
@ -354,20 +352,20 @@ export const applyRandomTests = (tc, mods, iterations) => {
const result = init({ users: 5, prng: gen })
const { testConnector, users } = result
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
if (prng.bool(gen)) {
testConnector.disconnectRandom()
} else {
testConnector.reconnectRandom()
}
} else if (prng.int32(gen, 0, 100) <= 1) {
} else if (prng.int31(gen, 0, 100) <= 1) {
// 1% chance to flush all & garbagecollect
// TODO: We do not gc all users as this does not work yet
// await garbageCollectUsers(t, users)
testConnector.flushAllMessages()
// 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
testConnector.flushRandomMessage()
}

View File

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

View File

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