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

Unified Diff: test/mjsunit/harmony/destructuring.js

Issue 1139603005: [destructuring] Implement BindingArrayPattern (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 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
« src/parser.cc ('K') | « src/pattern-rewriter.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/mjsunit/harmony/destructuring.js
diff --git a/test/mjsunit/harmony/destructuring.js b/test/mjsunit/harmony/destructuring.js
index 257c4a164dbfb6f7034a534d77269d5737ee3dc7..28535b719a0f07219979b2f67f0e672d9d70d089 100644
--- a/test/mjsunit/harmony/destructuring.js
+++ b/test/mjsunit/harmony/destructuring.js
@@ -388,3 +388,149 @@
TypeError);
}
}());
+
+
+(function TestArrayLiteral() {
+ var [a,b,c] = [1,2,3];
arv (Not doing code reviews) 2015/05/19 17:03:48 ws
Dmitry Lomov (no reviews) 2015/05/20 07:42:42 Done.
+ assertSame(1, a);
+ assertSame(2, b);
+ assertSame(3, c);
+}());
+
+(function TestIterators() {
+ var log = [];
+ function* f() {
+ log.push("1");
+ yield 1;
+ log.push("2");
+ yield 2;
+ log.push("3");
+ yield 3;
+ log.push("done");
+ };
+
+ (function() {
+ log = [];
+ var [a,b,c] = f();
+ assertSame(1, a);
+ assertSame(2, b);
+ assertSame(3, c);
+ assertArrayEquals(["1", "2", "3"], log);
+ }());
+
+ (function() {
+ log = [];
+ var [a,b,c,d] = f();
+ assertSame(1, a);
+ assertSame(2, b);
+ assertSame(3, c);
+ assertSame(undefined, d);
+ assertArrayEquals(["1", "2", "3", "done"], log);
+ }());
+
+ (function() {
+ log = [];
+ var [a,,c] = f();
+ assertSame(1, a);
+ assertSame(3, c);
+ assertArrayEquals(["1", "2", "3"], log);
+ }());
+
+ (function() {
+ log = [];
+ var [a,,c,d] = f();
+ assertSame(1, a);
+ assertSame(3, c);
+ assertSame(undefined, d);
+ assertArrayEquals(["1", "2", "3", "done"], log);
+ }());
+
+ (function() {
+ log = [];
+ // last comma is not an elision.
+ var [a,b,] = f();
+ assertSame(1, a);
+ assertSame(2, b);
+ assertArrayEquals(["1", "2"], log);
+ }());
+
+ (function() {
+ log = [];
+ // last comma is not an elision, but the comma before the last is.
+ var [a,b,,] = f();
+ assertSame(1, a);
+ assertSame(2, b);
+ assertArrayEquals(["1", "2", "3"], log);
+ }());
+
+}());
+
+
+(function TestIteratorsLexical() {
+ 'use strict';
+ var log = [];
+ function* f() {
+ log.push("1");
+ yield 1;
+ log.push("2");
+ yield 2;
+ log.push("3");
+ yield 3;
+ log.push("done");
+ };
+
+ (function() {
+ log = [];
+ let [a,b,c] = f();
+ assertSame(1, a);
+ assertSame(2, b);
+ assertSame(3, c);
+ assertArrayEquals(["1", "2", "3"], log);
+ }());
+
+ (function() {
+ log = [];
+ let [a,b,c,d] = f();
+ assertSame(1, a);
+ assertSame(2, b);
+ assertSame(3, c);
+ assertSame(undefined, d);
+ assertArrayEquals(["1", "2", "3", "done"], log);
+ }());
+
+ (function() {
+ log = [];
+ let [a,,c] = f();
+ assertSame(1, a);
+ assertSame(3, c);
+ assertArrayEquals(["1", "2", "3"], log);
+ }());
+
+ (function() {
+ log = [];
+ let [a,,c,d] = f();
+ assertSame(1, a);
+ assertSame(3, c);
+ assertSame(undefined, d);
+ assertArrayEquals(["1", "2", "3", "done"], log);
+ }());
+
+ (function() {
+ log = [];
+ // last comma is not an elision.
+ let [a,b,] = f();
+ assertSame(1, a);
+ assertSame(2, b);
+ assertArrayEquals(["1", "2"], log);
+ }());
+
+ (function() {
+ log = [];
+ // last comma is not an elision, but the comma before the last is.
+ let [a,b,,] = f();
+ assertSame(1, a);
+ assertSame(2, b);
+ assertArrayEquals(["1", "2", "3"], log);
+ }());
+
arv (Not doing code reviews) 2015/05/19 17:03:48 Can you add some recursive tests too?
Dmitry Lomov (no reviews) 2015/05/20 07:42:42 Done.
+}());
« src/parser.cc ('K') | « src/pattern-rewriter.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698