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

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

Issue 6577036: [Isolates] Merge from bleeding_edge to isolates, revisions 6100-6300. (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/isolates/
Patch Set: '' Created 9 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 | Annotate | Revision Log
« no previous file with comments | « test/cctest/test-disasm-ia32.cc ('k') | test/cctest/test-regexp.cc » ('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 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 } 567 }
568 } 568 }
569 569
570 #undef CHECK_EQU 570 #undef CHECK_EQU
571 571
572 void TestStreamScanner(i::UC16CharacterStream* stream, 572 void TestStreamScanner(i::UC16CharacterStream* stream,
573 i::Token::Value* expected_tokens, 573 i::Token::Value* expected_tokens,
574 int skip_pos = 0, // Zero means not skipping. 574 int skip_pos = 0, // Zero means not skipping.
575 int skip_to = 0) { 575 int skip_to = 0) {
576 i::V8JavaScriptScanner scanner(ISOLATE); 576 i::V8JavaScriptScanner scanner(ISOLATE);
577 scanner.Initialize(stream, i::JavaScriptScanner::kAllLiterals); 577 scanner.Initialize(stream);
578 578
579 int i = 0; 579 int i = 0;
580 do { 580 do {
581 i::Token::Value expected = expected_tokens[i]; 581 i::Token::Value expected = expected_tokens[i];
582 i::Token::Value actual = scanner.Next(); 582 i::Token::Value actual = scanner.Next();
583 CHECK_EQ(i::Token::String(expected), i::Token::String(actual)); 583 CHECK_EQ(i::Token::String(expected), i::Token::String(actual));
584 if (scanner.location().end_pos == skip_pos) { 584 if (scanner.location().end_pos == skip_pos) {
585 scanner.SeekForward(skip_to); 585 scanner.SeekForward(skip_to);
586 } 586 }
587 i++; 587 i++;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 // Skip zero-four RBRACEs. 639 // Skip zero-four RBRACEs.
640 for (int i = 0; i <= 4; i++) { 640 for (int i = 0; i <= 4; i++) {
641 expectations3[6 - i] = i::Token::ILLEGAL; 641 expectations3[6 - i] = i::Token::ILLEGAL;
642 expectations3[5 - i] = i::Token::EOS; 642 expectations3[5 - i] = i::Token::EOS;
643 i::Utf8ToUC16CharacterStream stream3( 643 i::Utf8ToUC16CharacterStream stream3(
644 reinterpret_cast<const i::byte*>(str3), 644 reinterpret_cast<const i::byte*>(str3),
645 static_cast<unsigned>(strlen(str3))); 645 static_cast<unsigned>(strlen(str3)));
646 TestStreamScanner(&stream3, expectations3, 1, 1 + i); 646 TestStreamScanner(&stream3, expectations3, 1, 1 + i);
647 } 647 }
648 } 648 }
649
650
651 void TestScanRegExp(const char* re_source, const char* expected) {
652 i::Utf8ToUC16CharacterStream stream(
653 reinterpret_cast<const i::byte*>(re_source),
654 static_cast<unsigned>(strlen(re_source)));
655 i::V8JavaScriptScanner scanner(ISOLATE);
656 scanner.Initialize(&stream);
657
658 i::Token::Value start = scanner.peek();
659 CHECK(start == i::Token::DIV || start == i::Token::ASSIGN_DIV);
660 CHECK(scanner.ScanRegExpPattern(start == i::Token::ASSIGN_DIV));
661 scanner.Next(); // Current token is now the regexp literal.
662 CHECK(scanner.is_literal_ascii());
663 i::Vector<const char> actual = scanner.literal_ascii_string();
664 for (int i = 0; i < actual.length(); i++) {
665 CHECK_NE('\0', expected[i]);
666 CHECK_EQ(expected[i], actual[i]);
667 }
668 }
669
670
671 TEST(RegExpScanning) {
672 // RegExp token with added garbage at the end. The scanner should only
673 // scan the RegExp until the terminating slash just before "flipperwald".
674 TestScanRegExp("/b/flipperwald", "b");
675 // Incomplete escape sequences doesn't hide the terminating slash.
676 TestScanRegExp("/\\x/flipperwald", "\\x");
677 TestScanRegExp("/\\u/flipperwald", "\\u");
678 TestScanRegExp("/\\u1/flipperwald", "\\u1");
679 TestScanRegExp("/\\u12/flipperwald", "\\u12");
680 TestScanRegExp("/\\u123/flipperwald", "\\u123");
681 TestScanRegExp("/\\c/flipperwald", "\\c");
682 TestScanRegExp("/\\c//flipperwald", "\\c");
683 // Slashes inside character classes are not terminating.
684 TestScanRegExp("/[/]/flipperwald", "[/]");
685 TestScanRegExp("/[\\s-/]/flipperwald", "[\\s-/]");
686 // Incomplete escape sequences inside a character class doesn't hide
687 // the end of the character class.
688 TestScanRegExp("/[\\c/]/flipperwald", "[\\c/]");
689 TestScanRegExp("/[\\c]/flipperwald", "[\\c]");
690 TestScanRegExp("/[\\x]/flipperwald", "[\\x]");
691 TestScanRegExp("/[\\x1]/flipperwald", "[\\x1]");
692 TestScanRegExp("/[\\u]/flipperwald", "[\\u]");
693 TestScanRegExp("/[\\u1]/flipperwald", "[\\u1]");
694 TestScanRegExp("/[\\u12]/flipperwald", "[\\u12]");
695 TestScanRegExp("/[\\u123]/flipperwald", "[\\u123]");
696 // Escaped ']'s wont end the character class.
697 TestScanRegExp("/[\\]/]/flipperwald", "[\\]/]");
698 // Escaped slashes are not terminating.
699 TestScanRegExp("/\\//flipperwald", "\\/");
700 // Starting with '=' works too.
701 TestScanRegExp("/=/", "=");
702 TestScanRegExp("/=?/", "=?");
703 }
OLDNEW
« no previous file with comments | « test/cctest/test-disasm-ia32.cc ('k') | test/cctest/test-regexp.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698