1 // Most tests taken from https://github.com/mathiasbynens/Array.of/blob/master/tests/tests.js
2 // Thanks @mathiasbynens
6 var defineProperty = Object.defineProperty;
8 module.exports = function (t, a) {
9 var x = {}, testObject, MyType;
11 a.deep(t(), [], "No arguments");
12 a.deep(t(3), [3], "One numeric argument");
13 a.deep(t(3, 'raz', null, x, undefined), [3, 'raz', null, x, undefined],
16 a(t.length, 0, "Length");
18 a.deep(t('abc'), ['abc'], "String");
19 a.deep(t(undefined), [undefined], "Undefined");
20 a.deep(t(null), [null], "Null");
21 a.deep(t(false), [false], "Boolean");
22 a.deep(t(-Infinity), [-Infinity], "Infinity");
23 a.deep(t(-0), [-0], "-0");
24 a.deep(t(+0), [+0], "+0");
25 a.deep(t(1), [1], "1");
26 a.deep(t(1, 2, 3), [1, 2, 3], "Numeric args");
27 a.deep(t(+Infinity), [+Infinity], "+Infinity");
28 a.deep(t({ '0': 'a', '1': 'b', '2': 'c', length: 3 }),
29 [{ '0': 'a', '1': 'b', '2': 'c', length: 3 }], "Array like");
30 a.deep(t(undefined, null, false, -Infinity, -0, +0, 1, 2, +Infinity),
31 [undefined, null, false, -Infinity, -0, +0, 1, 2, +Infinity], "Falsy arguments");
34 a.deep(t.call(null, 'abc'), ['abc'], "String");
35 a.deep(t.call(null, undefined), [undefined], "Undefined");
36 a.deep(t.call(null, null), [null], "Null");
37 a.deep(t.call(null, false), [false], "Boolean");
38 a.deep(t.call(null, -Infinity), [-Infinity], "-Infinity");
39 a.deep(t.call(null, -0), [-0], "-0");
40 a.deep(t.call(null, +0), [+0], "+0");
41 a.deep(t.call(null, 1), [1], "1");
42 a.deep(t.call(null, 1, 2, 3), [1, 2, 3], "Numeric");
43 a.deep(t.call(null, +Infinity), [+Infinity], "+Infinity");
44 a.deep(t.call(null, { '0': 'a', '1': 'b', '2': 'c', length: 3 }),
45 [{ '0': 'a', '1': 'b', '2': 'c', length: 3 }], "Array-like");
46 a.deep(t.call(null, undefined, null, false, -Infinity, -0, +0, 1, 2, +Infinity),
47 [undefined, null, false, -Infinity, -0, +0, 1, 2, +Infinity], "Falsy");
49 a.h1("Other constructor context");
50 a.deep(t.call(Object, 1, 2, 3), { '0': 1, '1': 2, '2': 3, length: 3 }, "Many arguments");
52 testObject = Object(3);
56 testObject.length = 3;
57 a.deep(t.call(Object, 1, 2, 3), testObject, "Test object");
58 a(t.call(Object).length, 0, "No arguments");
59 a.throws(function () { t.call(function () { return Object.freeze({}); }); }, TypeError,
62 // Ensure no setters are called for the indexes
63 MyType = function () {};
64 defineProperty(MyType.prototype, '0', {
65 set: function (x) { throw new Error('Setter called: ' + x); }
67 a.deep(t.call(MyType, 'abc'), { '0': 'abc', length: 1 }, "Define, not set");