]> git.r.bdr.sh - rbdr/dotfiles/blob - atom/packages/vim-mode/node_modules/grim/node_modules/emissary/node_modules/es6-weak-map/node_modules/es5-ext/test/array/from/shim.js
310302ac486645fa66c9f007b1a969f039369772
[rbdr/dotfiles] / atom / packages / vim-mode / node_modules / grim / node_modules / emissary / node_modules / es6-weak-map / node_modules / es5-ext / test / array / from / shim.js
1 // Some tests taken from: https://github.com/mathiasbynens/Array.from/blob/master/tests/tests.js
2
3 'use strict';
4
5 module.exports = function (t, a) {
6 var o = [1, 2, 3], MyType;
7 a.not(t(o), o, "Array");
8 a.deep(t(o), o, "Array: same content");
9 a.deep(t('12r3v'), ['1', '2', 'r', '3', 'v'], "String");
10 a.deep(t((function () { return arguments; }(3, o, 'raz'))),
11 [3, o, 'raz'], "Arguments");
12 a.deep(t((function () { return arguments; }(3))), [3],
13 "Arguments with one numeric value");
14
15 a.deep(t({ 0: 'raz', 1: 'dwa', length: 2 }), ['raz', 'dwa'], "Other");
16
17 a.deep(t(o, function (val) { return (val + 2) * 10; }, 10), [30, 40, 50],
18 "Mapping");
19
20 a.throws(function () { t(); }, TypeError, "Undefined");
21 a.deep(t(3), [], "Primitive");
22
23 a(t.length, 1, "Length");
24 a.deep(t({ length: 0 }), [], "No values Array-like");
25 a.deep(t({ length: -1 }), [], "Invalid length Array-like");
26 a.deep(t({ length: -Infinity }), [], "Invalid length Array-like #2");
27 a.throws(function () { t(undefined); }, TypeError, "Undefined");
28 a.throws(function () { t(null); }, TypeError, "Null");
29 a.deep(t(false), [], "Boolean");
30 a.deep(t(-Infinity), [], "Inifity");
31 a.deep(t(-0), [], "-0");
32 a.deep(t(+0), [], "+0");
33 a.deep(t(1), [], "1");
34 a.deep(t(+Infinity), [], "+Infinity");
35 a.deep(t({}), [], "Plain object");
36 a.deep(t({ length: 1 }), [undefined], "Sparse array-like");
37 a.deep(t({ '0': 'a', '1': 'b', length: 2 }, function (x) { return x + x; }), ['aa', 'bb'],
38 "Map");
39 a.deep(t({ '0': 'a', '1': 'b', length: 2 }, function (x) { return String(this); }, undefined),
40 ['undefined', 'undefined'], "Map context");
41 a.deep(t({ '0': 'a', '1': 'b', length: 2 }, function (x) { return String(this); }, 'x'),
42 ['x', 'x'], "Map primitive context");
43 a.throws(function () { t({}, 'foo', 'x'); }, TypeError, "Non callable for map");
44
45 a.deep(t.call(null, { length: 1, '0': 'a' }), ['a'], "Null context");
46
47 a(t({ __proto__: { '0': 'abc', length: 1 } })[0], 'abc', "Values on prototype");
48
49 a.throws(function () { t.call(function () { return Object.freeze({}); }, {}); },
50 TypeError, "Contructor producing freezed objects");
51
52 // Ensure no setters are called for the indexes
53 // Ensure no setters are called for the indexes
54 MyType = function () {};
55 Object.defineProperty(MyType.prototype, '0', {
56 set: function (x) { throw new Error('Setter called: ' + x); }
57 });
58 a.deep(t.call(MyType, { '0': 'abc', length: 1 }), { '0': 'abc', length: 1 },
59 "Defined not set");
60 };