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

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

Issue 6113004: Version 3.0.7 (Closed) Base URL: https://v8.googlecode.com/svn/trunk
Patch Set: Created 9 years, 11 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-debug.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 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 // Skip zero-four RBRACEs. 638 // Skip zero-four RBRACEs.
639 for (int i = 0; i <= 4; i++) { 639 for (int i = 0; i <= 4; i++) {
640 expectations3[6 - i] = i::Token::ILLEGAL; 640 expectations3[6 - i] = i::Token::ILLEGAL;
641 expectations3[5 - i] = i::Token::EOS; 641 expectations3[5 - i] = i::Token::EOS;
642 i::Utf8ToUC16CharacterStream stream3( 642 i::Utf8ToUC16CharacterStream stream3(
643 reinterpret_cast<const i::byte*>(str3), 643 reinterpret_cast<const i::byte*>(str3),
644 static_cast<unsigned>(strlen(str3))); 644 static_cast<unsigned>(strlen(str3)));
645 TestStreamScanner(&stream3, expectations3, 1, 1 + i); 645 TestStreamScanner(&stream3, expectations3, 1, 1 + i);
646 } 646 }
647 } 647 }
648
649
650 void TestScanRegExp(const char* re_source, const char* expected) {
651 i::Utf8ToUC16CharacterStream stream(
652 reinterpret_cast<const i::byte*>(re_source),
653 static_cast<unsigned>(strlen(re_source)));
654 i::V8JavaScriptScanner scanner;
655 scanner.Initialize(&stream);
656
657 i::Token::Value start = scanner.peek();
658 CHECK(start == i::Token::DIV || start == i::Token::ASSIGN_DIV);
659 CHECK(scanner.ScanRegExpPattern(start == i::Token::ASSIGN_DIV));
660 scanner.Next(); // Current token is now the regexp literal.
661 CHECK(scanner.is_literal_ascii());
662 i::Vector<const char> actual = scanner.literal_ascii_string();
663 for (int i = 0; i < actual.length(); i++) {
664 CHECK_NE('\0', expected[i]);
665 CHECK_EQ(expected[i], actual[i]);
666 }
667 }
668
669
670 TEST(RegExpScanning) {
671 // RegExp token with added garbage at the end. The scanner should only
672 // scan the RegExp until the terminating slash just before "flipperwald".
673 TestScanRegExp("/b/flipperwald", "b");
674 // Incomplete escape sequences doesn't hide the terminating slash.
675 TestScanRegExp("/\\x/flipperwald", "\\x");
676 TestScanRegExp("/\\u/flipperwald", "\\u");
677 TestScanRegExp("/\\u1/flipperwald", "\\u1");
678 TestScanRegExp("/\\u12/flipperwald", "\\u12");
679 TestScanRegExp("/\\u123/flipperwald", "\\u123");
680 TestScanRegExp("/\\c/flipperwald", "\\c");
681 TestScanRegExp("/\\c//flipperwald", "\\c");
682 // Slashes inside character classes are not terminating.
683 TestScanRegExp("/[/]/flipperwald", "[/]");
684 TestScanRegExp("/[\\s-/]/flipperwald", "[\\s-/]");
685 // Incomplete escape sequences inside a character class doesn't hide
686 // the end of the character class.
687 TestScanRegExp("/[\\c/]/flipperwald", "[\\c/]");
688 TestScanRegExp("/[\\c]/flipperwald", "[\\c]");
689 TestScanRegExp("/[\\x]/flipperwald", "[\\x]");
690 TestScanRegExp("/[\\x1]/flipperwald", "[\\x1]");
691 TestScanRegExp("/[\\u]/flipperwald", "[\\u]");
692 TestScanRegExp("/[\\u1]/flipperwald", "[\\u1]");
693 TestScanRegExp("/[\\u12]/flipperwald", "[\\u12]");
694 TestScanRegExp("/[\\u123]/flipperwald", "[\\u123]");
695 // Escaped ']'s wont end the character class.
696 TestScanRegExp("/[\\]/]/flipperwald", "[\\]/]");
697 // Escaped slashes are not terminating.
698 TestScanRegExp("/\\//flipperwald", "\\/");
699 // Starting with '=' works too.
700 TestScanRegExp("/=/", "=");
701 TestScanRegExp("/=?/", "=?");
702 }
OLDNEW
« no previous file with comments | « test/cctest/test-debug.cc ('k') | test/cctest/test-regexp.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698