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

Unified Diff: test/cctest/test-regexp.cc

Issue 2050343002: [regexp] Experimental support for regexp named captures (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 4 years, 6 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 | « src/regexp/regexp-parser.cc ('k') | test/mjsunit/harmony/regexp-named-captures.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/test-regexp.cc
diff --git a/test/cctest/test-regexp.cc b/test/cctest/test-regexp.cc
index 0a153b78e05b145d822ba65656bd42807a369232..f07a333f6374611c81bdf117056fd1b5630950d8 100644
--- a/test/cctest/test-regexp.cc
+++ b/test/cctest/test-regexp.cc
@@ -438,6 +438,23 @@ void TestRegExpParser(bool lookbehind) {
CHECK_MIN_MAX("a(?=b)c", 2, 2);
CHECK_MIN_MAX("a(?=bbb|bb)c", 2, 2);
CHECK_MIN_MAX("a(?!bbb|bb)c", 2, 2);
+
+ FLAG_harmony_regexp_named_captures = true;
+ CheckParseEq("(?<a>x)(?<b>x)(?<c>x)\\k<a>",
+ "(: (^ 'x') (^ 'x') (^ 'x') (<- 1))", true);
+ CheckParseEq("(?<a>x)(?<b>x)(?<c>x)\\k<b>",
+ "(: (^ 'x') (^ 'x') (^ 'x') (<- 2))", true);
+ CheckParseEq("(?<a>x)(?<b>x)(?<c>x)\\k<c>",
+ "(: (^ 'x') (^ 'x') (^ 'x') (<- 3))", true);
+ CheckParseEq("(?<a>a)\\k<a>", "(: (^ 'a') (<- 1))", true);
+ CheckParseEq("(?<a>a\\k<a>)", "(^ 'a')", true);
+ CheckParseEq("(?<a>\\k<a>a)", "(^ 'a')", true);
+ CheckParseEq("(?<a>\\k<b>)(?<b>\\k<a>)", "(: (^ (<- 2)) (^ (<- 1)))", true);
+ CheckParseEq("\\k<a>(?<a>a)", "(: (<- 1) (^ 'a'))", true);
+
+ CheckParseEq("(?<\\u{03C0}>a)", "(^ 'a')", true);
+ CheckParseEq("(?<\\u03C0>a)", "(^ 'a')", true);
+ FLAG_harmony_regexp_named_captures = false;
}
@@ -450,7 +467,6 @@ TEST(ParserWithoutLookbehind) {
TestRegExpParser(true); // Lookbehind enabled.
}
-
TEST(ParserRegression) {
CheckParseEq("[A-Z$-][x]", "(! [A-Z $ -] [x])");
CheckParseEq("a{3,4*}", "(: 'a{3,' (# 0 - g '4') '}')");
@@ -458,14 +474,16 @@ TEST(ParserRegression) {
CheckParseEq("a|", "(| 'a' %)");
}
-static void ExpectError(const char* input,
- const char* expected) {
+static void ExpectError(const char* input, const char* expected,
+ bool unicode = false) {
v8::HandleScope scope(CcTest::isolate());
Zone zone(CcTest::i_isolate()->allocator());
FlatStringReader reader(CcTest::i_isolate(), CStrVector(input));
RegExpCompileData result;
- CHECK(!v8::internal::RegExpParser::ParseRegExp(
- CcTest::i_isolate(), &zone, &reader, JSRegExp::kNone, &result));
+ JSRegExp::Flags flags = JSRegExp::kNone;
+ if (unicode) flags |= JSRegExp::kUnicode;
+ CHECK(!v8::internal::RegExpParser::ParseRegExp(CcTest::i_isolate(), &zone,
+ &reader, flags, &result));
CHECK(result.tree == NULL);
CHECK(!result.error.is_null());
v8::base::SmartArrayPointer<char> str = result.error->ToCString(ALLOW_NULLS);
@@ -499,6 +517,23 @@ TEST(Errors) {
os << "()";
}
ExpectError(os.str().c_str(), kTooManyCaptures);
+
+ FLAG_harmony_regexp_named_captures = true;
+ const char* kInvalidCaptureName = "Invalid capture group name";
+ ExpectError("(?<>.)", kInvalidCaptureName, true);
+ ExpectError("(?<1>.)", kInvalidCaptureName, true);
+ ExpectError("(?<_%>.)", kInvalidCaptureName, true);
+ ExpectError("\\k<a", kInvalidCaptureName, true);
+ const char* kDuplicateCaptureName = "Duplicate capture group name";
+ ExpectError("(?<a>.)(?<a>.)", kDuplicateCaptureName, true);
+ const char* kInvalidUnicodeEscape = "Invalid Unicode escape sequence";
+ ExpectError("(?<\\u{FISK}", kInvalidUnicodeEscape, true);
+ const char* kInvalidCaptureReferenced = "Invalid named capture referenced";
+ ExpectError("\\k<a>", kInvalidCaptureReferenced, true);
+ ExpectError("(?<b>)\\k<a>", kInvalidCaptureReferenced, true);
+ const char* kInvalidNamedReference = "Invalid named reference";
+ ExpectError("\\ka", kInvalidNamedReference, true);
+ FLAG_harmony_regexp_named_captures = false;
}
« no previous file with comments | « src/regexp/regexp-parser.cc ('k') | test/mjsunit/harmony/regexp-named-captures.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698