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

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

Issue 716423002: ES6 unicode extensions, part 1. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: add tests Created 6 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 unified diff | Download patch
« no previous file with comments | « src/scanner.cc ('k') | test/mjsunit/harmony/unicode-escapes.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1339 matching lines...) Expand 10 before | Expand all | Expand 10 after
1350 enum ParserFlag { 1350 enum ParserFlag {
1351 kAllowLazy, 1351 kAllowLazy,
1352 kAllowNatives, 1352 kAllowNatives,
1353 kAllowHarmonyScoping, 1353 kAllowHarmonyScoping,
1354 kAllowHarmonyModules, 1354 kAllowHarmonyModules,
1355 kAllowHarmonyNumericLiterals, 1355 kAllowHarmonyNumericLiterals,
1356 kAllowHarmonyArrowFunctions, 1356 kAllowHarmonyArrowFunctions,
1357 kAllowHarmonyClasses, 1357 kAllowHarmonyClasses,
1358 kAllowHarmonyObjectLiterals, 1358 kAllowHarmonyObjectLiterals,
1359 kAllowHarmonyTemplates, 1359 kAllowHarmonyTemplates,
1360 kAllowHarmonySloppy 1360 kAllowHarmonySloppy,
1361 kAllowHarmonyUnicode
1361 }; 1362 };
1362 1363
1363 1364
1364 enum ParserSyncTestResult { 1365 enum ParserSyncTestResult {
1365 kSuccessOrError, 1366 kSuccessOrError,
1366 kSuccess, 1367 kSuccess,
1367 kError 1368 kError
1368 }; 1369 };
1369 1370
1370 template <typename Traits> 1371 template <typename Traits>
1371 void SetParserFlags(i::ParserBase<Traits>* parser, 1372 void SetParserFlags(i::ParserBase<Traits>* parser,
1372 i::EnumSet<ParserFlag> flags) { 1373 i::EnumSet<ParserFlag> flags) {
1373 parser->set_allow_lazy(flags.Contains(kAllowLazy)); 1374 parser->set_allow_lazy(flags.Contains(kAllowLazy));
1374 parser->set_allow_natives(flags.Contains(kAllowNatives)); 1375 parser->set_allow_natives(flags.Contains(kAllowNatives));
1375 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping)); 1376 parser->set_allow_harmony_scoping(flags.Contains(kAllowHarmonyScoping));
1376 parser->set_allow_harmony_modules(flags.Contains(kAllowHarmonyModules)); 1377 parser->set_allow_harmony_modules(flags.Contains(kAllowHarmonyModules));
1377 parser->set_allow_harmony_numeric_literals( 1378 parser->set_allow_harmony_numeric_literals(
1378 flags.Contains(kAllowHarmonyNumericLiterals)); 1379 flags.Contains(kAllowHarmonyNumericLiterals));
1379 parser->set_allow_harmony_object_literals( 1380 parser->set_allow_harmony_object_literals(
1380 flags.Contains(kAllowHarmonyObjectLiterals)); 1381 flags.Contains(kAllowHarmonyObjectLiterals));
1381 parser->set_allow_harmony_arrow_functions( 1382 parser->set_allow_harmony_arrow_functions(
1382 flags.Contains(kAllowHarmonyArrowFunctions)); 1383 flags.Contains(kAllowHarmonyArrowFunctions));
1383 parser->set_allow_harmony_classes(flags.Contains(kAllowHarmonyClasses)); 1384 parser->set_allow_harmony_classes(flags.Contains(kAllowHarmonyClasses));
1384 parser->set_allow_harmony_templates(flags.Contains(kAllowHarmonyTemplates)); 1385 parser->set_allow_harmony_templates(flags.Contains(kAllowHarmonyTemplates));
1385 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy)); 1386 parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy));
1387 parser->set_allow_harmony_unicode(flags.Contains(kAllowHarmonyUnicode));
1386 } 1388 }
1387 1389
1388 1390
1389 void TestParserSyncWithFlags(i::Handle<i::String> source, 1391 void TestParserSyncWithFlags(i::Handle<i::String> source,
1390 i::EnumSet<ParserFlag> flags, 1392 i::EnumSet<ParserFlag> flags,
1391 ParserSyncTestResult result) { 1393 ParserSyncTestResult result) {
1392 i::Isolate* isolate = CcTest::i_isolate(); 1394 i::Isolate* isolate = CcTest::i_isolate();
1393 i::Factory* factory = isolate->factory(); 1395 i::Factory* factory = isolate->factory();
1394 1396
1395 uintptr_t stack_limit = isolate->stack_guard()->real_climit(); 1397 uintptr_t stack_limit = isolate->stack_guard()->real_climit();
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
1686 1688
1687 static const ParserFlag default_flags[] = { 1689 static const ParserFlag default_flags[] = {
1688 kAllowHarmonyArrowFunctions, 1690 kAllowHarmonyArrowFunctions,
1689 kAllowHarmonyClasses, 1691 kAllowHarmonyClasses,
1690 kAllowHarmonyNumericLiterals, 1692 kAllowHarmonyNumericLiterals,
1691 kAllowHarmonyObjectLiterals, 1693 kAllowHarmonyObjectLiterals,
1692 kAllowHarmonyScoping, 1694 kAllowHarmonyScoping,
1693 kAllowHarmonyModules, 1695 kAllowHarmonyModules,
1694 kAllowHarmonyTemplates, 1696 kAllowHarmonyTemplates,
1695 kAllowHarmonySloppy, 1697 kAllowHarmonySloppy,
1698 kAllowHarmonyUnicode,
1696 kAllowLazy, 1699 kAllowLazy,
1697 kAllowNatives, 1700 kAllowNatives,
1698 }; 1701 };
1699 ParserFlag* generated_flags = NULL; 1702 ParserFlag* generated_flags = NULL;
1700 if (flags == NULL) { 1703 if (flags == NULL) {
1701 flags = default_flags; 1704 flags = default_flags;
1702 flags_len = arraysize(default_flags); 1705 flags_len = arraysize(default_flags);
1703 if (always_true_flags != NULL || always_false_flags != NULL) { 1706 if (always_true_flags != NULL || always_false_flags != NULL) {
1704 // Remove always_true/false_flags from default_flags. 1707 // Remove always_true/false_flags from default_flags.
1705 CHECK((always_true_flags != NULL) == (always_true_len > 0)); 1708 CHECK((always_true_flags != NULL) == (always_true_len > 0));
(...skipping 2661 matching lines...) Expand 10 before | Expand all | Expand 10 after
4367 const char* context_data[][2] = {{"", ""}, 4370 const char* context_data[][2] = {{"", ""},
4368 {"'use strict';", ""}, 4371 {"'use strict';", ""},
4369 {NULL, NULL}}; 4372 {NULL, NULL}};
4370 const char* data[] = { 4373 const char* data[] = {
4371 "var foob\\u123r = 0;", 4374 "var foob\\u123r = 0;",
4372 "var \\u123roo = 0;", 4375 "var \\u123roo = 0;",
4373 "\"foob\\u123rr\"", 4376 "\"foob\\u123rr\"",
4374 // No escapes allowed in regexp flags 4377 // No escapes allowed in regexp flags
4375 "/regex/\\u0069g", 4378 "/regex/\\u0069g",
4376 "/regex/\\u006g", 4379 "/regex/\\u006g",
4380 // Braces gone wrong
4381 "var foob\\u{c481r = 0;",
4382 "var foob\\uc481}r = 0;",
4383 "var \\u{0052oo = 0;",
4384 "var \\u0052}oo = 0;",
4385 "\"foob\\u{c481r\"",
4386 "var foob\\u{}ar = 0;",
4387 // Too high value for the unicode escape
4388 "\"\\u{110000}\"",
4389 // Not an unicode escape
4390 "var foob\\v1234r = 0;",
4391 "var foob\\U1234r = 0;",
4392 "var foob\\v{1234}r = 0;",
4393 "var foob\\U{1234}r = 0;",
4377 NULL}; 4394 NULL};
4378 RunParserSyncTest(context_data, data, kError); 4395 static const ParserFlag always_flags[] = {kAllowHarmonyUnicode};
4396 RunParserSyncTest(context_data, data, kError, NULL, 0, always_flags,
4397 arraysize(always_flags));
4379 } 4398 }
4380 4399
4381 4400
4401 TEST(UnicodeEscapes) {
4402 const char* context_data[][2] = {{"", ""},
4403 {"'use strict';", ""},
4404 {NULL, NULL}};
4405 const char* data[] = {
4406 // Identifier starting with escape
4407 "var \\u0052oo = 0;",
4408 "var \\u{0052}oo = 0;",
4409 "var \\u{52}oo = 0;",
4410 "var \\u{00000000052}oo = 0;",
4411 // Identifier with an escape but not starting with an escape
4412 "var foob\\uc481r = 0;",
4413 "var foob\\u{c481}r = 0;",
4414 // String with an escape
4415 "\"foob\\uc481r\"",
4416 "\"foob\\{uc481}r\"",
4417 // This character is a valid unicode character, representable as a surrogate
4418 // pair, not representable as 4 hex digits.
4419 "\"foo\\u{10e6d}\"",
4420 // Max value for the unicode escape
4421 "\"\\u{10ffff}\"",
4422 NULL};
4423 static const ParserFlag always_flags[] = {kAllowHarmonyUnicode};
4424 RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags,
4425 arraysize(always_flags));
4426 }
4427
4428
4382 TEST(ScanTemplateLiterals) { 4429 TEST(ScanTemplateLiterals) {
4383 const char* context_data[][2] = {{"'use strict';", ""}, 4430 const char* context_data[][2] = {{"'use strict';", ""},
4384 {"function foo(){ 'use strict';" 4431 {"function foo(){ 'use strict';"
4385 " var a, b, c; return ", "}"}, 4432 " var a, b, c; return ", "}"},
4386 {NULL, NULL}}; 4433 {NULL, NULL}};
4387 4434
4388 const char* data[] = { 4435 const char* data[] = {
4389 "``", 4436 "``",
4390 "`no-subst-template`", 4437 "`no-subst-template`",
4391 "`template-head${a}`", 4438 "`template-head${a}`",
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
4514 always_false_flags, arraysize(always_false_flags)); 4561 always_false_flags, arraysize(always_false_flags));
4515 4562
4516 const char* good_data[] = { 4563 const char* good_data[] = {
4517 "let = 1;", 4564 "let = 1;",
4518 "for(let = 1;;){}", 4565 "for(let = 1;;){}",
4519 NULL}; 4566 NULL};
4520 RunParserSyncTest(context_data, good_data, kSuccess, NULL, 0, 4567 RunParserSyncTest(context_data, good_data, kSuccess, NULL, 0,
4521 always_true_flags, arraysize(always_true_flags), 4568 always_true_flags, arraysize(always_true_flags),
4522 always_false_flags, arraysize(always_false_flags)); 4569 always_false_flags, arraysize(always_false_flags));
4523 } 4570 }
OLDNEW
« no previous file with comments | « src/scanner.cc ('k') | test/mjsunit/harmony/unicode-escapes.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698