1// Copyright JS Foundation and other contributors, http://js.foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15// Test with regular inputs
16var array1 = Array.of(1, 2, 3, 4, 5);
17assert(array1.length === 5);
18assert(array1[2] === 3);
19
20// Test with no input
21var array2 = Array.of();
22assert(array2.length === 0);
23assert(array2[0] === undefined);
24
25// Test when an input is another array
26var array3 = Array.of(array1, 6, 7);
27assert(array3.length === 3);
28assert(array3[0] instanceof Array);
29assert(array3[0][3] === 4);
30assert(array3[2] === 7);
31
32// Test with undefined
33var array4 = Array.of(undefined);
34assert(array4.length === 1);
35assert(array4[0] === undefined);
36
37// Test when input is an object
38var obj = {
39  0: 0,
40  1: 1
41};
42
43var array5 = Array.of(obj, 2, 3);
44assert(array5[0] instanceof Object);
45assert(array5[0][0] === 0);
46assert(array5[0][1] === 1);
47assert(array5[2] === 3);
48
49// Test with array holes
50var array6 = Array.of.apply(null, [,,undefined]);
51assert(array6.length === 3);
52assert(array6[0] === undefined);
53
54// Test with another class
55var hits = 0;
56function Test() {
57    hits++;
58}
59Test.of = Array.of;
60
61hits = 0;
62var array6 = Test.of(1, 2);
63assert(hits === 1);
64assert(array6.length === 2);
65assert(array6[1] === 2);
66
67// Test with bounded builtin function
68var boundedBuiltinFn = Array.of.bind(Array);
69var array7 = Array.of.call(boundedBuiltinFn, boundedBuiltinFn);
70assert(array7.length === 1);
71assert(array7[0] === boundedBuiltinFn);
72
73// Test superficial features
74var desc = Object.getOwnPropertyDescriptor(Array, "of");
75assert(desc.configurable === true);
76assert(desc.writable === true);
77assert(desc.enumerable === false);
78assert(Array.of.length === 0);
79