core-tests.js revision 7a685ad8e3b2ef0bf1db17e4af0c55aad6811342
YUI.add('core-tests', function(Y) {
var testCore = new Y.Test.Case({
name: "Core tests",
'cached functions should execute only once per input': function() {
var r1 = "", r2 = "", r3 = "";
var f1 = function(a) {
r1 += a;
};
var c1 = Y.cached(f1);
c1('a');
c1('b');
c1('a');
c1('b');
c1('a');
c1('b');
Y.Assert.areEqual('ab', r1);
var f2 = function(a, b) {
r2 += (a + b);
};
var c2 = Y.cached(f2);
c2('a', 'b');
c2('c', 'd');
c2('a', 'b');
c2('c', 'd');
c2('a', 'b');
c2('c', 'd');
var o = new Y.EventTarget();
o.foo = 1;
var f3 = function(a) {
Y.Assert.areEqual(1, this.foo);
r3 += a;
};
var c3 = Y.cached(Y.bind(f3, o), {
a: 'z'
});
c3('a');
c3('b');
c3('a');
c3('b');
c3('a');
c3('b');
Y.Assert.areEqual('b', r3);
// falsy second arg needs to produce a different key than no second arg
var cn = Y.ClassNameManager.getClassName;
Y.Assert.areEqual('yui3-a-', cn('a', ''));
Y.Assert.areEqual('yui3-a', cn('a'));
},
test_ie_enum_bug: function() {
var o = {
valueOf: function() {
return 'foo';
}
},
p = Y.merge(o);
Y.Assert.areEqual('foo', p.valueOf());
},
test_guid: function() {
var id, id2, i;
for (i = 0; i < 1000; i++) {
id = Y.guid();
id2 = Y.guid();
Y.Assert.areNotEqual(id, id2, 'GUID creation failed, ids match');
}
},
test_stamp: function() {
var id, id2, i;
for (i = 0; i < 1000; i++) {
id = Y.stamp({});
id2 = Y.stamp({});
Y.Assert.areNotEqual(id, id2, 'STAMP GUID creation failed, ids match');
}
},
test_use_array: function() {
var Assert = Y.Assert;
YUI().use(['dd', 'node'], function(Y) {
Assert.isObject(Y.DD, 'DD was not loaded');
Assert.isObject(Y.Node, 'Node was not loaded');
});
},
test_use_strings: function() {
var Assert = Y.Assert;
YUI().use('dd', 'node', function(Y) {
Assert.isObject(Y.DD, 'DD was not loaded');
Assert.isObject(Y.Node, 'Node was not loaded');
});
},
test_one_submodule: function() {
var Assert = Y.Assert;
YUI({
modules:{
'something':{
'submodules':{
'something1':{
fullpath: './assets/sub.js'
}
}
}
}
}).use('something1', function(Y) {
Assert.isTrue(Y.something1);
});
},
test_rollup_false: function() {
var Assert = Y.Assert;
YUI().use('dd', function(Y) {
Assert.isUndefined(Y.Env._attached.dd, 'DD Alias Module was attached');
});
YUI().use('node', function(Y) {
Assert.isUndefined(Y.Env._attached.node, 'Node Alias Module was attached');
});
},
test_log_params: function() {
if (Y.UA.ie) {
return;
}
var l = console.info,
Assert = Y.Assert,
last;
console.info = function(str) {
last = str.split(':')[0];
};
YUI().use(function (Y) {
Y.config.logInclude = {
logMe: true,
butNotMe: false
};
Y.log('test logInclude logMe','info','logMe');
Assert.areEqual(last, 'logMe', 'logInclude (true) Failed');
last = undefined;
Y.log('test logInclude butNotMe','info','butNotMe');
Assert.isUndefined(last, 'logInclude (false) Failed');
Y.config.logInclude = '';
Y.config.logExclude = {
excludeMe: true,
butDontExcludeMe: false
};
Y.log('test logExclude excludeMe','info','excludeMe');
Assert.isUndefined(last, 'excludeInclude (true) Failed');
Y.log('test logExclude butDontExcludeMe','info','butDontExcludeMe');
Assert.areEqual(last, 'butDontExcludeMe', 'logExclue (false) Failed');
});
console.info = l;
}
});
Y.SeedTests.add(testCore);
});