made xml tests more expressive
This commit is contained in:
parent
014495febd
commit
f9542b90db
@ -54,14 +54,15 @@ YXml = (function() {
|
|||||||
this._model = _at__model;
|
this._model = _at__model;
|
||||||
delete this._xml;
|
delete this._xml;
|
||||||
return this._model.observe(function(events) {
|
return this._model.observe(function(events) {
|
||||||
var c, event, i, parent, _i, _j, _len, _len1, _ref;
|
var c, children, event, i, parent, _i, _j, _len, _len1, _ref;
|
||||||
for (_i = 0, _len = events.length; _i < _len; _i++) {
|
for (_i = 0, _len = events.length; _i < _len; _i++) {
|
||||||
event = events[_i];
|
event = events[_i];
|
||||||
if (event.name === "parent" && event.type !== "add") {
|
if (event.name === "parent" && event.type !== "add") {
|
||||||
parent = event.oldValue;
|
parent = event.oldValue;
|
||||||
_ref = parent.getChildren();
|
children = (_ref = parent._model.val("children")) != null ? _ref.val() : void 0;
|
||||||
for (i = _j = 0, _len1 = _ref.length; _j < _len1; i = ++_j) {
|
if (children != null) {
|
||||||
c = _ref[i];
|
for (i = _j = 0, _len1 = children.length; _j < _len1; i = ++_j) {
|
||||||
|
c = children[i];
|
||||||
if (c === this) {
|
if (c === this) {
|
||||||
parent._model.val("children")["delete"](i);
|
parent._model.val("children")["delete"](i);
|
||||||
break;
|
break;
|
||||||
@ -69,6 +70,7 @@ YXml = (function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return void 0;
|
return void 0;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -205,13 +207,18 @@ YXml = (function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
YXml.prototype.empty = function() {
|
YXml.prototype.empty = function() {
|
||||||
var child, _i, _len, _ref, _results;
|
var child, children, _i, _len, _ref, _results;
|
||||||
_ref = this._model.val("children").val();
|
children = this._model.val("children");
|
||||||
|
_ref = children.val();
|
||||||
_results = [];
|
_results = [];
|
||||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||||
child = _ref[_i];
|
child = _ref[_i];
|
||||||
|
if (child.constructor === String) {
|
||||||
|
_results.push(children["delete"](0));
|
||||||
|
} else {
|
||||||
_results.push(child.remove());
|
_results.push(child.remove());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return _results;
|
return _results;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -245,7 +252,7 @@ YXml = (function() {
|
|||||||
|
|
||||||
YXml.prototype.removeAttr = function(attrName) {
|
YXml.prototype.removeAttr = function(attrName) {
|
||||||
if (attrName === "class") {
|
if (attrName === "class") {
|
||||||
this._model.val("classes", new Y.Object());
|
this._model.val("classes", new this._model.custom_types.Object());
|
||||||
} else {
|
} else {
|
||||||
this._model.val("attributes")["delete"](attrName);
|
this._model.val("attributes")["delete"](attrName);
|
||||||
}
|
}
|
||||||
@ -255,7 +262,7 @@ YXml = (function() {
|
|||||||
YXml.prototype.removeClass = function() {
|
YXml.prototype.removeClass = function() {
|
||||||
var className, _i, _len;
|
var className, _i, _len;
|
||||||
if (arguments.length === 0) {
|
if (arguments.length === 0) {
|
||||||
this._model.val("classes", new Y.Object());
|
this._model.val("classes", new this._model.custom_types.Object());
|
||||||
} else {
|
} else {
|
||||||
for (_i = 0, _len = arguments.length; _i < _len; _i++) {
|
for (_i = 0, _len = arguments.length; _i < _len; _i++) {
|
||||||
className = arguments[_i];
|
className = arguments[_i];
|
||||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -41,7 +41,9 @@ class YXml
|
|||||||
for event in events
|
for event in events
|
||||||
if event.name is "parent" and event.type isnt "add"
|
if event.name is "parent" and event.type isnt "add"
|
||||||
parent = event.oldValue
|
parent = event.oldValue
|
||||||
for c,i in parent.getChildren()
|
children = parent._model.val("children")?.val()
|
||||||
|
if children?
|
||||||
|
for c,i in children
|
||||||
if c is @
|
if c is @
|
||||||
parent._model.val("children").delete i
|
parent._model.val("children").delete i
|
||||||
break
|
break
|
||||||
@ -167,7 +169,11 @@ class YXml
|
|||||||
#
|
#
|
||||||
empty: ()->
|
empty: ()->
|
||||||
# TODO: do it like this : @_model.val("children", new Y.List())
|
# TODO: do it like this : @_model.val("children", new Y.List())
|
||||||
for child in @_model.val("children").val()
|
children = @_model.val("children")
|
||||||
|
for child in children.val()
|
||||||
|
if child.constructor is String
|
||||||
|
children.delete(0)
|
||||||
|
else
|
||||||
child.remove()
|
child.remove()
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -207,7 +213,7 @@ class YXml
|
|||||||
#
|
#
|
||||||
removeAttr: (attrName)->
|
removeAttr: (attrName)->
|
||||||
if attrName is "class"
|
if attrName is "class"
|
||||||
@_model.val("classes", new Y.Object())
|
@_model.val("classes", new @_model.custom_types.Object())
|
||||||
else
|
else
|
||||||
@_model.val("attributes").delete(attrName)
|
@_model.val("attributes").delete(attrName)
|
||||||
@
|
@
|
||||||
@ -218,7 +224,7 @@ class YXml
|
|||||||
#
|
#
|
||||||
removeClass: ()->
|
removeClass: ()->
|
||||||
if arguments.length is 0
|
if arguments.length is 0
|
||||||
@_model.val("classes", new Y.Object())
|
@_model.val("classes", new @_model.custom_types.Object())
|
||||||
else
|
else
|
||||||
for className in arguments
|
for className in arguments
|
||||||
@_model.val("classes").delete(className)
|
@_model.val("classes").delete(className)
|
||||||
|
@ -20,7 +20,7 @@ module.exports = class Test
|
|||||||
@time = 0 # denotes to the time when run was started
|
@time = 0 # denotes to the time when run was started
|
||||||
@ops = 0 # number of operations (used with @time)
|
@ops = 0 # number of operations (used with @time)
|
||||||
@time_now = 0 # current time
|
@time_now = 0 # current time
|
||||||
@max_depth = 10
|
@max_depth = 4
|
||||||
|
|
||||||
@debug = false
|
@debug = false
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@ class XmlTest extends Test
|
|||||||
|
|
||||||
constructor: (suffix)->
|
constructor: (suffix)->
|
||||||
super suffix, Y
|
super suffix, Y
|
||||||
|
@doSomething_amount *= 20
|
||||||
|
|
||||||
makeNewUser: (userId)->
|
makeNewUser: (userId)->
|
||||||
conn = new Y.Test userId
|
conn = new Y.Test userId
|
||||||
@ -32,7 +33,7 @@ class XmlTest extends Test
|
|||||||
|
|
||||||
compare: (o1, o2, depth)->
|
compare: (o1, o2, depth)->
|
||||||
if o1.constructor is Y.Xml
|
if o1.constructor is Y.Xml
|
||||||
@compare o1._model, o2._model, depth
|
super o1._model, o2._model, depth
|
||||||
else
|
else
|
||||||
super
|
super
|
||||||
|
|
||||||
@ -55,6 +56,12 @@ class XmlTest extends Test
|
|||||||
p = elems[_.random(0, elems.length-1)]
|
p = elems[_.random(0, elems.length-1)]
|
||||||
@getRandomRoot user_num, p, depth--
|
@getRandomRoot user_num, p, depth--
|
||||||
|
|
||||||
|
getRandomXmlElement: ()->
|
||||||
|
if _.random(0,1) is 0
|
||||||
|
new Y.Xml(@getRandomKey())
|
||||||
|
else
|
||||||
|
@getRandomText()
|
||||||
|
|
||||||
getGeneratingFunctions: (user_num)->
|
getGeneratingFunctions: (user_num)->
|
||||||
that = @
|
that = @
|
||||||
super(user_num).concat [
|
super(user_num).concat [
|
||||||
@ -81,24 +88,24 @@ class XmlTest extends Test
|
|||||||
types : [Y.Xml]
|
types : [Y.Xml]
|
||||||
,
|
,
|
||||||
f : (y)-> # append XML
|
f : (y)-> # append XML
|
||||||
child = new Y.Xml(that.getRandomKey())
|
child = that.getRandomXmlElement()
|
||||||
y.append(child)
|
y.append(child)
|
||||||
types : [Y.Xml]
|
types : [Y.Xml]
|
||||||
,
|
,
|
||||||
f : (y)-> # pepend XML
|
f : (y)-> # pepend XML
|
||||||
child = new Y.Xml(that.getRandomKey())
|
child = that.getRandomXmlElement()
|
||||||
y.prepend child
|
y.prepend child
|
||||||
types : [Y.Xml]
|
types : [Y.Xml]
|
||||||
,
|
,
|
||||||
f : (y)-> # after XML
|
f : (y)-> # after XML
|
||||||
if y.getParent()?
|
if y.getParent()?
|
||||||
child = new Y.Xml(that.getRandomKey())
|
child = that.getRandomXmlElement()
|
||||||
y.after child
|
y.after child
|
||||||
types : [Y.Xml]
|
types : [Y.Xml]
|
||||||
,
|
,
|
||||||
f : (y)-> # before XML
|
f : (y)-> # before XML
|
||||||
if y.getParent()?
|
if y.getParent()?
|
||||||
child = new Y.Xml(that.getRandomKey())
|
child = that.getRandomXmlElement()
|
||||||
y.before child
|
y.before child
|
||||||
types : [Y.Xml]
|
types : [Y.Xml]
|
||||||
,
|
,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user