diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2021-09-12 17:30:27 +0430 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-09-13 14:38:53 +0430 |
commit | 246ab432ffc579b4ae4374b1a699bd1e689dc506 (patch) | |
tree | 77ec6153d31f03f9ecc7db1b3a446c0ddc497eb6 /Tests | |
parent | 913382734c7bcbeac1366c1197766b398974c031 (diff) | |
download | serenity-246ab432ffc579b4ae4374b1a699bd1e689dc506.zip |
LibRegex: Add a basic optimization pass
This currently tries to convert forking loops to atomic groups, and
unify the left side of alternations.
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/LibRegex/Regex.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/Tests/LibRegex/Regex.cpp b/Tests/LibRegex/Regex.cpp index 5203a277a0..4aeffb8da8 100644 --- a/Tests/LibRegex/Regex.cpp +++ b/Tests/LibRegex/Regex.cpp @@ -8,6 +8,7 @@ #include <LibTest/TestCase.h> // import first, to prevent warning of VERIFY* redefinition #include <AK/StringBuilder.h> +#include <AK/Tuple.h> #include <LibRegex/Regex.h> #include <LibRegex/RegexDebug.h> #include <stdio.h> @@ -887,3 +888,21 @@ BENCHMARK_CASE(fork_performance) auto result = re.match(g_lots_of_a_s); EXPECT_EQ(result.success, true); } + +TEST_CASE(optimizer_atomic_groups) +{ + Array tests { + // Fork -> ForkReplace + Tuple { "a*b"sv, "aaaaa"sv, false }, + Tuple { "a+b"sv, "aaaaa"sv, false }, + // Alternative fuse + Tuple { "(abcfoo|abcbar|abcbaz).*x"sv, "abcbarx"sv, true }, + Tuple { "(a|a)"sv, "a"sv, true }, + }; + + for (auto& test : tests) { + Regex<ECMA262> re(test.get<0>()); + auto result = re.match(test.get<1>()); + EXPECT_EQ(result.success, test.get<2>()); + } +} |