ArrayAssert = Y.ArrayAssert,
ObjectAssert = Y.ObjectAssert,
name: 'Core',
test_clone: function () {
var a = {
'bool' : false,
'num' : 0,
'nul' : null,
'undef': undefined,
'T' : 'blabber'
};
var b = Y.clone(a);
var c = (function() {
var _c = 3;
return {
a: 1,
b: 2,
c: function() {
return _c;
}
};
}());
var d = Y.clone(c);
},
test_clone_node: function () {
var a = {
y: Y,
w: window,
d: document,
};
var b = Y.clone(a);
},
test_each: function () {
var count = 0;
Y.each(null, function(v, k) {
// should not throw
});
Y.each('string', function(v, k) {
// should not throw
});
Y.each(12345, function(v, k) {
// should not throw
});
count++;
});
},
test_extend: function () {
var firedbase = false;
var firedextended = false;
var Base = function() {
// bind by string in order to allow the subclass
};
base: function() {
firedbase = true;
}
});
var Extended = function() {
};
base: function() {
firedextended = true;
}
});
var b = new Extended();
},
test_merge: function () {
Y.Assert.isFalse((o123.hasOwnProperty('foo')), 'prototype properties added to Object should not be iterable');
}
}));
name: 'augment()',
setUp: function () {
this.receiver = function () {};
this.supplier = function () {};
},
tearDown: function () {
delete this.receiver;
delete this.supplier;
},
"receiver object should be augmented with supplier's prototype properties": function () {
var receiver = {},
},
"receiver object properties should not be overwritten when `overwrite` is not `true`": function () {
},
"receiver object properties should be overwritten when `overwrite` is `true`": function () {
},
"only whitelisted properties should be copied to a receiver object": function () {
var receiver = {},
},
"supplier constructor should be called immediately when augmenting a receiver object": function () {
var calls = 0,
receiver = {};
},
"supplier constructor should receive supplied args when augmenting a receiver object": function () {
var calls = 0,
receiver = {};
calls += 1;
}
calls += 1;
}
receiver = {};
},
"receiver function prototype should be augmented with supplier's prototype properties": function () {
var receiverCalls = 0,
supplierCalls = 0,
Assert.areNotSame(supplier.prototype.bar, receiver.prototype.bar, '`bar()` should be sequestered on `receiver.prototype`');
Assert.areNotSame(supplier.prototype.baz, receiver.prototype.baz, '`baz()` should be sequestered on `receiver.prototype`');
Assert.areNotSame(supplier.prototype.bar, instance.bar, '`bar()` should be sequestered on a new instance of `receiver`');
Assert.areNotSame(supplier.prototype.baz, instance.baz, '`baz()` should be sequestered on a new instance of `receiver`');
Assert.areSame('bar', instance.bar(), 'calling `bar()` on a new instance of `receiver` should work');
Assert.areSame(1, supplierCalls, "supplier's constructor should be called on first use of a sequestered function");
Assert.areSame(supplier.prototype.bar, instance.bar, 'after the first call, `instance.bar` and `supplier.prototype.bar` should be the same');
Assert.areSame(supplier.prototype.baz, instance.baz, 'after the first call, `instance.baz` and `supplier.prototype.baz` should be the same');
},
"receiver function prototype properties should not be overwritten when `overwrite` is not `true`": function () {
function quux() {}
},
"receiver function prototype properties should be overwritten when `overwrite` is `true`": function () {
function quux() {}
},
"only whitelisted properties should be copied to a receiver function": function () {
},
"supplier constructor should receive supplied args when augmenting a receiver function": function () {
var calls = 0,
receiver = function () {};
calls += 1;
}
calls += 1;
}
receiver = function () {};
},
'augmenting a Y.Node instance should not overwrite existing properties by default': function () {
Assert.isInstanceOf(Y.Node, node.get('parentNode'), 'parentNode attribute should be a Node instance before augment');
Assert.isInstanceOf(Y.Node, node.get('parentNode'), 'parentNode attribute should be a Node instance after augment');
}
}));
// TODO: mix tests should be moved to the tests for yui-core.js, where mix()
// lives now. Need to refactor yui-core tests first though.
name: 'mix: default mode (object to object)',
setUp: function () {
},
tearDown: function () {
},
'test [mode 0]: missing receiver or supplier': function () {
var receiver = {a: 'a'},
supplier = {z: 'z'};
},
'test [mode 0]: returns receiver': function () {
var receiver = {a: 'a'},
supplier = {z: 'z'};
},
'test [mode 0]: no overwrite, no whitelist, no merge': function () {
var receiver = {a: 'a'},
receiver = {};
},
'test [mode 0]: overwrite, no whitelist, no merge': function () {
},
'test [mode 0]: overwrite, whitelist, no merge': function () {
},
'test [mode 0]: no overwrite, whitelist, no merge': function () {
},
'test [mode 0]: no overwrite, no whitelist, merge': function () {
var receiver = {a: 'a', fakeout: {a: 'a'}, obj: {a: 'a', b: 'b', deep: {foo: 'foo', deeper: {bar: 'bar'}}}},
supplier = {a: 'z', foo: 'foo', bar: 'bar', fakeout: 'moo', obj: {a: 'z', deep: {deeper: {bar: 'z', baz: 'baz'}}}};
Assert.areSame(1, Y.Object.size(receiver.fakeout), 'non-objects should not be merged into objects');
Assert.areNotSame(receiver.obj.deep, supplier.obj.deep, 'deep objects should be merged, not overwritten');
Assert.areNotSame(receiver.obj.deep.deeper, supplier.obj.deep.deeper, 'deeper objects should be merged, not overwritten');
Assert.areSame('bar', receiver.obj.deep.deeper.bar, 'deeper merged properties should not be overwritten');
// Array merge (see http://yuilibrary.com/projects/yui3/ticket/2528405)
},
'test [mode 0]: overwrite, no whitelist, merge': function () {
Assert.areNotSame(receiver.obj.deep, supplier.obj.deep, 'deep objects should be merged, not overwritten');
Assert.areNotSame(receiver.obj.deep.deeper, supplier.obj.deep.deeper, 'deeper objects should be merged, not overwritten');
// Array merge (see http://yuilibrary.com/projects/yui3/ticket/2528405)
},
'test [mode 0]: overwrite, whitelist, merge': function () {
Assert.areNotSame(receiver.obj.deep, supplier.obj.deep, 'deep objects should be merged, not overwritten');
Assert.areNotSame(receiver.obj.deep.deeper, supplier.obj.deep.deeper, 'deeper objects should be merged, not overwritten');
Assert.areSame('bar', receiver.obj.deep.deeper.bar, 'non-whitelisted deeper objects should be merged');
},
'test [mode 0]: overwrite, whitelist, toplevel merge': function() {
ObjectAssert.hasKeys(['a', 'b', 'c'], receiver.foo, "merge property with an object value from whitelist is missing properties");
ObjectAssert.areEqual({a:1, b:2, c:3}, receiver.foo, "merge property with an object value from whitelist doesn't have expected properties/values");
}
}));
name: 'mix: mode 1 (prototype to prototype)',
setUp: function () {
this.supplier = function () {};
this.supplier.prototype = {a: 'z', foo: 'foo', bar: 'bar', obj: {a: 'z', deep: {deeper: {bar: 'z'}}}};
},
tearDown: function () {
delete this.supplier;
},
'test [mode 1]: no overwrite, no whitelist, no merge': function () {
var receiver = function () {};
receiver.a = 'a';
ObjectAssert.ownsKeys(['a', 'foo', 'bar', 'obj'], receiver.prototype, 'prototype should own new keys');
},
'test [mode 1]: overwrite, no whitelist, no merge': function () {
var receiver = function () {};
receiver.a = 'a';
},
'test [mode 1]: overwrite, whitelist, no merge': function () {
var receiver = function () {};
},
'test [mode 1]: no overwrite, whitelist, no merge': function () {
var receiver = function () {};
},
'test [mode 1]: no overwrite, no whitelist, merge': function () {
var receiver = function () {};
},
'test [mode 1]: overwrite, no whitelist, merge': function () {
var receiver = function () {};
},
'test [mode 1]: overwrite, whitelist, merge': function () {
var receiver = function () {};
}
}));
// The tests for other modes above cover the various mix options exhaustively.
// From here on, we're just doing sanity checks of the remaining modes.
name: 'mix: mode 2 (object to object and prototype to prototype)',
setUp: function () {
this.supplier = function () {};
this.supplier.prototype = {a: 'z', foo: 'foo', bar: 'bar', obj: {a: 'z', deep: {deeper: {bar: 'z'}}}};
},
tearDown: function () {
delete this.supplier;
},
'test [mode 2]: basic sanity check': function () {
var receiver = function () {};
}
}));
name: 'mix: mode 3 (prototype to object)',
setUp: function () {
this.supplier = function () {};
this.supplier.prototype = {a: 'z', foo: 'foo', bar: 'bar', obj: {a: 'z', deep: {deeper: {bar: 'z'}}}};
},
tearDown: function () {
delete this.supplier;
},
'test [mode 3]: basic sanity check': function () {
var receiver = function () {};
}
}));
name: 'mix: mode 4 (object to prototype)',
setUp: function () {
this.supplier = function () {};
this.supplier.prototype = {a: 'z', foo: 'foo', bar: 'bar', obj: {a: 'z', deep: {deeper: {bar: 'z'}}}};
},
tearDown: function () {
delete this.supplier;
},
'test [mode 4]: basic sanity check': function () {
var receiver = function () {};
}
}));