Chromium Code Reviews| Index: test/cctest/test-parsing.cc |
| diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc |
| index 3c7822a03209f55c7888e27c05e2cdf1622b8f6c..520981bf548b7e4d833bb81cd70471f6c7a3790f 100644 |
| --- a/test/cctest/test-parsing.cc |
| +++ b/test/cctest/test-parsing.cc |
| @@ -1511,6 +1511,7 @@ enum ParserFlag { |
| kAllowHarmonyForIn, |
| kAllowHarmonyAsyncAwait, |
| kAllowHarmonyRestrictiveGenerators, |
| + kAllowHarmonyTrailingCommasInParameters, |
| }; |
| enum ParserSyncTestResult { |
| @@ -1535,6 +1536,8 @@ void SetParserFlags(i::ParserBase<Traits>* parser, |
| flags.Contains(kAllowHarmonyAsyncAwait)); |
| parser->set_allow_harmony_restrictive_generators( |
| flags.Contains(kAllowHarmonyRestrictiveGenerators)); |
| + parser->set_allow_harmony_trailing_commas_in_parameters( |
| + flags.Contains(kAllowHarmonyTrailingCommasInParameters)); |
| } |
| @@ -7814,3 +7817,76 @@ TEST(NoDuplicateAsyncFunctionInBlock) { |
| RunParserSyncTest(top_level_context_data, error_data, kSuccess, NULL, 0, |
| always_flags, arraysize(always_flags)); |
| } |
| + |
| +TEST(TrailingCommasInParameters) { |
| + // clang-format off |
| + const char* context_data[][2] = { |
| + { "'use strict';", "" }, |
|
jwolfe
2016/06/22 18:04:41
Is this unnecessary? It looked like other tests we
jwolfe
2016/06/23 18:43:00
Never mind. I've changed this in a later patch.
|
| + { "", "" }, |
| + { NULL, NULL } |
| + }; |
| + |
| + const char* data[] = { |
| + " function a(b,) {}", |
| + " function* a(b,) {}", |
| + "(function a(b,) {});", |
| + "(function* a(b,) {});", |
| + "(function (b,) {});", |
| + "(function* (b,) {});", |
| + "(b,) => {};", |
| + "a(1,);", |
| + "a(...[],);", |
| + NULL |
| + }; |
| + // clang-format on |
| + |
| + static const ParserFlag always_flags[] = { |
| + kAllowHarmonyTrailingCommasInParameters}; |
| + RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags, |
| + arraysize(always_flags)); |
| +} |
| + |
| +TEST(TrailingCommasInParametersErrors) { |
|
jwolfe
2016/06/22 18:04:41
should i combine these two tests? (effectively del
|
| + // clang-format off |
| + const char* context_data[][2] = { |
| + { "'use strict';", "" }, |
| + { "", "" }, |
| + { NULL, NULL } |
| + }; |
| + |
| + const char* data[] = { |
| + // too many trailing commas |
| + " function a(b,,) {}", |
| + " function* a(b,,) {}", |
| + "(function a(b,,) {});", |
| + "(function* a(b,,) {});", |
| + "(function (b,,) {});", |
| + "(function* (b,,) {});", |
| + "(b,,) => {};", |
| + "a(1,,);", |
| + // only a trailing comma and no parameters |
| + " function a1(,) {}", |
| + " function* a2(,) {}", |
| + "(function a3(,) {});", |
| + "(function* a4(,) {});", |
| + "(function (,) {});", |
| + "(function* (,) {});", |
| + "(,) => {};", |
| + "a1(,);", |
| + // no trailing commas after rest parameter declaration |
| + " function a(...b,) {}", |
| + " function* a(...b,) {}", |
| + "(function a(...b,) {});", |
| + "(function* a(...b,) {});", |
| + "(function (...b,) {});", |
| + "(function* (...b,) {});", |
| + "(...b,) => {};", |
| + NULL |
| + }; |
| + // clang-format on |
| + |
| + static const ParserFlag always_flags[] = { |
| + kAllowHarmonyTrailingCommasInParameters}; |
| + RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, |
| + arraysize(always_flags)); |
| +} |