michael@0: load(libdir + "asserts.js"); michael@0: load(libdir + "iteration.js"); michael@0: load(libdir + "eqArrayHelper.js"); michael@0: michael@0: assertEqArray([...[1, 2, 3]], [1, 2, 3]); michael@0: assertEqArray([1, ...[2, 3, 4], 5], [1, 2, 3, 4, 5]); michael@0: assertEqArray([1, ...[], 2], [1, 2]); michael@0: assertEqArray([1, ...[2, 3], 4, ...[5, 6]], [1, 2, 3, 4, 5, 6]); michael@0: assertEqArray([1, ...[], 2], [1, 2]); michael@0: assertEqArray([1,, ...[2]], [1,, 2]); michael@0: assertEqArray([1,, ...[2],, 3,, 4,], [1,, 2,, 3,, 4,]); michael@0: assertEqArray([...[1, 2, 3],,,,], [1, 2, 3,,,,]); michael@0: assertEqArray([,,...[1, 2, 3],,,,], [,,1,2,3,,,,]); michael@0: michael@0: assertEqArray([...[undefined]], [undefined]); michael@0: michael@0: // other iterable objects michael@0: assertEqArray([...new Int32Array([1, 2, 3])], [1, 2, 3]); michael@0: assertEqArray([..."abc"], ["a", "b", "c"]); michael@0: assertEqArray([...[1, 2, 3][std_iterator]()], [1, 2, 3]); michael@0: assertEqArray([...Set([1, 2, 3])], [1, 2, 3]); michael@0: assertEqArray([...Map([["a", "A"], ["b", "B"], ["c", "C"]])].map(([k, v]) => k + v), ["aA", "bB", "cC"]); michael@0: let itr = {}; michael@0: itr[std_iterator] = function () { michael@0: return { michael@0: i: 1, michael@0: next: function() { michael@0: if (this.i < 4) michael@0: return { value: this.i++, done: false }; michael@0: else michael@0: return { value: undefined, done: true }; michael@0: } michael@0: }; michael@0: } michael@0: assertEqArray([...itr], [1, 2, 3]); michael@0: function* gen() { michael@0: for (let i = 1; i < 4; i ++) michael@0: yield i; michael@0: } michael@0: assertEqArray([...gen()], [1, 2, 3]); michael@0: michael@0: let a, b = [1, 2, 3]; michael@0: assertEqArray([...a=b], [1, 2, 3]); michael@0: michael@0: // According to the draft spec, null and undefined are to be treated as empty michael@0: // arrays. However, they are not iterable. If the spec is not changed to be in michael@0: // terms of iterables, these tests should be fixed. michael@0: //assertEqArray([1, ...null, 2], [1, 2]); michael@0: //assertEqArray([1, ...undefined, 2], [1, 2]); michael@0: assertThrowsInstanceOf(() => [...null], TypeError); michael@0: assertThrowsInstanceOf(() => [...undefined], TypeError); michael@0: