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