summaryrefslogtreecommitdiff
path: root/Tests
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2021-09-07 14:33:06 +0430
committerAndreas Kling <kling@serenityos.org>2021-09-07 20:01:58 +0200
commit7fefb8148bc65fe61562f773956d2c41b2646a8a (patch)
tree02473551e5f671a7212a06ecd7ab03870c191a08 /Tests
parent44b8afdbc4518f596980e0b4ca88e7d1aaeeba26 (diff)
downloadserenity-7fefb8148bc65fe61562f773956d2c41b2646a8a.zip
LibRegex: Use the correct capture group index in ERE bytecode generation
Otherwise the left and right capture instructions wouldn't point to the same capture group if there was another nested group there.
Diffstat (limited to 'Tests')
-rw-r--r--Tests/LibRegex/Regex.cpp12
1 files changed, 12 insertions, 0 deletions
diff --git a/Tests/LibRegex/Regex.cpp b/Tests/LibRegex/Regex.cpp
index be2b026fd0..5203a277a0 100644
--- a/Tests/LibRegex/Regex.cpp
+++ b/Tests/LibRegex/Regex.cpp
@@ -485,6 +485,18 @@ TEST_CASE(simple_period_end_benchmark)
EXPECT_EQ(re.search("hello?", m), true);
}
+TEST_CASE(posix_extended_nested_capture_group)
+{
+ Regex<PosixExtended> re("(h(e(?<llo>llo)))"); // group 0 -> "hello", group 1 -> "ello", group 2/"llo" -> "llo"
+ auto result = re.match("hello");
+ EXPECT(result.success);
+ EXPECT_EQ(result.capture_group_matches.size(), 1u);
+ EXPECT_EQ(result.capture_group_matches[0].size(), 3u);
+ EXPECT_EQ(result.capture_group_matches[0][0].view, "hello"sv);
+ EXPECT_EQ(result.capture_group_matches[0][1].view, "ello"sv);
+ EXPECT_EQ(result.capture_group_matches[0][2].view, "llo"sv);
+}
+
TEST_CASE(ECMA262_parse)
{
struct _test {