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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « test/cctest/test-debug.cc ('k') | test/cctest/test-regexp.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-parsing.cc
diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc
index da5d771d7b2b6d75d4fa14d4a6f93e4307bc37a3..151cf50a5c4baa538448e211256455fbc7691167 100755
--- a/test/cctest/test-parsing.cc
+++ b/test/cctest/test-parsing.cc
@@ -645,3 +645,58 @@ TEST(StreamScanner) {
TestStreamScanner(&stream3, expectations3, 1, 1 + i);
}
}
+
+
+void TestScanRegExp(const char* re_source, const char* expected) {
+ i::Utf8ToUC16CharacterStream stream(
+ reinterpret_cast<const i::byte*>(re_source),
+ static_cast<unsigned>(strlen(re_source)));
+ i::V8JavaScriptScanner scanner;
+ scanner.Initialize(&stream);
+
+ i::Token::Value start = scanner.peek();
+ CHECK(start == i::Token::DIV || start == i::Token::ASSIGN_DIV);
+ CHECK(scanner.ScanRegExpPattern(start == i::Token::ASSIGN_DIV));
+ scanner.Next(); // Current token is now the regexp literal.
+ CHECK(scanner.is_literal_ascii());
+ i::Vector<const char> actual = scanner.literal_ascii_string();
+ for (int i = 0; i < actual.length(); i++) {
+ CHECK_NE('\0', expected[i]);
+ CHECK_EQ(expected[i], actual[i]);
+ }
+}
+
+
+TEST(RegExpScanning) {
+ // RegExp token with added garbage at the end. The scanner should only
+ // scan the RegExp until the terminating slash just before "flipperwald".
+ TestScanRegExp("/b/flipperwald", "b");
+ // Incomplete escape sequences doesn't hide the terminating slash.
+ TestScanRegExp("/\\x/flipperwald", "\\x");
+ TestScanRegExp("/\\u/flipperwald", "\\u");
+ TestScanRegExp("/\\u1/flipperwald", "\\u1");
+ TestScanRegExp("/\\u12/flipperwald", "\\u12");
+ TestScanRegExp("/\\u123/flipperwald", "\\u123");
+ TestScanRegExp("/\\c/flipperwald", "\\c");
+ TestScanRegExp("/\\c//flipperwald", "\\c");
+ // Slashes inside character classes are not terminating.
+ TestScanRegExp("/[/]/flipperwald", "[/]");
+ TestScanRegExp("/[\\s-/]/flipperwald", "[\\s-/]");
+ // Incomplete escape sequences inside a character class doesn't hide
+ // the end of the character class.
+ TestScanRegExp("/[\\c/]/flipperwald", "[\\c/]");
+ TestScanRegExp("/[\\c]/flipperwald", "[\\c]");
+ TestScanRegExp("/[\\x]/flipperwald", "[\\x]");
+ TestScanRegExp("/[\\x1]/flipperwald", "[\\x1]");
+ TestScanRegExp("/[\\u]/flipperwald", "[\\u]");
+ TestScanRegExp("/[\\u1]/flipperwald", "[\\u1]");
+ TestScanRegExp("/[\\u12]/flipperwald", "[\\u12]");
+ TestScanRegExp("/[\\u123]/flipperwald", "[\\u123]");
+ // Escaped ']'s wont end the character class.
+ TestScanRegExp("/[\\]/]/flipperwald", "[\\]/]");
+ // Escaped slashes are not terminating.
+ TestScanRegExp("/\\//flipperwald", "\\/");
+ // Starting with '=' works too.
+ TestScanRegExp("/=/", "=");
+ TestScanRegExp("/=?/", "=?");
+}
« 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