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

Side by Side Diff: test/cctest/test-parsing.cc

Issue 938443002: [es6] implement spread calls (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Eagerly iterate spread expressions, make parser more complicated, simplify harmony-spread Created 5 years, 10 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 unified diff | Download patch
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1370 matching lines...) Expand 10 before | Expand all | Expand 10 after
1381 kAllowHarmonyModules, 1381 kAllowHarmonyModules,
1382 kAllowHarmonyNumericLiterals, 1382 kAllowHarmonyNumericLiterals,
1383 kAllowHarmonyArrowFunctions, 1383 kAllowHarmonyArrowFunctions,
1384 kAllowHarmonyClasses, 1384 kAllowHarmonyClasses,
1385 kAllowHarmonyObjectLiterals, 1385 kAllowHarmonyObjectLiterals,
1386 kAllowHarmonyRestParameters, 1386 kAllowHarmonyRestParameters,
1387 kAllowHarmonyTemplates, 1387 kAllowHarmonyTemplates,
1388 kAllowHarmonySloppy, 1388 kAllowHarmonySloppy,
1389 kAllowHarmonyUnicode, 1389 kAllowHarmonyUnicode,
1390 kAllowHarmonyComputedPropertyNames, 1390 kAllowHarmonyComputedPropertyNames,
1391 kAllowStrongMode 1391 kAllowStrongMode,
1392 kAllowHarmonySpreadCalls
1392 }; 1393 };
1393 1394
1394 1395
1395 enum ParserSyncTestResult { 1396 enum ParserSyncTestResult {
1396 kSuccessOrError, 1397 kSuccessOrError,
1397 kSuccess, 1398 kSuccess,
1398 kError 1399 kError
1399 }; 1400 };
1400 1401
1401 template <typename Traits> 1402 template <typename Traits>
(...skipping 3573 matching lines...) Expand 10 before | Expand all | Expand 10 after
4975 4976
4976 static const ParserFlag always_flags[] = {kAllowHarmonyRestParameters}; 4977 static const ParserFlag always_flags[] = {kAllowHarmonyRestParameters};
4977 4978
4978 // In strict mode, the error is using "eval" or "arguments" as parameter names 4979 // In strict mode, the error is using "eval" or "arguments" as parameter names
4979 // In sloppy mode, the error is that eval / arguments are duplicated 4980 // In sloppy mode, the error is that eval / arguments are duplicated
4980 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags, 4981 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
4981 arraysize(always_flags)); 4982 arraysize(always_flags));
4982 } 4983 }
4983 4984
4984 4985
4986 TEST(SpreadCall) {
4987 const char* context_data[][2] = {{"function fn() { 'use strict';} fn(", ");"},
4988 {"function fn() {} fn(", ");"},
4989 {NULL, NULL}};
4990
4991 const char* data[] = {
4992 "...([1, 2, 3])",
4993 "...'123', ...'456'",
rossberg 2015/02/24 16:22:47 Have some more tests with spreads interleaved with
4994 "...new Set([1, 2, 3]), 4",
4995 "1, ...[2, 3], 4",
4996 "...Array(...[1,2,3,4])",
4997 "...NaN",
4998 NULL};
4999
5000 static const ParserFlag always_flags[] = {kAllowHarmonySpreadCalls};
5001
5002 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags,
5003 arraysize(always_flags));
5004 }
5005
5006
5007 TEST(SpreadCallErrors) {
5008 const char* context_data[][2] = {{"function fn() { 'use strict';} fn(", ");"},
5009 {"function fn() {} fn(", ");"},
5010 {NULL, NULL}};
5011
5012 const char* data[] = {
5013 "(...[1, 2, 3])",
5014 "......[1,2,3]",
5015 NULL};
5016
5017 static const ParserFlag always_flags[] = {kAllowHarmonySpreadCalls};
5018
5019 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
5020 arraysize(always_flags));
5021 }
5022
5023
5024 TEST(BadRestSpread) {
5025 const char* context_data[][2] = {{"function fn() { 'use strict';", "} fn();"},
5026 {"function fn() { ", "} fn();" },
5027 {NULL, NULL}};
5028 const char* data[] = {
5029 "return ...[1,2,3];",
5030 "var ...x = [1,2,3];",
5031 "var [...x,] = [1,2,3];",
5032 "var [...x, y] = [1,2,3];",
5033 "var {...x} = [1,2,3];",
5034 "var { x } = {x: ...[1,2,3]}",
5035 NULL};
5036 RunParserSyncTest(context_data, data, kError, NULL, 0, NULL, 0);
5037 }
5038
5039
4985 TEST(LexicalScopingSloppyMode) { 5040 TEST(LexicalScopingSloppyMode) {
4986 const char* context_data[][2] = { 5041 const char* context_data[][2] = {
4987 {"", ""}, 5042 {"", ""},
4988 {"function f() {", "}"}, 5043 {"function f() {", "}"},
4989 {"{", "}"}, 5044 {"{", "}"},
4990 {NULL, NULL}}; 5045 {NULL, NULL}};
4991 const char* bad_data[] = { 5046 const char* bad_data[] = {
4992 "let x = 1;", 5047 "let x = 1;",
4993 "for(let x = 1;;){}", 5048 "for(let x = 1;;){}",
4994 "for(let x of []){}", 5049 "for(let x of []){}",
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
5446 "b, a, a", 5501 "b, a, a",
5447 "a, b, c, c", 5502 "a, b, c, c",
5448 "a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, w", 5503 "a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, w",
5449 NULL}; 5504 NULL};
5450 5505
5451 static const ParserFlag always_flags[] = { kAllowStrongMode }; 5506 static const ParserFlag always_flags[] = { kAllowStrongMode };
5452 RunParserSyncTest(strict_context_data, data, kError, NULL, 0, always_flags, 5507 RunParserSyncTest(strict_context_data, data, kError, NULL, 0, always_flags,
5453 arraysize(always_flags)); 5508 arraysize(always_flags));
5454 RunParserSyncTest(sloppy_context_data, data, kSuccess, NULL, 0, NULL, 0); 5509 RunParserSyncTest(sloppy_context_data, data, kSuccess, NULL, 0, NULL, 0);
5455 } 5510 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698