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

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

Issue 1189743003: [destructuring] Implement parameter pattern matching. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix magic number issue Created 5 years, 6 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
« no previous file with comments | « src/snapshot/serialize.cc ('k') | test/mjsunit/harmony/destructuring.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 675b48797952dbaf3e0afd23b933c61651ea1998..1aa520183d21749f14f529077dbee86a9dbf5f71 100644
--- a/test/cctest/test-parsing.cc
+++ b/test/cctest/test-parsing.cc
@@ -6389,7 +6389,6 @@ TEST(DestructuringPositiveTests) {
{"function f(", ") {}"},
{"function f(argument1, ", ") {}"},
{"var f = (", ") => {};"},
- {"var f = ", " => {};"},
{"var f = (argument1,", ") => {};"},
{NULL, NULL}};
@@ -6417,6 +6416,7 @@ TEST(DestructuringPositiveTests) {
"{42 : x = 42}",
"{42e-2 : x}",
"{42e-2 : x = 42}",
+ "{x : y, x : z}",
"{'hi' : x}",
"{'hi' : x = 42}",
"{var: x}",
@@ -6605,6 +6605,115 @@ TEST(DestructuringDisallowPatternsInForVarIn) {
}
+TEST(DestructuringDuplicateParams) {
+ i::FLAG_harmony_destructuring = true;
+ i::FLAG_harmony_arrow_functions = true;
+ i::FLAG_harmony_computed_property_names = true;
+ static const ParserFlag always_flags[] = {
+ kAllowHarmonyObjectLiterals, kAllowHarmonyComputedPropertyNames,
+ kAllowHarmonyArrowFunctions, kAllowHarmonyDestructuring};
+ const char* context_data[][2] = {{"'use strict';", ""},
+ {"function outer() { 'use strict';", "}"},
+ {nullptr, nullptr}};
+
+
+ // clang-format off
+ const char* error_data[] = {
+ "function f(x,x){}",
+ "function f(x, {x : x}){}",
+ "function f(x, {x}){}",
+ "function f({x,x}) {}",
+ "function f([x,x]) {}",
+ "function f(x, [y,{z:x}]) {}",
+ "function f([x,{y:x}]) {}",
+ // non-simple parameter list causes duplicates to be errors in sloppy mode.
+ "function f(x, x, {a}) {}",
+ nullptr};
+ // clang-format on
+ RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags,
+ arraysize(always_flags));
+}
+
+
+TEST(DestructuringDuplicateParamsSloppy) {
+ i::FLAG_harmony_destructuring = true;
+ i::FLAG_harmony_arrow_functions = true;
+ i::FLAG_harmony_computed_property_names = true;
+ static const ParserFlag always_flags[] = {
+ kAllowHarmonyObjectLiterals, kAllowHarmonyComputedPropertyNames,
+ kAllowHarmonyArrowFunctions, kAllowHarmonyDestructuring};
+ const char* context_data[][2] = {
+ {"", ""}, {"function outer() {", "}"}, {nullptr, nullptr}};
+
+
+ // clang-format off
+ const char* error_data[] = {
+ // non-simple parameter list causes duplicates to be errors in sloppy mode.
+ "function f(x, {x : x}){}",
+ "function f(x, {x}){}",
+ "function f({x,x}) {}",
+ "function f(x, x, {a}) {}",
+ nullptr};
+ // clang-format on
+ RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags,
+ arraysize(always_flags));
+}
+
+
+TEST(DestructuringDisallowPatternsInSingleParamArrows) {
+ i::FLAG_harmony_destructuring = true;
+ i::FLAG_harmony_arrow_functions = true;
+ i::FLAG_harmony_computed_property_names = true;
+ static const ParserFlag always_flags[] = {
+ kAllowHarmonyObjectLiterals, kAllowHarmonyComputedPropertyNames,
+ kAllowHarmonyArrowFunctions, kAllowHarmonyDestructuring};
+ const char* context_data[][2] = {{"'use strict';", ""},
+ {"function outer() { 'use strict';", "}"},
+ {"", ""},
+ {"function outer() { ", "}"},
+ {nullptr, nullptr}};
+
+ // clang-format off
+ const char* error_data[] = {
+ "var f = {x} => {};",
+ "var f = {x,y} => {};",
+ nullptr};
+ // clang-format on
+ RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags,
+ arraysize(always_flags));
+}
+
+
+TEST(DestructuringDisallowPatternsInRestParams) {
+ i::FLAG_harmony_destructuring = true;
+ i::FLAG_harmony_arrow_functions = true;
+ i::FLAG_harmony_rest_parameters = true;
+ i::FLAG_harmony_computed_property_names = true;
+ static const ParserFlag always_flags[] = {
+ kAllowHarmonyObjectLiterals, kAllowHarmonyComputedPropertyNames,
+ kAllowHarmonyArrowFunctions, kAllowHarmonyRestParameters,
+ kAllowHarmonyDestructuring};
+ const char* context_data[][2] = {{"'use strict';", ""},
+ {"function outer() { 'use strict';", "}"},
+ {"", ""},
+ {"function outer() { ", "}"},
+ {nullptr, nullptr}};
+
+ // clang-format off
+ const char* error_data[] = {
+ "function(...{}) {}",
+ "function(...{x}) {}",
+ "function(...[x]) {}",
+ "(...{}) => {}",
+ "(...{x}) => {}",
+ "(...[x]) => {}",
+ nullptr};
+ // clang-format on
+ RunParserSyncTest(context_data, error_data, kError, NULL, 0, always_flags,
+ arraysize(always_flags));
+}
+
+
TEST(SpreadArray) {
i::FLAG_harmony_spread_arrays = true;
« no previous file with comments | « src/snapshot/serialize.cc ('k') | test/mjsunit/harmony/destructuring.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698