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

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

Issue 1107053002: Parsing binding patterns. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Minor fix to formatter flags Created 5 years, 8 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/preparser.cc ('k') | no next file » | 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 bd3247e044a738947d859880a7a84ccb708bacbc..8d4ff02c55acf8c56a93f07778fa388a203fbdab 100644
--- a/test/cctest/test-parsing.cc
+++ b/test/cctest/test-parsing.cc
@@ -1381,8 +1381,9 @@ enum ParserFlag {
kAllowHarmonySloppy,
kAllowHarmonyUnicode,
kAllowHarmonyComputedPropertyNames,
- kAllowStrongMode,
- kAllowHarmonySpreadCalls
+ kAllowHarmonySpreadCalls,
+ kAllowHarmonyDestructuring,
+ kAllowStrongMode
};
@@ -1411,6 +1412,8 @@ void SetParserFlags(i::ParserBase<Traits>* parser,
parser->set_allow_harmony_unicode(flags.Contains(kAllowHarmonyUnicode));
parser->set_allow_harmony_computed_property_names(
flags.Contains(kAllowHarmonyComputedPropertyNames));
+ parser->set_allow_harmony_destructuring(
+ flags.Contains(kAllowHarmonyDestructuring));
parser->set_allow_strong_mode(flags.Contains(kAllowStrongMode));
}
@@ -6344,3 +6347,122 @@ TEST(StrongModeFreeVariablesNotDeclared) {
*exception));
}
}
+
+
+TEST(DestructuringPositiveTests) {
+ i::FLAG_harmony_destructuring = true;
+
+ const char* context_data[][2] = {{"'use strict'; let ", " = {};"},
+ {"var ", " = {};"},
+ {"'use strict'; const ", " = {};"},
+ {NULL, NULL}};
+
+ // clang-format off
+ const char* data[] = {
+ "a",
+ "{ x : y }",
+ "[a]",
+ "[a,b,c]",
+ "{ x : x, y : y }",
+ "[]",
+ "{}",
+ "[{x:x, y:y}, [a,b,c]]",
arv (Not doing code reviews) 2015/04/28 13:42:14 moar "{var: x}", "{42: x}", "{+2: x}", "{-2: x}",
Dmitry Lomov (no reviews) 2015/04/28 16:01:36 Done. {+2: x} and {-2: x} are not valid AFAIU.
arv (Not doing code reviews) 2015/04/28 16:07:22 You are right... but 42e-2 is... not needed though
+ "[a,,b]",
+ NULL};
+ // clang-format on
+ static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring};
+ RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags,
+ arraysize(always_flags));
+}
+
+
+TEST(DestructuringNegativeTests) {
+ i::FLAG_harmony_destructuring = true;
+ static const ParserFlag always_flags[] = {kAllowHarmonyDestructuring};
+
+ { // All modes.
+ const char* context_data[][2] = {{"'use strict'; let ", " = {};"},
+ {"var ", " = {};"},
+ {"'use strict'; const ", " = {};"},
+ {NULL, NULL}};
+
+ // clang-format off
+ const char* data[] = {
+ "a++",
+ "++a",
+ "delete a",
+ "void a",
+ "typeof a",
+ "--a",
+ "+a",
+ "-a",
+ "~a",
+ "!a",
+ "{ x : y++ }",
+ "[a++]",
+ "(x => y)",
+ "a[i]", "a()",
+ "a.b",
+ "new a",
+ "a + a",
+ "a - a",
+ "a * a",
+ "a / a",
+ "a == a",
+ "a != a",
+ "a > a",
+ "a < a",
+ "a <<< a",
+ "a >>> a",
+ "function a() {}",
+ "a`bcd`",
+ "x => x",
+ "this",
+ "null",
+ "true",
+ "false",
arv (Not doing code reviews) 2015/04/28 13:42:14 moar // keywords "var", // nested "[var]", "{x
Dmitry Lomov (no reviews) 2015/04/28 16:01:36 Done.
+ "1",
+ "'abc'",
+ "class {}",
+ "() => x",
+ NULL};
+ // clang-format on
+ RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
+ arraysize(always_flags));
+ }
+
+ { // Strict mode.
+ const char* context_data[][2] = {{"'use strict'; let ", " = {};"},
+ {"'use strict'; const ", " = {};"},
+ {NULL, NULL}};
+
+ // clang-format off
+ const char* data[] = {
+ "[eval]",
+ "{ a : arguments }",
+ "[public]",
+ "{ x : private }",
+ NULL};
+ // clang-format on
+ RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
+ arraysize(always_flags));
+ }
+
+ { // 'yield' in generators.
+ const char* context_data[][2] = {
+ {"function*() { var ", " = {};"},
+ {"function*() { 'use strict'; let ", " = {};"},
+ {"function*() { 'use strict'; const ", " = {};"},
+ {NULL, NULL}};
+
+ // clang-format off
+ const char* data[] = {
+ "yield",
+ "[yield]",
+ "{ x : yield }",
+ NULL};
+ // clang-format on
+ RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
+ arraysize(always_flags));
+ }
+}
« no previous file with comments | « src/preparser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698