fixed some bugs & linted & prettyfied gulpfile

This commit is contained in:
Kevin Jahns
2015-09-13 18:22:45 +02:00
parent 82b3e50d49
commit 2a601ac6f6
11 changed files with 82 additions and 141 deletions

View File

@@ -1,5 +1,5 @@
/* global Y */
/* eslint-env browser,jasmine */
/* eslint-env browser, jasmine */
/*
This is just a compilation of functions that help to test this library!
@@ -15,9 +15,6 @@ if (typeof global !== 'undefined') {
}
g.g = g
//var co = require('co')
// g.co = co
function wait (t) {
if (t == null) {
t = 10
@@ -194,7 +191,6 @@ function async (makeGenerator) {
return Promise.resolve(result.value).then(function (res) {
return handle(generator.next(res))
}, function (err) {
debugger
return handle(generator.throw(err))
})
}
@@ -207,10 +203,3 @@ function async (makeGenerator) {
}
}
g.wrapCo = async
/*function wrapCo (gen) {
return function (done) {
return co.wrap(gen)(done)
}
}
g.wrapCo = wrapCo*/

View File

@@ -79,10 +79,25 @@ class AbstractOperationStore { // eslint-disable-line no-unused-vars
if (o.left != null) {
var left = yield* this.getOperation(o.left)
left.right = o.right
yield* this.setOperation(left)
}
if (o.right != null) {
var right = yield* this.getOperation(o.right)
right.left = o.left
yield* this.setOperation(right)
}
var parent = yield* this.getOperation(o.parent)
var setParent = false
if (Y.utils.compareIds(parent.start, o.id)) {
setParent = true
parent.start = o.right
}
if (Y.utils.compareIds(parent.end, o.id)) {
setParent = true
parent.end = o.left
}
if (setParent) {
yield* this.setOperation(parent)
}
yield* this.removeOperation(o.id)
}

View File

@@ -16,12 +16,12 @@ class DeleteStore extends Y.utils.RBTree {
}
isDeleted (id) {
var n = this.findNodeWithUpperBound(id)
return n !== null && n.val.id[0] === id[0] && id[0] < n.val.id[0] + n.val.len
return n !== null && n.val.id[0] === id[0] && id[1] < n.val.id[1] + n.val.len
}
delete (id) {
var n = this.findNodeWithUpperBound(id)
if (n != null && n.val.id[0] === id[0]) {
if (n.val.id[1] === id[1]) {
if (n.val.id[1] <= id[1] && id[1] < n.val.id[1] + n.val.len) {
// already deleted
return
} else if (n.val.id[1] + n.val.len === id[1]) {

View File

@@ -10,14 +10,20 @@ describe('Memory', function () {
it('Deleted operation is deleted', function () {
ds.delete(['u1', 10])
expect(ds.isDeleted(['u1', 10])).toBeTruthy()
expect(ds.toDeleteSet()).toBeTruthy({'u1': [10, 1]})
expect(ds.toDeleteSet()).toEqual({'u1': [[10, 1]]})
})
it('Deleted operation extends other deleted operation', function () {
ds.delete(['u1', 10])
ds.delete(['u1', 11])
expect(ds.isDeleted(['u1', 10])).toBeTruthy()
expect(ds.isDeleted(['u1', 11])).toBeTruthy()
expect(ds.toDeleteSet()).toBeTruthy({'u1': [10, 2]})
expect(ds.toDeleteSet()).toEqual({'u1': [[10, 2]]})
})
it('Deleted operation extends other deleted operation', function () {
ds.delete(['0', 3])
ds.delete(['0', 4])
ds.delete(['0', 2])
expect(ds.toDeleteSet()).toEqual({'0': [[2, 3]]})
})
it('Creates operations', function () {
var dels = ds.getDeletions({5: [[4, 1]]})

View File

@@ -34,7 +34,7 @@ var Struct = {
var target = yield* this.getOperation(op.target)
if (target != null && !target.deleted) {
target.deleted = true
if (target.left !== null && (yield* this.getOperation(target.left)).deleted) {
if (target.left === null || (yield* this.getOperation(target.left)).deleted) {
this.store.addToGarbageCollector(target.id)
target.gc = true
}

View File

@@ -6,7 +6,7 @@ var numberOfYArrayTests = 5
describe('Array Type', function () {
var y1, y2, y3, yconfig1, yconfig2, yconfig3, flushAll
jasmine.DEFAULT_TIMEOUT_INTERVAL = 5000
jasmine.DEFAULT_TIMEOUT_INTERVAL = 100
beforeEach(wrapCo(function * (done) {
yield createUsers(this, 3)
y1 = (yconfig1 = this.users[0]).root
@@ -23,7 +23,6 @@ describe('Array Type', function () {
describe('Basic tests', function () {
it('insert three elements, try re-get property', wrapCo(function * (done) {
console.log("blahhhhhhhhhhhhhhhhh ")
var array = yield y1.set('Array', Y.Array)
array.insert(0, [1, 2, 3])
array = yield y1.get('Array') // re-get property
@@ -104,9 +103,9 @@ describe('Array Type', function () {
l2 = yield y2.get('Array')
l1.insert(0, ['x', 'y'])
l1.delete(0, 2)
yield wait(500)
yield wait()
yield flushAll()
yield wait(500)
yield wait()
expect(l1.toArray()).toEqual(l2.toArray())
yield compareAllUsers(this.users)
done()

View File

@@ -57,6 +57,6 @@ class YConfig { // eslint-disable-line no-unused-vars
if (g) { // eslint-disable-line
g.Y = Y //eslint-disable-line
debugger //eslint-disable-line
// debugger //eslint-disable-line
}
Y.utils = {}