fix some tests

This commit is contained in:
Kevin Jahns 2018-02-26 03:23:22 +01:00
parent 250050e83b
commit f35c056bde
3 changed files with 25 additions and 22 deletions

View File

@ -3,7 +3,7 @@ import commonjs from 'rollup-plugin-commonjs'
import multiEntry from 'rollup-plugin-multi-entry' import multiEntry from 'rollup-plugin-multi-entry'
export default { export default {
input: 'test/y-text.tests.js', input: 'test/index.js',
name: 'y-tests', name: 'y-tests',
sourcemap: true, sourcemap: true,
output: { output: {

View File

@ -225,29 +225,31 @@ export default class YArray extends Type {
}) })
} }
insert (pos, content) { insert (pos, content) {
let left = null this._transact(() => {
let right = this._start let left = null
let count = 0 let right = this._start
const y = this._y let count = 0
while (right !== null) { const y = this._y
const rightLen = right._deleted ? 0 : (right._length - 1) while (right !== null) {
if (count <= pos && pos <= count + rightLen) { const rightLen = right._deleted ? 0 : (right._length - 1)
const splitDiff = pos - count if (count <= pos && pos <= count + rightLen) {
right = right._splitAt(y, splitDiff) const splitDiff = pos - count
left = right._left right = right._splitAt(y, splitDiff)
count += splitDiff left = right._left
break count += splitDiff
break
}
if (!right._deleted) {
count += right._length
}
left = right
right = right._right
} }
if (!right._deleted) { if (pos > count) {
count += right._length throw new Error('Position exceeds array range!')
} }
left = right this.insertAfter(left, content)
right = right._right })
}
if (pos > count) {
throw new Error('Position exceeds array range!')
}
this.insertAfter(left, content)
} }
push (content) { push (content) {
let n = this._start let n = this._start

View File

@ -1,5 +1,6 @@
import './red-black-tree.js' import './red-black-tree.js'
import './y-array.tests.js' import './y-array.tests.js'
import './y-text.tests.js'
import './y-map.tests.js' import './y-map.tests.js'
import './y-xml.tests.js' import './y-xml.tests.js'
import './encode-decode.tests.js' import './encode-decode.tests.js'