1425bb815Sopenharmony_ci// Copyright JS Foundation and other contributors, http://js.foundation
2425bb815Sopenharmony_ci//
3425bb815Sopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License");
4425bb815Sopenharmony_ci// you may not use this file except in compliance with the License.
5425bb815Sopenharmony_ci// You may obtain a copy of the License at
6425bb815Sopenharmony_ci//
7425bb815Sopenharmony_ci//     http://www.apache.org/licenses/LICENSE-2.0
8425bb815Sopenharmony_ci//
9425bb815Sopenharmony_ci// Unless required by applicable law or agreed to in writing, software
10425bb815Sopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS
11425bb815Sopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12425bb815Sopenharmony_ci// See the License for the specific language governing permissions and
13425bb815Sopenharmony_ci// limitations under the License.
14425bb815Sopenharmony_ci
15425bb815Sopenharmony_ci// Test with regular inputs
16425bb815Sopenharmony_civar array1 = Array.of(1, 2, 3, 4, 5);
17425bb815Sopenharmony_ciassert(array1.length === 5);
18425bb815Sopenharmony_ciassert(array1[2] === 3);
19425bb815Sopenharmony_ci
20425bb815Sopenharmony_ci// Test with no input
21425bb815Sopenharmony_civar array2 = Array.of();
22425bb815Sopenharmony_ciassert(array2.length === 0);
23425bb815Sopenharmony_ciassert(array2[0] === undefined);
24425bb815Sopenharmony_ci
25425bb815Sopenharmony_ci// Test when an input is another array
26425bb815Sopenharmony_civar array3 = Array.of(array1, 6, 7);
27425bb815Sopenharmony_ciassert(array3.length === 3);
28425bb815Sopenharmony_ciassert(array3[0] instanceof Array);
29425bb815Sopenharmony_ciassert(array3[0][3] === 4);
30425bb815Sopenharmony_ciassert(array3[2] === 7);
31425bb815Sopenharmony_ci
32425bb815Sopenharmony_ci// Test with undefined
33425bb815Sopenharmony_civar array4 = Array.of(undefined);
34425bb815Sopenharmony_ciassert(array4.length === 1);
35425bb815Sopenharmony_ciassert(array4[0] === undefined);
36425bb815Sopenharmony_ci
37425bb815Sopenharmony_ci// Test when input is an object
38425bb815Sopenharmony_civar obj = {
39425bb815Sopenharmony_ci  0: 0,
40425bb815Sopenharmony_ci  1: 1
41425bb815Sopenharmony_ci};
42425bb815Sopenharmony_ci
43425bb815Sopenharmony_civar array5 = Array.of(obj, 2, 3);
44425bb815Sopenharmony_ciassert(array5[0] instanceof Object);
45425bb815Sopenharmony_ciassert(array5[0][0] === 0);
46425bb815Sopenharmony_ciassert(array5[0][1] === 1);
47425bb815Sopenharmony_ciassert(array5[2] === 3);
48425bb815Sopenharmony_ci
49425bb815Sopenharmony_ci// Test with array holes
50425bb815Sopenharmony_civar array6 = Array.of.apply(null, [,,undefined]);
51425bb815Sopenharmony_ciassert(array6.length === 3);
52425bb815Sopenharmony_ciassert(array6[0] === undefined);
53425bb815Sopenharmony_ci
54425bb815Sopenharmony_ci// Test with another class
55425bb815Sopenharmony_civar hits = 0;
56425bb815Sopenharmony_cifunction Test() {
57425bb815Sopenharmony_ci    hits++;
58425bb815Sopenharmony_ci}
59425bb815Sopenharmony_ciTest.of = Array.of;
60425bb815Sopenharmony_ci
61425bb815Sopenharmony_cihits = 0;
62425bb815Sopenharmony_civar array6 = Test.of(1, 2);
63425bb815Sopenharmony_ciassert(hits === 1);
64425bb815Sopenharmony_ciassert(array6.length === 2);
65425bb815Sopenharmony_ciassert(array6[1] === 2);
66425bb815Sopenharmony_ci
67425bb815Sopenharmony_ci// Test with bounded builtin function
68425bb815Sopenharmony_civar boundedBuiltinFn = Array.of.bind(Array);
69425bb815Sopenharmony_civar array7 = Array.of.call(boundedBuiltinFn, boundedBuiltinFn);
70425bb815Sopenharmony_ciassert(array7.length === 1);
71425bb815Sopenharmony_ciassert(array7[0] === boundedBuiltinFn);
72425bb815Sopenharmony_ci
73425bb815Sopenharmony_ci// Test superficial features
74425bb815Sopenharmony_civar desc = Object.getOwnPropertyDescriptor(Array, "of");
75425bb815Sopenharmony_ciassert(desc.configurable === true);
76425bb815Sopenharmony_ciassert(desc.writable === true);
77425bb815Sopenharmony_ciassert(desc.enumerable === false);
78425bb815Sopenharmony_ciassert(Array.of.length === 0);
79