array-test.js revision c10296bbdbfbe582ff454be77952d702e261484c
name: 'Array tests',
testArray: function () {
// @TODO NodeList will be wrapped rather than have the items coerced into an
// array. If Array.test is adapted to handle NodeLists this could be made to
// work.
// Y.log('els length:' + els.length);
// Y.log('a length:' + a.length);
// Y.log('els tagName:' + els.tagName);
// Y.log('els alert:' + els.alert);
// Y.log('els size:' + els.size);
// Y.log('els array test:' + Y.Array.test(els));
// Y.Lang.type is broken for HTMLElementCollections in Safari. isObject
// returns false because typeof returns function
// Y.log('els isObject:' + Y.Lang.isObject(els)); // false in Safari
// Y.log('els type:' + Y.Lang.type(els) + '+'); // object
// Y.log('els typeof:' + typeof els); // function
// Y.log('els isFunction:' + Y.Lang.isFunction(els)); // false
// Y.log('els.call:' + els.call);
// Y.log('els.apply:' + els.apply);
},
testEach: function () {
var calls = 0,
calls += 1;
});
}, obj);
},
testHash: function () {
{a: 'foo', b: 'bar', c: true},
'keys should be mapped to values; true is used for missing values'
);
{a: true, b: true, c: true},
'the values array is optional'
);
// TODO: Y.Array.hash() should probably skip falsy keys.
// Y.ArrayAssert.itemsAreSame(
// ['a', 'b'],
// Y.Object.keys(Y.Array.hash(['a', undefined, null, false, 'b'], ['foo', 'bar'])),
// 'falsy keys should be skipped'
// );
},
testIndexOf: function () {
// TODO: support fromIndex
},
testNumericSort: function () {
// the stock sort behavior should fail to produce desired result
},
testSome: function () {
calls = 0;
calls += 1;
if (v === 2) { return 'truthy'; }
}), 'should return true');
}, obj), 'should return false');
},
testTest: function () {
// Y.Assert.areEqual(1, Y.Array.test('string'.toCharArray()));
Y.Assert.areEqual(2, Y.Array.test(arguments), 'arguments should be arraylike'); // arguments collection
Y.Assert.areEqual(2, Y.Array.test(document.getElementsByTagName('span')), 'htmlelement collections should be arraylike'); // HTMLElementsCollection
// @TODO figure out what to do with this. A NodeList does not contain a collection of Nodes; it
// contains a collection of HTMLElements.
// Y.Assert.areEqual(3, Y.Array.test(Y.all('#btnRun')), 'nodelists should be specifically identified as a special collection'); // NodeList
Y.Assert.areEqual(0, Y.Array.test(Y.all('span')), 'nodelists are not currently considered arraylike'); // NodeList
}
}));