]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/stress/array-from-with-iterable.js
1 function shouldBe(actual
, expected
) {
2 if (actual
!== expected
)
3 throw new Error('bad value: ' + actual
);
7 var set = new Set([0, 1, 2, 3, 4, 5]);
8 var array
= Array
.from(set);
10 shouldBe(array
.length
, set.size
);
11 for (var i
= 0; i
< array
.length
; ++i
) {
12 shouldBe(set.has(array
[i
]), true);
24 var array
= Array
.from(map
);
26 shouldBe(array
.length
, map
.size
);
27 for (var i
= 0; i
< array
.length
; ++i
) {
28 shouldBe(array
[i
][1], 0);
29 shouldBe(map
.has(array
[i
][0]), true);
30 shouldBe(map
.get(array
[i
][0]), 0);
34 var string
= "Cocoa Cappuccino";
35 var array
= Array
.from(string
);
36 shouldBe(array
.length
, string
.length
);
37 for (var i
= 0; i
< array
.length
; ++i
) {
38 shouldBe(array
[i
], string
[i
]);
41 // Arguments is iterable
42 var argumentsGenerators
= [
62 for (var gen
of argumentsGenerators
) {
63 var args
= gen(1, 2, 3, 4, 5);
64 var array
= Array
.from(args
);
65 shouldBe(array
.length
, args
.length
);
66 for (var i
= 0; i
< array
.length
; ++i
) {
67 shouldBe(array
[i
], args
[i
]);