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

Unified Diff: test/cctest/test-parsing.cc

Issue 1309813007: [es6] implement destructuring assignment (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase*** oops Created 5 years 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
« no previous file with comments | « src/typing-asm.cc ('k') | test/mjsunit/harmony/destructuring-assignment.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-parsing.cc
diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc
index 3a01b217a9132450bb813ee67da9702b6334dbf5..62270d8a0c3439f5f6e8f6c2917319bfa7792bce 100644
--- a/test/cctest/test-parsing.cc
+++ b/test/cctest/test-parsing.cc
@@ -1511,6 +1511,7 @@ enum ParserFlag {
kAllowHarmonySloppy,
kAllowHarmonySloppyLet,
kAllowHarmonyDestructuring,
+ kAllowHarmonyDestructuringAssignment,
kAllowHarmonyNewTarget,
kAllowStrongMode,
kNoLegacyConst
@@ -1536,6 +1537,8 @@ void SetParserFlags(i::ParserBase<Traits>* parser,
parser->set_allow_harmony_sloppy_let(flags.Contains(kAllowHarmonySloppyLet));
parser->set_allow_harmony_destructuring_bind(
flags.Contains(kAllowHarmonyDestructuring));
+ parser->set_allow_harmony_destructuring_assignment(
+ flags.Contains(kAllowHarmonyDestructuringAssignment));
parser->set_allow_strong_mode(flags.Contains(kAllowStrongMode));
parser->set_allow_legacy_const(!flags.Contains(kNoLegacyConst));
}
@@ -6820,6 +6823,264 @@ TEST(DestructuringNegativeTests) {
}
+TEST(DestructuringAssignmentPositiveTests) {
+ const char* context_data[][2] = {
+ {"'use strict'; let x, y, z; (", " = {});"},
+ {"var x, y, z; (", " = {});"},
+ {"'use strict'; let x, y, z; for (x in ", " = {});"},
+ {"'use strict'; let x, y, z; for (x of ", " = {});"},
+ {"var x, y, z; for (x in ", " = {});"},
+ {"var x, y, z; for (x of ", " = {});"},
+ {NULL, NULL}};
+
+ // clang-format off
+ const char* data[] = {
+ "x",
+
+ "{ x : y }",
+ "{ x : foo().y }",
+ "{ x : foo()[y] }",
+ "{ x : y.z }",
+ "{ x : y[z] }",
+ "{ x : { y } }",
+ "{ x : { foo: y } }",
+ "{ x : { foo: foo().y } }",
+ "{ x : { foo: foo()[y] } }",
+ "{ x : { foo: y.z } }",
+ "{ x : { foo: y[z] } }",
+ "{ x : [ y ] }",
+ "{ x : [ foo().y ] }",
+ "{ x : [ foo()[y] ] }",
+ "{ x : [ y.z ] }",
+ "{ x : [ y[z] ] }",
+
+ "{ x : y = 10 }",
+ "{ x : foo().y = 10 }",
+ "{ x : foo()[y] = 10 }",
+ "{ x : y.z = 10 }",
+ "{ x : y[z] = 10 }",
+ "{ x : { y = 10 } = {} }",
+ "{ x : { foo: y = 10 } = {} }",
+ "{ x : { foo: foo().y = 10 } = {} }",
+ "{ x : { foo: foo()[y] = 10 } = {} }",
+ "{ x : { foo: y.z = 10 } = {} }",
+ "{ x : { foo: y[z] = 10 } = {} }",
+ "{ x : [ y = 10 ] = {} }",
+ "{ x : [ foo().y = 10 ] = {} }",
+ "{ x : [ foo()[y] = 10 ] = {} }",
+ "{ x : [ y.z = 10 ] = {} }",
+ "{ x : [ y[z] = 10 ] = {} }",
+
+ "[ x ]",
+ "[ foo().x ]",
+ "[ foo()[x] ]",
+ "[ x.y ]",
+ "[ x[y] ]",
+ "[ { x } ]",
+ "[ { x : y } ]",
+ "[ { x : foo().y } ]",
+ "[ { x : foo()[y] } ]",
+ "[ { x : x.y } ]",
+ "[ { x : x[y] } ]",
+ "[ [ x ] ]",
+ "[ [ foo().x ] ]",
+ "[ [ foo()[x] ] ]",
+ "[ [ x.y ] ]",
+ "[ [ x[y] ] ]",
+
+ "[ x = 10 ]",
+ "[ foo().x = 10 ]",
+ "[ foo()[x] = 10 ]",
+ "[ x.y = 10 ]",
+ "[ x[y] = 10 ]",
+ "[ { x = 10 } = {} ]",
+ "[ { x : y = 10 } = {} ]",
+ "[ { x : foo().y = 10 } = {} ]",
+ "[ { x : foo()[y] = 10 } = {} ]",
+ "[ { x : x.y = 10 } = {} ]",
+ "[ { x : x[y] = 10 } = {} ]",
+ "[ [ x = 10 ] = {} ]",
+ "[ [ foo().x = 10 ] = {} ]",
+ "[ [ foo()[x] = 10 ] = {} ]",
+ "[ [ x.y = 10 ] = {} ]",
+ "[ [ x[y] = 10 ] = {} ]",
+
+ "{ x : y }",
+ "{ x : y = 1 }",
+ "{ x }",
+ "{ x, y, z }",
+ "{ x = 1, y: z, z: y }",
+ "{x = 42, y = 15}",
+ "[x]",
+ "[x = 1]",
+ "[x,y,z]",
+ "[x, y = 42, z]",
+ "{ x : x, y : y }",
+ "{ x : x = 1, y : y }",
+ "{ x : x, y : y = 42 }",
+ "[]",
+ "{}",
+ "[{x:x, y:y}, [,x,z,]]",
+ "[{x:x = 1, y:y = 2}, [z = 3, z = 4, z = 5]]",
+ "[x,,y]",
+ "[(x),,(y)]",
+ "[(x)]",
+ "{42 : x}",
+ "{42 : x = 42}",
+ "{42e-2 : x}",
+ "{42e-2 : x = 42}",
+ "{'hi' : x}",
+ "{'hi' : x = 42}",
+ "{var: x}",
+ "{var: x = 42}",
+ "{var: (x) = 42}",
+ "{[x] : z}",
+ "{[1+1] : z}",
+ "{[1+1] : (z)}",
+ "{[foo()] : z}",
+ "{[foo()] : (z)}",
+ "{[foo()] : foo().bar}",
+ "{[foo()] : foo()['bar']}",
+ "{[foo()] : this.bar}",
+ "{[foo()] : this['bar']}",
+ "{[foo()] : 'foo'.bar}",
+ "{[foo()] : 'foo'['bar']}",
+ "[...x]",
+ "[x,y,...z]",
+ "[x,,...z]",
+ "{ x: y } = z",
+ "[x, y] = z",
+ "{ x: y } = { z }",
+ "[x, y] = { z }",
+ "{ x: y } = [ z ]",
+ "[x, y] = [ z ]",
+ "[((x, y) => z).x]",
+ "{x: ((y, z) => z).x}",
+ "[((x, y) => z)['x']]",
+ "{x: ((y, z) => z)['x']}",
+
+ "{x: { y = 10 } }",
+ "[(({ x } = { x: 1 }) => x).a]",
+ NULL};
+ // clang-format on
+ static const ParserFlag always_flags[] = {
+ kAllowHarmonyDestructuringAssignment, kAllowHarmonyDestructuring,
+ kAllowHarmonyDefaultParameters};
+ RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags,
+ arraysize(always_flags));
+
+ const char* empty_context_data[][2] = {
+ {"'use strict';", ""}, {"", ""}, {NULL, NULL}};
+
+ // CoverInitializedName ambiguity handling in various contexts
+ const char* ambiguity_data[] = {
+ "var foo = { x = 10 } = {};",
+ "var foo = { q } = { x = 10 } = {};",
+ "var foo; foo = { x = 10 } = {};",
+ "var foo; foo = { q } = { x = 10 } = {};",
+ "var x; ({ x = 10 } = {});",
+ "var q, x; ({ q } = { x = 10 } = {});",
+ "var x; [{ x = 10 } = {}]",
+ "var x; (true ? { x = true } = {} : { x = false } = {})",
+ "var q, x; (q, { x = 10 } = {});",
+ "var { x = 10 } = { x = 20 } = {};",
+ "var { x = 10 } = (o = { x = 20 } = {});",
+ "var x; (({ x = 10 } = { x = 20 } = {}) => x)({})",
+ NULL,
+ };
+ RunParserSyncTest(empty_context_data, ambiguity_data, kSuccess, NULL, 0,
+ always_flags, arraysize(always_flags));
+}
+
+
+TEST(DestructuringAssignmentNegativeTests) {
+ const char* context_data[][2] = {
+ {"'use strict'; let x, y, z; (", " = {});"},
+ {"var x, y, z; (", " = {});"},
+ {"'use strict'; let x, y, z; for (x in ", " = {});"},
+ {"'use strict'; let x, y, z; for (x of ", " = {});"},
+ {"var x, y, z; for (x in ", " = {});"},
+ {"var x, y, z; for (x of ", " = {});"},
+ {NULL, NULL}};
+
+ // clang-format off
+ const char* data[] = {
+ "{ x : ++y }",
+ "{ x : y * 2 }",
+ "{ ...x }",
+ "{ get x() {} }",
+ "{ set x() {} }",
+ "{ x: y() }",
+ "{ this }",
+ "{ x: this }",
+ "{ x: this = 1 }",
+ "{ super }",
+ "{ x: super }",
+ "{ x: super = 1 }",
+ "{ new.target }",
+ "{ x: new.target }",
+ "{ x: new.target = 1 }",
+ "[x--]",
+ "[--x = 1]",
+ "[x()]",
+ "[this]",
+ "[this = 1]",
+ "[new.target]",
+ "[new.target = 1]",
+ "[super]",
+ "[super = 1]",
+ "[function f() {}]",
+ "[50]",
+ "[(50)]",
+ "[(function() {})]",
+ "[(foo())]",
+ "{ x: 50 }",
+ "{ x: (50) }",
+ "['str']",
+ "{ x: 'str' }",
+ "{ x: ('str') }",
+ "{ x: (foo()) }",
+ "{ x: (function() {}) }",
+ "{ x: y } = 'str'",
+ "[x, y] = 'str'",
+ "[(x,y) => z]",
+ "{x: (y) => z}",
+ "[x, ...y, z]",
+ "[...x,]",
+ "[x, y, ...z = 1]",
+ "[...z = 1]",
+ NULL};
+ // clang-format on
+ static const ParserFlag always_flags[] = {
+ kAllowHarmonyDestructuringAssignment, kAllowHarmonyDestructuring,
+ kAllowHarmonyDefaultParameters};
+ RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
+ arraysize(always_flags));
+
+ const char* empty_context_data[][2] = {
+ {"'use strict';", ""}, {"", ""}, {NULL, NULL}};
+
+ // CoverInitializedName ambiguity handling in various contexts
+ const char* ambiguity_data[] = {
+ "var foo = { x = 10 };",
+ "var foo = { q } = { x = 10 };",
+ "var foo; foo = { x = 10 };",
+ "var foo; foo = { q } = { x = 10 };",
+ "var x; ({ x = 10 });",
+ "var q, x; ({ q } = { x = 10 });",
+ "var x; [{ x = 10 }]",
+ "var x; (true ? { x = true } : { x = false })",
+ "var q, x; (q, { x = 10 });",
+ "var { x = 10 } = { x = 20 };",
+ "var { x = 10 } = (o = { x = 20 });",
+ "var x; (({ x = 10 } = { x = 20 }) => x)({})",
+ NULL,
+ };
+ RunParserSyncTest(empty_context_data, ambiguity_data, kError, NULL, 0,
+ always_flags, arraysize(always_flags));
+}
+
+
TEST(DestructuringDisallowPatternsInForVarIn) {
i::FLAG_harmony_destructuring_bind = true;
static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring};
@@ -7013,9 +7274,8 @@ TEST(DefaultParametersYieldInInitializers) {
kSuccess, NULL, 0, always_flags, arraysize(always_flags));
RunParserSyncTest(sloppy_arrow_context_data, parameter_data, kSuccess, NULL,
0, always_flags, arraysize(always_flags));
- // TODO(wingo): Will change to kSuccess when destructuring assignment lands.
RunParserSyncTest(sloppy_arrow_context_data, destructuring_assignment_data,
- kError, NULL, 0, always_flags, arraysize(always_flags));
+ kSuccess, NULL, 0, always_flags, arraysize(always_flags));
RunParserSyncTest(strict_function_context_data, parameter_data, kError, NULL,
0, always_flags, arraysize(always_flags));
« no previous file with comments | « src/typing-asm.cc ('k') | test/mjsunit/harmony/destructuring-assignment.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698