tests are no longer failing :)
This commit is contained in:
parent
2e9f8f6d03
commit
f189ae11b0
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -245,7 +245,11 @@ module.exports = function() {
|
||||
Insert.prototype.type = "Insert";
|
||||
|
||||
Insert.prototype.val = function() {
|
||||
return this.content;
|
||||
if ((this.content != null) && (this.content.getCustomType != null)) {
|
||||
return this.content.getCustomType();
|
||||
} else {
|
||||
return this.content;
|
||||
}
|
||||
};
|
||||
|
||||
Insert.prototype.applyDelete = function(o) {
|
||||
|
@ -51,7 +51,7 @@ module.exports = function() {
|
||||
rep = content;
|
||||
}
|
||||
this.retrieveSub(name).replace(rep);
|
||||
return this;
|
||||
return this.getCustomType();
|
||||
} else if (name != null) {
|
||||
prop = this._map[name];
|
||||
if ((prop != null) && !prop.isContentDeleted()) {
|
||||
@ -201,7 +201,7 @@ module.exports = function() {
|
||||
result = [];
|
||||
while (o !== this.end) {
|
||||
if (!o.is_deleted) {
|
||||
result.push(o);
|
||||
result.push(o.val());
|
||||
}
|
||||
o = o.next_cl;
|
||||
}
|
||||
@ -285,6 +285,9 @@ module.exports = function() {
|
||||
} else {
|
||||
for (_i = 0, _len = content.length; _i < _len; _i++) {
|
||||
c = content[_i];
|
||||
if ((c != null) && (c._name != null) && (c._getModel != null)) {
|
||||
c = c._getModel(this.custom_types, this.operations);
|
||||
}
|
||||
tmp = (new ops.Insert(null, c, void 0, left, right)).execute();
|
||||
left = tmp;
|
||||
}
|
||||
@ -345,7 +348,7 @@ module.exports = function() {
|
||||
this.event_properties = _at_event_properties;
|
||||
this.event_this = _at_event_this;
|
||||
if (this.event_properties['object'] == null) {
|
||||
this.event_properties['object'] = this.event_this;
|
||||
this.event_properties['object'] = this.event_this.getCustomType();
|
||||
}
|
||||
ReplaceManager.__super__.constructor.call(this, custom_type, uid, beginning, end);
|
||||
}
|
||||
@ -465,7 +468,7 @@ module.exports = function() {
|
||||
var old_value;
|
||||
if (this.next_cl.type === "Delimiter" && this.prev_cl.type !== "Delimiter") {
|
||||
if (!this.is_deleted) {
|
||||
old_value = this.prev_cl.content;
|
||||
old_value = this.prev_cl.val();
|
||||
this.parent.callEventDecorator([
|
||||
{
|
||||
type: "update",
|
||||
@ -494,7 +497,7 @@ module.exports = function() {
|
||||
{
|
||||
type: "delete",
|
||||
changedBy: o.uid.creator,
|
||||
oldValue: this.content
|
||||
oldValue: this.val()
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
71
build/node/Types/List.js
Normal file
71
build/node/Types/List.js
Normal file
@ -0,0 +1,71 @@
|
||||
var YList;
|
||||
|
||||
YList = (function() {
|
||||
function YList(list) {
|
||||
if (list == null) {
|
||||
this._list = [];
|
||||
} else if (list.constructor === Array) {
|
||||
this._list = list;
|
||||
} else {
|
||||
throw new Error("Y.List expects an Array as a parameter");
|
||||
}
|
||||
}
|
||||
|
||||
YList.prototype._name = "List";
|
||||
|
||||
YList.prototype._getModel = function(types, ops) {
|
||||
if (this._model == null) {
|
||||
this._model = new ops.ListManager(this).execute();
|
||||
this.insert(0, this._list);
|
||||
}
|
||||
delete this._list;
|
||||
return this._model;
|
||||
};
|
||||
|
||||
YList.prototype._setModel = function(_at__model) {
|
||||
this._model = _at__model;
|
||||
return delete this._list;
|
||||
};
|
||||
|
||||
YList.prototype.val = function() {
|
||||
return this._model.val.apply(this._model, arguments);
|
||||
};
|
||||
|
||||
YList.prototype.observe = function() {
|
||||
this._model.observe.apply(this._model, arguments);
|
||||
return this;
|
||||
};
|
||||
|
||||
YList.prototype.unobserve = function() {
|
||||
this._model.unobserve.apply(this._model, arguments);
|
||||
return this;
|
||||
};
|
||||
|
||||
YList.prototype.insert = function(position, content) {
|
||||
if (typeof position !== "number") {
|
||||
throw new Error("Y.List.insert expects a Number as the first parameter!");
|
||||
}
|
||||
this._model.insert(position, content);
|
||||
return this;
|
||||
};
|
||||
|
||||
YList.prototype["delete"] = function(position, length) {
|
||||
this._model["delete"](position, length);
|
||||
return this;
|
||||
};
|
||||
|
||||
return YList;
|
||||
|
||||
})();
|
||||
|
||||
if (typeof window !== "undefined" && window !== null) {
|
||||
if (window.Y != null) {
|
||||
window.Y.List = YList;
|
||||
} else {
|
||||
throw new Error("You must first import Y!");
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof module !== "undefined" && module !== null) {
|
||||
module.exports = YList;
|
||||
}
|
@ -39,7 +39,13 @@ YObject = (function() {
|
||||
};
|
||||
|
||||
YObject.prototype.observe = function(f) {
|
||||
return this._model.observe(f);
|
||||
this._model.observe(f);
|
||||
return this;
|
||||
};
|
||||
|
||||
YObject.prototype.unobserve = function(f) {
|
||||
this._model.unobserve(f);
|
||||
return this;
|
||||
};
|
||||
|
||||
YObject.prototype.val = function(name, content) {
|
||||
@ -64,7 +70,8 @@ YObject = (function() {
|
||||
};
|
||||
|
||||
YObject.prototype["delete"] = function(name) {
|
||||
return this._model["delete"](name);
|
||||
this._model["delete"](name);
|
||||
return this;
|
||||
};
|
||||
|
||||
return YObject;
|
||||
|
@ -52,7 +52,7 @@ YText = (function() {
|
||||
throw new Error("Y.String.insert expects a String as the second parameter!");
|
||||
}
|
||||
if (typeof position !== "number") {
|
||||
throw new Error("Y.String.insert expects a Number as the second parameter!");
|
||||
throw new Error("Y.String.insert expects a Number as the first parameter!");
|
||||
}
|
||||
if (content.length > 0) {
|
||||
ith = this._model.getOperationByPosition(position);
|
||||
|
@ -43,5 +43,3 @@ if (typeof window !== "undefined" && window !== null) {
|
||||
}
|
||||
|
||||
createY.Object = require("./Types/Object");
|
||||
|
||||
createY.Text = require("./Types/Text");
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -301,7 +301,10 @@ module.exports = ()->
|
||||
type: "Insert"
|
||||
|
||||
val: ()->
|
||||
@content
|
||||
if @content? and @content.getCustomType?
|
||||
@content.getCustomType()
|
||||
else
|
||||
@content
|
||||
|
||||
#
|
||||
# set content to null and other stuff
|
||||
|
@ -42,7 +42,7 @@ module.exports = ()->
|
||||
else
|
||||
rep = content
|
||||
@retrieveSub(name).replace rep
|
||||
@
|
||||
@getCustomType()
|
||||
else if name?
|
||||
prop = @_map[name]
|
||||
if prop? and not prop.isContentDeleted()
|
||||
@ -172,7 +172,7 @@ module.exports = ()->
|
||||
result = []
|
||||
while o isnt @end
|
||||
if not o.is_deleted
|
||||
result.push o
|
||||
result.push o.val()
|
||||
o = o.next_cl
|
||||
result
|
||||
|
||||
@ -243,6 +243,8 @@ module.exports = ()->
|
||||
(new ops.Insert null, content, undefined, left, right).execute()
|
||||
else
|
||||
for c in content
|
||||
if c? and c._name? and c._getModel?
|
||||
c = c._getModel(@custom_types, @operations)
|
||||
tmp = (new ops.Insert null, c, undefined, left, right).execute()
|
||||
left = tmp
|
||||
@
|
||||
@ -317,7 +319,7 @@ module.exports = ()->
|
||||
# @param {Delimiter} end Reference or Object.
|
||||
constructor: (custom_type, @event_properties, @event_this, uid, beginning, end)->
|
||||
if not @event_properties['object']?
|
||||
@event_properties['object'] = @event_this
|
||||
@event_properties['object'] = @event_this.getCustomType()
|
||||
super custom_type, uid, beginning, end
|
||||
|
||||
type: "ReplaceManager"
|
||||
@ -439,7 +441,7 @@ module.exports = ()->
|
||||
if @next_cl.type is "Delimiter" and @prev_cl.type isnt "Delimiter"
|
||||
# this replaces another Replaceable
|
||||
if not @is_deleted # When this is received from the HB, this could already be deleted!
|
||||
old_value = @prev_cl.content
|
||||
old_value = @prev_cl.val()
|
||||
@parent.callEventDecorator [
|
||||
type: "update"
|
||||
changedBy: @uid.creator
|
||||
@ -462,7 +464,7 @@ module.exports = ()->
|
||||
@parent.callEventDecorator [
|
||||
type: "delete"
|
||||
changedBy: o.uid.creator
|
||||
oldValue: @content
|
||||
oldValue: @val()
|
||||
]
|
||||
|
||||
#
|
||||
|
@ -0,0 +1,70 @@
|
||||
class YList
|
||||
|
||||
#
|
||||
# @private
|
||||
# @param {Object} uid A unique identifier. If uid is undefined, a new uid will be created.
|
||||
#
|
||||
constructor: (list)->
|
||||
if not list?
|
||||
@_list = []
|
||||
else if list.constructor is Array
|
||||
@_list = list
|
||||
else
|
||||
throw new Error "Y.List expects an Array as a parameter"
|
||||
|
||||
_name: "List"
|
||||
|
||||
_getModel: (types, ops)->
|
||||
if not @_model?
|
||||
@_model = new ops.ListManager(@).execute()
|
||||
@insert 0, @_list
|
||||
delete @_list
|
||||
@_model
|
||||
|
||||
_setModel: (@_model)->
|
||||
delete @_list
|
||||
|
||||
val: ()->
|
||||
@_model.val.apply @_model, arguments
|
||||
|
||||
observe: ()->
|
||||
@_model.observe.apply @_model, arguments
|
||||
@
|
||||
|
||||
unobserve: ()->
|
||||
@_model.unobserve.apply @_model, arguments
|
||||
@
|
||||
|
||||
#
|
||||
# Inserts a Array into the list.
|
||||
#
|
||||
# @return {ListManager Type} This String object.
|
||||
#
|
||||
insert: (position, content)->
|
||||
if typeof position isnt "number"
|
||||
throw new Error "Y.List.insert expects a Number as the first parameter!"
|
||||
@_model.insert position, content
|
||||
@
|
||||
|
||||
delete: (position, length)->
|
||||
@_model.delete position, length
|
||||
@
|
||||
|
||||
if window?
|
||||
if window.Y?
|
||||
window.Y.List = YList
|
||||
else
|
||||
throw new Error "You must first import Y!"
|
||||
|
||||
if module?
|
||||
module.exports = YList
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -24,6 +24,11 @@ class YObject
|
||||
|
||||
observe: (f)->
|
||||
@_model.observe f
|
||||
@
|
||||
|
||||
unobserve: (f)->
|
||||
@_model.unobserve f
|
||||
@
|
||||
|
||||
#
|
||||
# @overload val()
|
||||
@ -57,6 +62,7 @@ class YObject
|
||||
|
||||
delete: (name)->
|
||||
@_model.delete(name)
|
||||
@
|
||||
|
||||
if window?
|
||||
if window.Y?
|
||||
|
@ -1,6 +1,5 @@
|
||||
#
|
||||
# Handles a String-like data structures with support for insert/delete at a word-position.
|
||||
# @note Currently, only Text is supported!
|
||||
#
|
||||
class YText
|
||||
|
||||
@ -59,7 +58,7 @@ class YText
|
||||
if content.constructor isnt String
|
||||
throw new Error "Y.String.insert expects a String as the second parameter!"
|
||||
if typeof position isnt "number"
|
||||
throw new Error "Y.String.insert expects a Number as the second parameter!"
|
||||
throw new Error "Y.String.insert expects a Number as the first parameter!"
|
||||
if content.length > 0
|
||||
ith = @_model.getOperationByPosition position
|
||||
# the (i-1)th character. e.g. "abc" the 1th character is "a"
|
||||
|
@ -37,4 +37,3 @@ if window?
|
||||
window.Y = createY
|
||||
|
||||
createY.Object = require "./Types/Object"
|
||||
createY.Text = require "./Types/Text"
|
||||
|
@ -9,6 +9,8 @@ chai.use(sinonChai)
|
||||
|
||||
Connector = require "../../y-test/lib/y-test.coffee"
|
||||
Y = require "../lib/y.coffee"
|
||||
Y.Text = require "../lib/Types/Text"
|
||||
Y.List = require "../lib/Types/List"
|
||||
|
||||
compare = (o1, o2)->
|
||||
if o1._name? and o1._name isnt o2._name
|
||||
@ -24,6 +26,10 @@ compare = (o1, o2)->
|
||||
Test = require "./TestSuite"
|
||||
|
||||
class JsonTest extends Test
|
||||
|
||||
constructor: (suffix)->
|
||||
super suffix, Y
|
||||
|
||||
makeNewUser: (userId)->
|
||||
conn = new Connector userId
|
||||
super new Y conn
|
||||
@ -148,19 +154,19 @@ describe "JsonFramework", ->
|
||||
expect(@yTest.getSomeUser().val("a").val("a").val("q").val()).to.equal("Adtrndtrtdrntdrnrtdnrtdnrtdnrtdnrdnrdt")
|
||||
|
||||
it "can handle creaton of complex json (3)", ->
|
||||
@yTest.users[0].val('l', [1,2,3], "mutable")
|
||||
@yTest.users[1].val('l', [4,5,6], "mutable")
|
||||
@yTest.users[0].val('l', new Y.List([1,2,3]))
|
||||
@yTest.users[1].val('l', new Y.List([4,5,6]))
|
||||
@yTest.compareAll()
|
||||
@yTest.users[2].val('l').insert(0,'A')
|
||||
w = @yTest.users[1].val('l').insert(0,'B', "mutable").val(0)
|
||||
w = @yTest.users[1].val('l').insert(0,new Y.Text('B')).val(0)
|
||||
w.insert 1, "C"
|
||||
expect(w.val()).to.equal("BC")
|
||||
@yTest.compareAll()
|
||||
|
||||
it "handles immutables and primitive data types", ->
|
||||
@yTest.getSomeUser().val('string', new Y.Text("text"))
|
||||
@yTest.getSomeUser().val('string', "text")
|
||||
@yTest.getSomeUser().val('number', 4)
|
||||
@yTest.getSomeUser().val('object', {q:"rr"})
|
||||
@yTest.getSomeUser().val('object', new Y.Object({q:"rr"}))
|
||||
@yTest.getSomeUser().val('null', null)
|
||||
@yTest.compareAll()
|
||||
expect(@yTest.getSomeUser().val('string')).to.equal "text"
|
||||
|
@ -7,13 +7,14 @@ _ = require("underscore")
|
||||
chai.use(sinonChai)
|
||||
|
||||
Connector = require "../../y-test/lib/y-test.coffee"
|
||||
Y = require "../lib/y"
|
||||
Y = null
|
||||
|
||||
module.exports = class Test
|
||||
constructor: (@name_suffix = "")->
|
||||
constructor: (@name_suffix = "", Yjs)->
|
||||
Y = Yjs
|
||||
@number_of_test_cases_multiplier = 1
|
||||
@repeat_this = 1 * @number_of_test_cases_multiplier
|
||||
@doSomething_amount = 1230 * @number_of_test_cases_multiplier
|
||||
@doSomething_amount = 123 * @number_of_test_cases_multiplier
|
||||
@number_of_engines = 5 + @number_of_test_cases_multiplier - 1
|
||||
|
||||
@time = 0 # denotes to the time when run was started
|
||||
@ -94,13 +95,20 @@ module.exports = class Test
|
||||
throw new Error "implement me!"
|
||||
|
||||
compare: (o1, o2)->
|
||||
if o1._name? and o1._name isnt o2._name
|
||||
if o1 is o2
|
||||
true
|
||||
else if o1._name? and o1._name isnt o2._name
|
||||
throw new Error "different types"
|
||||
else if o1._name is "Object"
|
||||
for name, val of o1.val()
|
||||
@compare(val, o2.val(name))
|
||||
else if o1._name?
|
||||
@compare(o1.val(), o2.val())
|
||||
else if o1.constructor is Array and o2.constructor is Array
|
||||
if o1.length isnt o2.length
|
||||
throw new Error "The Arrays do not have the same size!"
|
||||
for o,i in o1
|
||||
@compare o, o2[i]
|
||||
else if o1 isnt o2
|
||||
throw new Error "different values"
|
||||
|
||||
|
@ -8,11 +8,16 @@ _ = require("underscore")
|
||||
chai.use(sinonChai)
|
||||
|
||||
Y = require "../lib/y"
|
||||
Y.Text = require "../lib/Types/Text"
|
||||
|
||||
Connector = require "../../y-test/lib/y-test.coffee"
|
||||
|
||||
Test = require "./TestSuite"
|
||||
class TextTest extends Test
|
||||
|
||||
constructor: (suffix)->
|
||||
super suffix, Y
|
||||
|
||||
type: "TextTest"
|
||||
|
||||
makeNewUser: (userId)->
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user