Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(410)

Unified Diff: test/mjsunit/harmony/spread-call.js

Issue 938443002: [es6] implement spread calls (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add construct support, clean out some gunk Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/mjsunit/harmony/spread-call.js
diff --git a/test/mjsunit/harmony/spread-call.js b/test/mjsunit/harmony/spread-call.js
new file mode 100644
index 0000000000000000000000000000000000000000..7310185dbf904689261501c54f58f03d486fa614
--- /dev/null
+++ b/test/mjsunit/harmony/spread-call.js
@@ -0,0 +1,229 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --harmony-spreadcalls
+
+(function testSpreadCallsStrict() {
+ "use strict"
+ function countArgs() { return arguments.length; }
+
+ // Test this argument
+ function returnThis() { return this; }
+ assertEquals(void 0, returnThis(..."test"));
+
+ // Test argument counting with different iterables
+ assertEquals(0, countArgs(...""));
+ assertEquals(1, countArgs(..."t"));
+ assertEquals(2, countArgs(..."te"));
+ assertEquals(3, countArgs(..."tes"));
+ assertEquals(4, countArgs(..."test"));
+ assertEquals(4, countArgs(..."tes", ..."t"));
+ assertEquals(4, countArgs("t", ..."es", "t"));
+ assertEquals(5, countArgs(..."test!"));
+ assertEquals(5, countArgs(..."tes", ..."t!"));
+ assertEquals(6, countArgs(..."test!!"));
+ assertEquals(6, countArgs(..."tes", ..."t!!"));
+
+ assertEquals(1, countArgs(...[1]));
+ assertEquals(2, countArgs(...[1, 2]));
+ assertEquals(3, countArgs(...[1, 2, 3]));
+ assertEquals(4, countArgs(...[1, 2, 3, 4]));
+ assertEquals(5, countArgs(...[1, 2, 3, 4, 5]));
+ assertEquals(6, countArgs(...[1, 2, 3, 4, 5, 6]));
+
+ assertEquals(1, countArgs(...new Set([1])));
+ assertEquals(2, countArgs(...new Set([1, 2])));
+ assertEquals(3, countArgs(...new Set([1, 2, 3])));
+ assertEquals(4, countArgs(...new Set([1, 2, 3, 4])));
+ assertEquals(5, countArgs(...new Set([1, 2, 3, 4, 5])));
+ assertEquals(6, countArgs(...new Set([1, 2, 3, 4, 5, 6])));
+
+ assertEquals(3, countArgs(...(function*(){ yield 1; yield 2; yield 3; })()));
+
+ // Test values
+ function sum() {
+ var sum = arguments[0];
+ for (var i = 1; i < arguments.length; ++i) {
+ sum += arguments[i];
+ }
+ return sum;
+ }
+
+ assertEquals(void 0, sum(...""));
+ assertEquals(void 0, sum(...[]));
+ assertEquals(void 0, sum(...new Set));
+ assertEquals(void 0, sum(...(function*() { })()));
+
+ assertEquals("test", sum(..."test"));
+ assertEquals(10, sum(...[1, 2, 3, 4]));
+ assertEquals(10, sum(...[1, 2, 3], 4));
+ assertEquals(10, sum(1, ...[2, 3], 4));
+ assertEquals(10, sum(1, ...[2, 3], ...[4]));
+ assertEquals(10, sum(1, 2, ...[3, 4]));
+ assertEquals(10, sum(...new Set([1, 2, 3, 4])));
+ assertEquals(10, sum(...(function*() {
+ yield 1;
+ yield 2;
+ yield 3;
+ yield 4;
+ })()));
+
+ // nested spreads
+ function makeArray() {
+ var result = [];
+ for (var i = 0; i < arguments.length; ++i) {
+ result.push(arguments[i]);
+ }
+ return result;
+ }
+ assertEquals(10, sum(...makeArray(...[1, 2, 3, 4])));
+ assertEquals("test!!!", sum(...makeArray(..."test!!!")));
+
+ // Methods
+ var O = {
+ returnThis: returnThis,
+ countArgs: countArgs,
+ sum: sum,
+ makeArray: makeArray,
+
+ nested: {
+ returnThis: returnThis,
+ countArgs: countArgs,
+ sum: sum,
+ makeArray: makeArray
+ }
+ };
+
+ // Test this argument
+ assertEquals(O, O.returnThis(..."test"));
+ assertEquals(O, O["returnThis"](..."test"));
+ assertEquals(O.nested, O.nested.returnThis(..."test"));
+ assertEquals(O.nested, O.nested["returnThis"](..."test"));
+
+ // Test argument counting with different iterables
+ assertEquals(0, O.countArgs(...""));
+ assertEquals(1, O.countArgs(..."t"));
+ assertEquals(2, O.countArgs(..."te"));
+ assertEquals(3, O.countArgs(..."tes"));
+ assertEquals(4, O.countArgs(..."test"));
+ assertEquals(4, O.countArgs(..."tes", ..."t"));
+ assertEquals(4, O.countArgs("t", ..."es", "t"));
+ assertEquals(5, O.countArgs(..."test!"));
+ assertEquals(5, O.countArgs(..."tes", ..."t!"));
+ assertEquals(6, O.countArgs(..."test!!"));
+ assertEquals(6, O.countArgs(..."tes", ..."t!!"));
+
+ assertEquals(1, O.countArgs(...[1]));
+ assertEquals(2, O.countArgs(...[1, 2]));
+ assertEquals(3, O.countArgs(...[1, 2, 3]));
+ assertEquals(4, O.countArgs(...[1, 2, 3, 4]));
+ assertEquals(5, O.countArgs(...[1, 2, 3, 4, 5]));
+ assertEquals(6, O.countArgs(...[1, 2, 3, 4, 5, 6]));
+
+ assertEquals(1, O.countArgs(...new Set([1])));
+ assertEquals(2, O.countArgs(...new Set([1, 2])));
+ assertEquals(3, O.countArgs(...new Set([1, 2, 3])));
+ assertEquals(4, O.countArgs(...new Set([1, 2, 3, 4])));
+ assertEquals(5, O.countArgs(...new Set([1, 2, 3, 4, 5])));
+ assertEquals(6, O.countArgs(...new Set([1, 2, 3, 4, 5, 6])));
+
+ assertEquals(3, O.countArgs(...(function*(){ yield 1; yield 2; yield 3; })()));
+
+ // Test values
+ assertEquals(void 0, O.sum(...""));
+ assertEquals(void 0, O.sum(...[]));
+ assertEquals(void 0, O.sum(...new Set));
+ assertEquals(void 0, O.sum(...(function*() { })()));
+
+ assertEquals("test", O.sum(..."test"));
+ assertEquals(10, O.sum(...[1, 2, 3, 4]));
+ assertEquals(10, O.sum(...[1, 2, 3], 4));
+ assertEquals(10, O.sum(1, ...[2, 3], 4));
+ assertEquals(10, O.sum(1, ...[2, 3], ...[4]));
+ assertEquals(10, O.sum(1, 2, ...[3, 4]));
+ assertEquals(10, O.sum(...new Set([1, 2, 3, 4])));
+ assertEquals(10, O.sum(...(function*() {
+ yield 1;
+ yield 2;
+ yield 3;
+ yield 4;
+ })()));
+
+ // nested spreads
+ assertEquals(10, O.sum(...O.makeArray(...[1, 2, 3, 4])));
+ assertEquals("test!!!", O.sum(...O.makeArray(..."test!!!")));
+})();
+
+
+(function testSpreadCallsSloppy() {
+ function countArgs() { return arguments.length; }
+
+ // Test argument counting with different iterables
+ assertEquals(0, countArgs(...""));
+ assertEquals(1, countArgs(..."t"));
+ assertEquals(2, countArgs(..."te"));
+ assertEquals(3, countArgs(..."tes"));
+ assertEquals(4, countArgs(..."test"));
+ assertEquals(4, countArgs(..."tes", ..."t"));
+ assertEquals(4, countArgs("t", ..."es", "t"));
+ assertEquals(5, countArgs(..."test!"));
+ assertEquals(5, countArgs(..."tes", ..."t!"));
+ assertEquals(6, countArgs(..."test!!"));
+ assertEquals(6, countArgs(..."tes", ..."t!!"));
+
+ assertEquals(1, countArgs(...[1]));
+ assertEquals(2, countArgs(...[1, 2]));
+ assertEquals(3, countArgs(...[1, 2, 3]));
+ assertEquals(4, countArgs(...[1, 2, 3, 4]));
+ assertEquals(5, countArgs(...[1, 2, 3, 4, 5]));
+ assertEquals(6, countArgs(...[1, 2, 3, 4, 5, 6]));
+
+ assertEquals(1, countArgs(...new Set([1])));
+ assertEquals(2, countArgs(...new Set([1, 2])));
+ assertEquals(3, countArgs(...new Set([1, 2, 3])));
+ assertEquals(4, countArgs(...new Set([1, 2, 3, 4])));
+ assertEquals(5, countArgs(...new Set([1, 2, 3, 4, 5])));
+ assertEquals(6, countArgs(...new Set([1, 2, 3, 4, 5, 6])));
+
+ assertEquals(3, countArgs(...(function*(){ yield 1; yield 2; yield 3; })()));
+
+ // Test values
+ function sum() {
+ var sum = arguments[0];
+ for (var i = 1; i < arguments.length; ++i) {
+ sum += arguments[i];
+ }
+ return sum;
+ }
+
+ assertEquals(void 0, sum(...""));
+ assertEquals(void 0, sum(...[]));
+ assertEquals(void 0, sum(...new Set));
+ assertEquals(void 0, sum(...(function*() { })()));
+
+ assertEquals("test", sum(..."test"));
+ assertEquals(10, sum(...[1, 2, 3, 4]));
+ assertEquals(10, sum(...[1, 2, 3], 4));
+ assertEquals(10, sum(1, ...[2, 3], 4));
+ assertEquals(10, sum(1, ...[2, 3], ...[4]));
+ assertEquals(10, sum(1, 2, ...[3, 4]));
+ assertEquals(10, sum(...new Set([1, 2, 3, 4])));
+ assertEquals(10, sum(...(function*() {
+ yield 1;
+ yield 2;
+ yield 3;
+ yield 4;
+ })()));
+
+ // nested spreads
+ function makeArray() {
+ var result = [];
+ for (var i = 0; i < arguments.length; ++i) {
+ result.push(arguments[i]);
+ }
+ return result;
+ }
+ assertEquals(10, sum(...makeArray(...[1, 2, 3, 4])));
+ assertEquals("test!!!", sum(...makeArray(..."test!!!")));
+})();
arv (Not doing code reviews) 2015/02/18 15:07:06 Maybe some tests with F.p.apply too? function f(s
caitp (gmail) 2015/02/18 15:32:08 Will do

Powered by Google App Engine
This is Rietveld 408576698