From 85d87cbcc848d3db2fd01aef1967b420c51aa39a Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Sat, 31 Jul 2021 18:47:44 +0430 Subject: [PATCH] LibRegex: Add some tests for Fork{Stay,Jump} performance Without the previous fixes, these will blow up the stack. --- Tests/LibRegex/Regex.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Tests/LibRegex/Regex.cpp b/Tests/LibRegex/Regex.cpp index 043d520d9c..89ac69de7e 100644 --- a/Tests/LibRegex/Regex.cpp +++ b/Tests/LibRegex/Regex.cpp @@ -726,3 +726,19 @@ TEST_CASE(case_insensitive_match) EXPECT_EQ(result.matches.at(0).column, 4ul); } } + +TEST_CASE(extremely_long_fork_chain) +{ + Regex re("(?:aa)*"); + auto result = re.match(String::repeated('a', 100'000)); + EXPECT_EQ(result.success, true); +} + +static auto g_lots_of_a_s = String::repeated('a', 10'000'000); + +BENCHMARK_CASE(fork_performance) +{ + Regex re("(?:aa)*"); + auto result = re.match(g_lots_of_a_s); + EXPECT_EQ(result.success, true); +}