OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 the V8 project authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Flags: --harmony | |
arv (Not doing code reviews)
2014/07/02 18:26:44
Use more specific flag(s).
| |
6 | |
7 assertEquals(1, Array.from.length); | |
8 | |
9 assertArrayEquals(Array.from(NaN), []); | |
10 assertArrayEquals(Array.from(Infinity), []); | |
11 assertArrayEquals(Array.from(10000000), []); | |
12 assertArrayEquals(Array.from('test'), ['t', 'e', 's', 't']); | |
13 assertArrayEquals(Array.from({length: 1, '0': { 'foo': 'bar' }}), [{'foo': 'bar' }]); | |
arv (Not doing code reviews)
2014/07/02 18:26:44
Can you add test with length = -1
I wish we could
| |
14 assertArrayEquals(Array.from(['foo', 'bar', 'baz']), ['foo', 'bar', 'baz']); | |
15 assertArrayEquals(Array.from((new Set).add('foo').add('bar').add('baz')), ['foo' , 'bar', 'baz']); | |
16 assertArrayEquals(Array.from((new Map).set(0, 'foo').set(1, 'bar').set(2, 'baz') ), [[0, 'foo'], [1, 'bar'], [2, 'baz']]); | |
17 assertArrayEquals(Array.from(generator()), ['a', 'b', 'c']); | |
18 assertArrayEquals(Array.from('test', function(x) { | |
19 return this.filter(x); | |
20 }, { | |
21 filter: function(x) { return x.toUpperCase(); } | |
22 }), ['T', 'E', 'S', 'T']); | |
23 assertArrayEquals(Array.from('test', function(x) { | |
24 return x.toUpperCase(); | |
25 }), ['T', 'E', 'S', 'T']); | |
26 | |
27 // Mozilla: | |
28 // Array.from on a string handles surrogate pairs correctly. | |
29 var gclef = "\uD834\uDD1E"; // U+1D11E MUSICAL SYMBOL G CLEF | |
30 assertArrayEquals(Array.from(gclef), [gclef]); | |
31 assertArrayEquals(Array.from(gclef + " G"), [gclef, " ", "G"]); | |
32 | |
33 function* generator() { | |
34 var a = ['a', 'b', 'c']; | |
arv (Not doing code reviews)
2014/07/02 18:26:43
function* generator() {
yield 'a';
yield 'b';
| |
35 var n = 0; | |
36 while (n < a.length) { | |
37 yield a[n++]; | |
38 } | |
39 } | |
40 | |
41 assertThrows('Array.from(null)', TypeError); | |
42 assertThrows('Array.from(undefined)', TypeError); | |
43 | |
44 var nullIterator = {}; | |
45 nullIterator[Symbol.iterator] = null; | |
46 assertThrows('Array.from(nullIterator)', TypeError); | |
47 | |
48 var nonObjIterator = {}; | |
49 nonObjIterator[Symbol.iterator] = function() { return "nonObject"; }; | |
50 assertThrows('Array.from(nonObjIterator)', TypeError); | |
51 | |
52 assertThrows('Array.from([], null)', TypeError); | |
arv (Not doing code reviews)
2014/07/02 18:26:43
This needs more tests. Especially things like call
| |
OLD | NEW |