mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 20:27:45 +00:00
Tests: Move LibRegex tests to Tests/LibRegex
This commit is contained in:
parent
070cba9b0d
commit
6e918e4e02
6 changed files with 1 additions and 2 deletions
|
@ -8,5 +8,3 @@ set(SOURCES
|
|||
|
||||
serenity_lib(LibRegex regex)
|
||||
target_link_libraries(LibRegex LibC LibCore)
|
||||
|
||||
add_subdirectory(Tests)
|
||||
|
|
|
@ -1,969 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Emanuel Sprung <emanuel.sprung@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibTest/TestCase.h> // import first, to prevent warning of VERIFY* redefinition
|
||||
|
||||
#include <LibRegex/Regex.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef REGEX_DEBUG
|
||||
|
||||
# define BENCHMARK_LOOP_ITERATIONS 100000
|
||||
|
||||
//# define REGEX_BENCHMARK_OUR
|
||||
# ifndef __serenity__
|
||||
//# define REGEX_BENCHMARK_OTHER
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OTHER)
|
||||
# include <regex>
|
||||
# endif
|
||||
|
||||
# if not(defined(REGEX_BENCHMARK_OUR) && defined(REGEX_BENCHMARK_OUR))
|
||||
BENCHMARK_CASE(dummy_benchmark)
|
||||
{
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OUR)
|
||||
BENCHMARK_CASE(catch_all_benchmark)
|
||||
{
|
||||
Regex<PosixExtended> re("^.*$");
|
||||
RegexResult m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT(re.match("Hello World", m));
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OTHER)
|
||||
BENCHMARK_CASE(catch_all_benchmark_reference_stdcpp)
|
||||
{
|
||||
std::regex re("^.*$");
|
||||
std::cmatch m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(std::regex_match("Hello World", m, re), true);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OUR)
|
||||
BENCHMARK_CASE(simple_start_benchmark)
|
||||
{
|
||||
Regex<PosixExtended> re("^hello friends");
|
||||
RegexResult m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(re.match("Hello!", m), false);
|
||||
EXPECT_EQ(re.match("hello friends", m), true);
|
||||
EXPECT_EQ(re.match("Well, hello friends", m), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OTHER)
|
||||
BENCHMARK_CASE(simple_start_benchmark_reference_stdcpp)
|
||||
{
|
||||
std::regex re("^hello friends");
|
||||
std::cmatch m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(std::regex_match("Hello", m, re), false);
|
||||
EXPECT_EQ(std::regex_match("hello friends", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("Well, hello friends", m, re), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OUR)
|
||||
BENCHMARK_CASE(simple_end_benchmark)
|
||||
{
|
||||
Regex<PosixExtended> re(".*hello\\.\\.\\. there$");
|
||||
RegexResult m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(re.match("Hallo", m), false);
|
||||
EXPECT_EQ(re.match("I said fyhello... there", m), true);
|
||||
EXPECT_EQ(re.match("ahello... therea", m), false);
|
||||
EXPECT_EQ(re.match("hello.. there", m), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OTHER)
|
||||
BENCHMARK_CASE(simple_end_benchmark_reference_stdcpp)
|
||||
{
|
||||
std::regex re(".*hello\\.\\.\\. there$");
|
||||
std::cmatch m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(std::regex_search("Hallo", m, re), false);
|
||||
EXPECT_EQ(std::regex_search("I said fyhello... there", m, re), true);
|
||||
EXPECT_EQ(std::regex_search("ahello... therea", m, re), false);
|
||||
EXPECT_EQ(std::regex_search("hello.. there", m, re), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OUR)
|
||||
BENCHMARK_CASE(simple_period_benchmark)
|
||||
{
|
||||
Regex<PosixExtended> re("hello.");
|
||||
RegexResult m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(re.match("Hello1", m), false);
|
||||
EXPECT_EQ(re.match("hello1", m), true);
|
||||
EXPECT_EQ(re.match("hello2", m), true);
|
||||
EXPECT_EQ(re.match("hello?", m), true);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OTHER)
|
||||
BENCHMARK_CASE(simple_period_benchmark_reference_stdcpp)
|
||||
{
|
||||
std::regex re("hello.");
|
||||
std::cmatch m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(std::regex_match("Hello1", m, re), false);
|
||||
EXPECT_EQ(std::regex_match("hello1", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("hello2", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("hello?", m, re), true);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OUR)
|
||||
BENCHMARK_CASE(simple_period_end_benchmark)
|
||||
{
|
||||
Regex<PosixExtended> re("hello.$");
|
||||
RegexResult m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(re.search("Hello1", m), false);
|
||||
EXPECT_EQ(re.search("hello1hello1", m), true);
|
||||
EXPECT_EQ(re.search("hello2hell", m), false);
|
||||
EXPECT_EQ(re.search("hello?", m), true);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OTHER)
|
||||
BENCHMARK_CASE(simple_period_end_benchmark_reference_stdcpp)
|
||||
{
|
||||
std::regex re("hello.$");
|
||||
std::cmatch m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(std::regex_search("Hello1", m, re), false);
|
||||
EXPECT_EQ(std::regex_search("hello1hello1", m, re), true);
|
||||
EXPECT_EQ(std::regex_search("hello2hell", m, re), false);
|
||||
EXPECT_EQ(std::regex_search("hello?", m, re), true);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OUR)
|
||||
BENCHMARK_CASE(simple_escaped_benchmark)
|
||||
{
|
||||
Regex<PosixExtended> re("hello\\.");
|
||||
RegexResult m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(re.match("hello", m), false);
|
||||
EXPECT_EQ(re.match("hello.", m), true);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OTHER)
|
||||
BENCHMARK_CASE(simple_escaped_benchmark_reference_stdcpp)
|
||||
{
|
||||
std::regex re("hello\\.");
|
||||
std::cmatch m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(std::regex_match("hello", m, re), false);
|
||||
EXPECT_EQ(std::regex_match("hello.", m, re), true);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OUR)
|
||||
BENCHMARK_CASE(simple_period2_end_benchmark)
|
||||
{
|
||||
Regex<PosixExtended> re(".*hi... there$");
|
||||
RegexResult m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(re.search("Hello there", m), false);
|
||||
EXPECT_EQ(re.search("I said fyhi... there", m), true);
|
||||
EXPECT_EQ(re.search("....hi... ", m), false);
|
||||
EXPECT_EQ(re.search("I said fyhihii there", m), true);
|
||||
EXPECT_EQ(re.search("I said fyhihi there", m), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OTHER)
|
||||
BENCHMARK_CASE(simple_period2_end_benchmark_reference_stdcpp)
|
||||
{
|
||||
std::regex re(".*hi... there$");
|
||||
std::cmatch m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(std::regex_search("Hello there", m, re), false);
|
||||
EXPECT_EQ(std::regex_search("I said fyhi... there", m, re), true);
|
||||
EXPECT_EQ(std::regex_search("....hi... ", m, re), false);
|
||||
EXPECT_EQ(std::regex_search("I said fyhihii there", m, re), true);
|
||||
EXPECT_EQ(std::regex_search("I said fyhihi there", m, re), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OUR)
|
||||
BENCHMARK_CASE(simple_plus_benchmark)
|
||||
{
|
||||
Regex<PosixExtended> re("a+");
|
||||
RegexResult m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(re.search("b", m), false);
|
||||
EXPECT_EQ(re.search("a", m), true);
|
||||
EXPECT_EQ(re.search("aaaaaabbbbb", m), true);
|
||||
EXPECT_EQ(re.search("aaaaaaaaaaa", m), true);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OTHER)
|
||||
BENCHMARK_CASE(simple_plus_benchmark_reference_stdcpp)
|
||||
{
|
||||
std::regex re("a+");
|
||||
std::cmatch m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(std::regex_search("b", m, re), false);
|
||||
EXPECT_EQ(std::regex_search("a", m, re), true);
|
||||
EXPECT_EQ(std::regex_search("aaaaaabbbbb", m, re), true);
|
||||
EXPECT_EQ(std::regex_search("aaaaaaaaaaa", m, re), true);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OUR)
|
||||
BENCHMARK_CASE(simple_questionmark_benchmark)
|
||||
{
|
||||
Regex<PosixExtended> re("da?d");
|
||||
RegexResult m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(re.search("a", m), false);
|
||||
EXPECT_EQ(re.search("daa", m), false);
|
||||
EXPECT_EQ(re.search("ddddd", m), true);
|
||||
EXPECT_EQ(re.search("dd", m), true);
|
||||
EXPECT_EQ(re.search("dad", m), true);
|
||||
EXPECT_EQ(re.search("dada", m), true);
|
||||
EXPECT_EQ(re.search("adadaa", m), true);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OTHER)
|
||||
BENCHMARK_CASE(simple_questionmark_benchmark_reference_stdcpp)
|
||||
{
|
||||
std::regex re("da?d");
|
||||
std::cmatch m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(std::regex_search("a", m, re), false);
|
||||
EXPECT_EQ(std::regex_search("daa", m, re), false);
|
||||
EXPECT_EQ(std::regex_search("ddddd", m, re), true);
|
||||
EXPECT_EQ(std::regex_search("dd", m, re), true);
|
||||
EXPECT_EQ(std::regex_search("dad", m, re), true);
|
||||
EXPECT_EQ(std::regex_search("dada", m, re), true);
|
||||
EXPECT_EQ(std::regex_search("adadaa", m, re), true);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OUR)
|
||||
BENCHMARK_CASE(character_class_benchmark)
|
||||
{
|
||||
Regex<PosixExtended> re("[[:alpha:]]");
|
||||
RegexResult m;
|
||||
String haystack = "[Window]\nOpacity=255\nAudibleBeep=0\n";
|
||||
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(re.match(haystack.characters(), m), false);
|
||||
EXPECT_EQ(re.search(haystack.characters(), m), true);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OTHER)
|
||||
BENCHMARK_CASE(character_class_benchmark_reference_stdcpp)
|
||||
{
|
||||
std::regex re("[[:alpha:]]");
|
||||
std::cmatch m;
|
||||
String haystack = "[Window]\nOpacity=255\nAudibleBeep=0\n";
|
||||
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(std::regex_match(haystack.characters(), m, re), false);
|
||||
EXPECT_EQ(std::regex_search(haystack.characters(), m, re), true);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OUR)
|
||||
BENCHMARK_CASE(escaped_char_questionmark_benchmark)
|
||||
{
|
||||
Regex<PosixExtended> re("This\\.?And\\.?That");
|
||||
RegexResult m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(re.match("ThisAndThat", m), true);
|
||||
EXPECT_EQ(re.match("This.And.That", m), true);
|
||||
EXPECT_EQ(re.match("This And That", m), false);
|
||||
EXPECT_EQ(re.match("This..And..That", m), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OTHER)
|
||||
BENCHMARK_CASE(escaped_char_questionmark_benchmark_reference_stdcpp)
|
||||
{
|
||||
std::regex re("This\\.?And\\.?That");
|
||||
std::cmatch m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(std::regex_match("ThisAndThat", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("This.And.That", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("This And That", m, re), false);
|
||||
EXPECT_EQ(std::regex_match("This..And..That", m, re), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OUR)
|
||||
BENCHMARK_CASE(char_qualifier_asterisk_benchmark)
|
||||
{
|
||||
Regex<PosixExtended> re("regex*");
|
||||
RegexResult m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(re.search("#include <regex.h>", m), true);
|
||||
EXPECT_EQ(re.search("#include <stdio.h>", m), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OTHER)
|
||||
BENCHMARK_CASE(char_qualifier_asterisk_benchmark_reference_stdcpp)
|
||||
{
|
||||
std::regex re("regex*");
|
||||
std::cmatch m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(std::regex_search("#include <regex.h>", m, re), true);
|
||||
EXPECT_EQ(std::regex_search("#include <stdio.h>", m, re), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OUR)
|
||||
BENCHMARK_CASE(parens_qualifier_questionmark_benchmark)
|
||||
{
|
||||
Regex<PosixExtended> re("test(hello)?test");
|
||||
RegexResult m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(re.match("testtest", m), true);
|
||||
EXPECT_EQ(re.match("testhellotest", m), true);
|
||||
EXPECT_EQ(re.match("testasfdtest", m), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OTHER)
|
||||
BENCHMARK_CASE(parens_qualifier_questionmark_benchmark_reference_stdcpp)
|
||||
{
|
||||
std::regex re("test(hello)?test");
|
||||
std::cmatch m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(std::regex_match("testtest", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("testhellotest", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("testasfdtest", m, re), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OUR)
|
||||
BENCHMARK_CASE(parens_qualifier_asterisk_benchmark)
|
||||
{
|
||||
Regex<PosixExtended> re("test(hello)*test");
|
||||
RegexResult m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(re.match("testtest", m), true);
|
||||
EXPECT_EQ(re.match("testhellohellotest", m), true);
|
||||
EXPECT_EQ(re.search("testhellohellotest, testhellotest", m), true);
|
||||
EXPECT_EQ(re.match("aaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbb", m), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OTHER)
|
||||
BENCHMARK_CASE(parens_qualifier_asterisk_benchmark_reference_stdcpp)
|
||||
{
|
||||
std::regex re("test(hello)*test");
|
||||
std::cmatch m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(std::regex_match("testtest", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("testhellohellotest", m, re), true);
|
||||
EXPECT_EQ(std::regex_search("testhellohellotest, testhellotest", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("aaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbb", m, re), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OUR)
|
||||
BENCHMARK_CASE(parens_qualifier_asterisk_2_benchmark)
|
||||
{
|
||||
Regex<PosixExtended> re("test(.*)test");
|
||||
RegexResult m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(re.match("testasdftest", m), true);
|
||||
EXPECT_EQ(re.match("testasdfasdftest", m), true);
|
||||
EXPECT_EQ(re.search("testaaaatest, testbbbtest, testtest", m), true);
|
||||
EXPECT_EQ(re.match("aaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbb", m), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OTHER)
|
||||
BENCHMARK_CASE(parens_qualifier_asterisk_2_benchmark_reference_stdcpp)
|
||||
{
|
||||
std::regex re("test(.*)test");
|
||||
std::cmatch m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(std::regex_match("testasdftest", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("testasdfasdftest", m, re), true);
|
||||
EXPECT_EQ(std::regex_search("testaaaatest, testbbbtest, testtest", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("aaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbb", m, re), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OUR)
|
||||
BENCHMARK_CASE(multi_parens_qualifier_questionmark_benchmark)
|
||||
{
|
||||
Regex<PosixExtended> re("test(a)?(b)?(c)?test");
|
||||
RegexResult m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(re.match("testtest", m), true);
|
||||
EXPECT_EQ(re.match("testabctest", m), true);
|
||||
EXPECT_EQ(re.search("testabctest, testactest", m), true);
|
||||
EXPECT_EQ(re.match("aaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbb", m), false);
|
||||
EXPECT_EQ(re.match("test", m), false);
|
||||
EXPECT_EQ(re.match("whaaaaat", m), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OTHER)
|
||||
BENCHMARK_CASE(multi_parens_qualifier_questionmark_benchmark_reference_stdcpp)
|
||||
{
|
||||
std::regex re("test(a)?(b)?(c)?test");
|
||||
std::cmatch m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(std::regex_match("testtest", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("testabctest", m, re), true);
|
||||
EXPECT_EQ(std::regex_search("testabctest, testactest", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("aaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbb", m, re), false);
|
||||
EXPECT_EQ(std::regex_match("test", m, re), false);
|
||||
EXPECT_EQ(std::regex_match("whaaaaat", m, re), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OUR)
|
||||
BENCHMARK_CASE(simple_alternative_benchmark)
|
||||
{
|
||||
Regex<PosixExtended> re("test|hello|friends");
|
||||
RegexResult m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(re.match("test", m), true);
|
||||
EXPECT_EQ(re.match("hello", m), true);
|
||||
EXPECT_EQ(re.match("friends", m), true);
|
||||
EXPECT_EQ(re.match("whaaaaat", m), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OTHER)
|
||||
BENCHMARK_CASE(simple_alternative_benchmark_reference_stdcpp)
|
||||
{
|
||||
std::regex re("test|hello|friends");
|
||||
std::cmatch m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(std::regex_match("test", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("hello", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("friends", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("whaaaaat", m, re), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OUR)
|
||||
BENCHMARK_CASE(alternative_match_groups_benchmark)
|
||||
{
|
||||
Regex<PosixExtended> re("test(a)?(b)?|hello ?(dear|my)? friends");
|
||||
RegexResult m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(re.match("test", m), true);
|
||||
EXPECT_EQ(re.match("testa", m), true);
|
||||
EXPECT_EQ(re.match("testb", m), true);
|
||||
EXPECT_EQ(re.match("hello friends", m), true);
|
||||
EXPECT_EQ(re.match("hello dear friends", m), true);
|
||||
EXPECT_EQ(re.match("hello my friends", m), true);
|
||||
EXPECT_EQ(re.match("testabc", m), false);
|
||||
EXPECT_EQ(re.match("hello test friends", m), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OTHER)
|
||||
BENCHMARK_CASE(alternative_match_groups_benchmark_reference_stdcpp)
|
||||
{
|
||||
std::regex re("test(a)?(b)?|hello ?(dear|my)? friends");
|
||||
std::cmatch m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(std::regex_match("test", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("testa", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("testb", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("hello friends", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("hello dear friends", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("hello my friends", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("testabc", m, re), false);
|
||||
EXPECT_EQ(std::regex_match("hello test friends", m, re), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OUR)
|
||||
BENCHMARK_CASE(parens_qualifier_exact_benchmark)
|
||||
{
|
||||
Regex<PosixExtended> re("(hello){3}");
|
||||
RegexResult m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(re.match("hello", m), false);
|
||||
EXPECT_EQ(re.match("hellohellohello", m), true);
|
||||
EXPECT_EQ(re.search("hellohellohellohello", m), true);
|
||||
EXPECT_EQ(re.search("test hellohellohello", m), true);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OTHER)
|
||||
BENCHMARK_CASE(parens_qualifier_exact_benchmark_reference_stdcpp)
|
||||
{
|
||||
std::regex re("(hello){3}");
|
||||
std::cmatch m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(std::regex_match("hello", m, re), false);
|
||||
EXPECT_EQ(std::regex_match("hellohellohello", m, re), true);
|
||||
EXPECT_EQ(std::regex_search("hellohellohellohello", m, re), true);
|
||||
EXPECT_EQ(std::regex_search("test hellohellohello", m, re), true);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OUR)
|
||||
BENCHMARK_CASE(parens_qualifier_minimum_benchmark)
|
||||
{
|
||||
Regex<PosixExtended> re("(hello){3,}");
|
||||
RegexResult m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(re.match("hello", m), false);
|
||||
EXPECT_EQ(re.match("hellohellohello", m), true);
|
||||
EXPECT_EQ(re.search("hellohellohellohello", m), true);
|
||||
EXPECT_EQ(re.search("test hellohellohello", m), true);
|
||||
EXPECT_EQ(re.search("test hellohellohellohello", m), true);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OTHER)
|
||||
BENCHMARK_CASE(parens_qualifier_minimum_benchmark_reference_stdcpp)
|
||||
{
|
||||
std::regex re("(hello){3,}");
|
||||
std::cmatch m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(std::regex_match("hello", m, re), false);
|
||||
EXPECT_EQ(std::regex_match("hellohellohello", m, re), true);
|
||||
EXPECT_EQ(std::regex_search("hellohellohellohello", m, re), true);
|
||||
EXPECT_EQ(std::regex_search("test hellohellohello", m, re), true);
|
||||
EXPECT_EQ(std::regex_search("test hellohellohellohello", m, re), true);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OUR)
|
||||
BENCHMARK_CASE(parens_qualifier_maximum_benchmark)
|
||||
{
|
||||
Regex<PosixExtended> re("(hello){2,3}");
|
||||
RegexResult m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(re.match("hello", m), false);
|
||||
EXPECT_EQ(re.match("hellohellohello", m), true);
|
||||
EXPECT_EQ(re.search("hellohellohellohello", m), true);
|
||||
EXPECT_EQ(re.search("test hellohellohello", m), true);
|
||||
EXPECT_EQ(re.search("test hellohellohellohello", m), true);
|
||||
EXPECT_EQ(re.match("test hellohellohellohello", m), false);
|
||||
EXPECT_EQ(re.search("test hellohellohellohello", m), true);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OTHER)
|
||||
BENCHMARK_CASE(parens_qualifier_maximum_benchmark_reference_stdcpp)
|
||||
{
|
||||
std::regex re("(hello){2,3}");
|
||||
std::cmatch m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(std::regex_match("hello", m, re), false);
|
||||
EXPECT_EQ(std::regex_match("hellohellohello", m, re), true);
|
||||
EXPECT_EQ(std::regex_search("hellohellohellohello", m, re), true);
|
||||
EXPECT_EQ(std::regex_search("test hellohellohello", m, re), true);
|
||||
EXPECT_EQ(std::regex_search("test hellohellohellohello", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("test hellohellohellohello", m, re), false);
|
||||
EXPECT_EQ(std::regex_search("test hellohellohellohello", m, re), true);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OUR)
|
||||
BENCHMARK_CASE(char_qualifier_min_max_benchmark)
|
||||
{
|
||||
Regex<PosixExtended> re("c{3,30}");
|
||||
RegexResult m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(re.match("cc", m), false);
|
||||
EXPECT_EQ(re.match("ccc", m), true);
|
||||
EXPECT_EQ(re.match("cccccccccccccccccccccccccccccc", m), true);
|
||||
EXPECT_EQ(re.match("ccccccccccccccccccccccccccccccc", m), false);
|
||||
EXPECT_EQ(re.search("ccccccccccccccccccccccccccccccc", m), true);
|
||||
EXPECT_EQ(re.match("cccccccccccccccccccccccccccccccc", m), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OTHER)
|
||||
BENCHMARK_CASE(char_qualifier_min_max_benchmark_reference_stdcpp)
|
||||
{
|
||||
std::regex re("c{3,30}");
|
||||
std::cmatch m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(std::regex_match("cc", m, re), false);
|
||||
EXPECT_EQ(std::regex_match("ccc", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("cccccccccccccccccccccccccccccc", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("ccccccccccccccccccccccccccccccc", m, re), false);
|
||||
EXPECT_EQ(std::regex_search("ccccccccccccccccccccccccccccccc", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("cccccccccccccccccccccccccccccccc", m, re), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OUR)
|
||||
BENCHMARK_CASE(simple_bracket_chars_benchmark)
|
||||
{
|
||||
Regex<PosixExtended> re("[abc]");
|
||||
RegexResult m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(re.match("a", m), true);
|
||||
EXPECT_EQ(re.match("b", m), true);
|
||||
EXPECT_EQ(re.match("c", m), true);
|
||||
EXPECT_EQ(re.match("d", m), false);
|
||||
EXPECT_EQ(re.match("e", m), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OTHER)
|
||||
BENCHMARK_CASE(simple_bracket_chars_benchmark_reference_stdcpp)
|
||||
{
|
||||
std::regex re("[abc]");
|
||||
std::cmatch m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(std::regex_match("a", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("b", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("c", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("d", m, re), false);
|
||||
EXPECT_EQ(std::regex_match("e", m, re), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OUR)
|
||||
BENCHMARK_CASE(simple_bracket_chars_inverse_benchmark)
|
||||
{
|
||||
Regex<PosixExtended> re("[^abc]");
|
||||
RegexResult m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(re.match("a", m), false);
|
||||
EXPECT_EQ(re.match("b", m), false);
|
||||
EXPECT_EQ(re.match("c", m), false);
|
||||
EXPECT_EQ(re.match("d", m), true);
|
||||
EXPECT_EQ(re.match("e", m), true);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OTHER)
|
||||
BENCHMARK_CASE(simple_bracket_chars_inverse_benchmark_reference_stdcpp)
|
||||
{
|
||||
std::regex re("[^abc]");
|
||||
std::cmatch m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(std::regex_match("a", m, re), false);
|
||||
EXPECT_EQ(std::regex_match("b", m, re), false);
|
||||
EXPECT_EQ(std::regex_match("c", m, re), false);
|
||||
EXPECT_EQ(std::regex_match("d", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("e", m, re), true);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OUR)
|
||||
BENCHMARK_CASE(simple_bracket_chars_range_benchmark)
|
||||
{
|
||||
Regex<PosixExtended> re("[a-d]");
|
||||
RegexResult m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(re.match("a", m), true);
|
||||
EXPECT_EQ(re.match("b", m), true);
|
||||
EXPECT_EQ(re.match("c", m), true);
|
||||
EXPECT_EQ(re.match("d", m), true);
|
||||
EXPECT_EQ(re.match("e", m), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OTHER)
|
||||
BENCHMARK_CASE(simple_bracket_chars_range_benchmark_reference_stdcpp)
|
||||
{
|
||||
std::regex re("[a-d]");
|
||||
std::cmatch m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(std::regex_match("a", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("b", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("c", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("d", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("e", m, re), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OUR)
|
||||
BENCHMARK_CASE(simple_bracket_chars_range_inverse_benchmark)
|
||||
{
|
||||
Regex<PosixExtended> re("[^a-df-z]");
|
||||
RegexResult m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(re.match("a", m), false);
|
||||
EXPECT_EQ(re.match("b", m), false);
|
||||
EXPECT_EQ(re.match("c", m), false);
|
||||
EXPECT_EQ(re.match("d", m), false);
|
||||
EXPECT_EQ(re.match("e", m), true);
|
||||
EXPECT_EQ(re.match("k", m), false);
|
||||
EXPECT_EQ(re.match("z", m), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OTHER)
|
||||
BENCHMARK_CASE(simple_bracket_chars_range_inverse_benchmark_reference_stdcpp)
|
||||
{
|
||||
std::regex re("[^a-df-z]");
|
||||
std::cmatch m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(std::regex_match("a", m, re), false);
|
||||
EXPECT_EQ(std::regex_match("b", m, re), false);
|
||||
EXPECT_EQ(std::regex_match("c", m, re), false);
|
||||
EXPECT_EQ(std::regex_match("d", m, re), false);
|
||||
EXPECT_EQ(std::regex_match("e", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("k", m, re), false);
|
||||
EXPECT_EQ(std::regex_match("z", m, re), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OUR)
|
||||
BENCHMARK_CASE(bracket_character_class_uuid_benchmark)
|
||||
{
|
||||
Regex<PosixExtended> re("^([[:xdigit:]]{8})-([[:xdigit:]]{4})-([[:xdigit:]]{4})-([[:xdigit:]]{4})-([[:xdigit:]]{12})$");
|
||||
RegexResult m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(re.match("fb9b62a2-1579-4e3a-afba-76239ccb6583", m), true);
|
||||
EXPECT_EQ(re.match("fb9b62a2", m), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OTHER)
|
||||
BENCHMARK_CASE(bracket_character_class_uuid_benchmark_reference_stdcpp)
|
||||
{
|
||||
std::regex re("^([[:xdigit:]]{8})-([[:xdigit:]]{4})-([[:xdigit:]]{4})-([[:xdigit:]]{4})-([[:xdigit:]]{12})$");
|
||||
std::cmatch m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(std::regex_match("fb9b62a2-1579-4e3a-afba-76239ccb6583", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("fb9b62a2", m, re), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OUR)
|
||||
BENCHMARK_CASE(simple_bracket_character_class_inverse_benchmark)
|
||||
{
|
||||
Regex<PosixExtended> re("[^[:digit:]]");
|
||||
RegexResult m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(re.match("1", m), false);
|
||||
EXPECT_EQ(re.match("2", m), false);
|
||||
EXPECT_EQ(re.match("3", m), false);
|
||||
EXPECT_EQ(re.match("d", m), true);
|
||||
EXPECT_EQ(re.match("e", m), true);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OTHER)
|
||||
BENCHMARK_CASE(simple_bracket_character_class_inverse_benchmark_reference_stdcpp)
|
||||
{
|
||||
std::regex re("[^[:digit:]]");
|
||||
std::cmatch m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(std::regex_match("1", m, re), false);
|
||||
EXPECT_EQ(std::regex_match("2", m, re), false);
|
||||
EXPECT_EQ(std::regex_match("3", m, re), false);
|
||||
EXPECT_EQ(std::regex_match("d", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("e", m, re), true);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OUR)
|
||||
BENCHMARK_CASE(email_address_benchmark)
|
||||
{
|
||||
Regex<PosixExtended> re("^[A-Z0-9a-z._%+-]{1,64}@(?:[A-Za-z0-9-]{1,63}\\.){1,125}[A-Za-z]{2,63}$");
|
||||
RegexResult m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(re.match("hello.world@domain.tld", m), true);
|
||||
EXPECT_EQ(re.match("this.is.a.very_long_email_address@world.wide.web", m), true);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OTHER)
|
||||
BENCHMARK_CASE(email_address_benchmark_reference_stdcpp)
|
||||
{
|
||||
std::regex re("^[A-Z0-9a-z._%+-]{1,64}@(?:[A-Za-z0-9-]{1,63}\\.){1,125}[A-Za-z]{2,63}$");
|
||||
std::cmatch m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(std::regex_match("hello.world@domain.tld", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("this.is.a.very_long_email_address@world.wide.web", m, re), true);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OUR)
|
||||
BENCHMARK_CASE(simple_ignorecase_benchmark)
|
||||
{
|
||||
Regex<PosixExtended> re("^hello friends", PosixFlags::Insensitive);
|
||||
RegexResult m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(re.match("Hello Friends", m), true);
|
||||
EXPECT_EQ(re.match("hello Friends", m), true);
|
||||
|
||||
EXPECT_EQ(re.match("hello Friends!", m), false);
|
||||
EXPECT_EQ(re.search("hello Friends", m), true);
|
||||
|
||||
EXPECT_EQ(re.match("hell Friends", m), false);
|
||||
EXPECT_EQ(re.search("hell Friends", m), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OTHER)
|
||||
BENCHMARK_CASE(simple_ignorecase_benchmark_reference_stdcpp)
|
||||
{
|
||||
std::regex re("^hello friends", std::regex_constants::icase);
|
||||
std::cmatch m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(std::regex_match("Hello Friends", m, re), true);
|
||||
EXPECT_EQ(std::regex_match("hello Friends", m, re), true);
|
||||
|
||||
EXPECT_EQ(std::regex_match("hello Friends!", m, re), false);
|
||||
EXPECT_EQ(std::regex_search("hello Friends", m, re), true);
|
||||
|
||||
EXPECT_EQ(std::regex_match("hell Friends", m, re), false);
|
||||
EXPECT_EQ(std::regex_search("hell Friends", m, re), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OUR)
|
||||
BENCHMARK_CASE(simple_notbol_noteol_benchmark)
|
||||
{
|
||||
String pattern = "^hello friends$";
|
||||
String pattern2 = "hello friends";
|
||||
regex_t regex, regex2;
|
||||
|
||||
EXPECT_EQ(regcomp(®ex, pattern.characters(), REG_EXTENDED | REG_NOSUB | REG_ICASE), REG_NOERR);
|
||||
EXPECT_EQ(regcomp(®ex2, pattern2.characters(), REG_EXTENDED | REG_NOSUB | REG_ICASE), REG_NOERR);
|
||||
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
|
||||
EXPECT_EQ(regexec(®ex, "hello friends", 0, NULL, REG_NOTBOL), REG_NOMATCH);
|
||||
EXPECT_EQ(regexec(®ex, "hello friends", 0, NULL, REG_NOTEOL), REG_NOMATCH);
|
||||
EXPECT_EQ(regexec(®ex, "hello friends", 0, NULL, REG_NOTBOL | REG_NOTEOL), REG_NOMATCH);
|
||||
|
||||
EXPECT_EQ(regexec(®ex, "a hello friends b", 0, NULL, REG_NOTBOL), REG_NOMATCH);
|
||||
EXPECT_EQ(regexec(®ex, "a hello friends", 0, NULL, REG_NOTBOL), REG_NOMATCH);
|
||||
EXPECT_EQ(regexec(®ex, "a hello friends", 0, NULL, REG_NOTBOL | REG_SEARCH), REG_NOERR);
|
||||
EXPECT_EQ(regexec(®ex, "a hello friends b", 0, NULL, REG_NOTBOL | REG_SEARCH), REG_NOERR);
|
||||
|
||||
EXPECT_EQ(regexec(®ex, "a hello friends b", 0, NULL, REG_NOTEOL), REG_NOMATCH);
|
||||
EXPECT_EQ(regexec(®ex, "hello friends b", 0, NULL, REG_NOTEOL), REG_NOMATCH);
|
||||
EXPECT_EQ(regexec(®ex, "hello friends b", 0, NULL, REG_NOTEOL | REG_SEARCH), REG_NOERR);
|
||||
EXPECT_EQ(regexec(®ex, "a hello friends b", 0, NULL, REG_NOTEOL | REG_SEARCH), REG_NOMATCH);
|
||||
|
||||
EXPECT_EQ(regexec(®ex, "a hello friends b", 0, NULL, REG_NOTBOL | REG_NOTEOL), REG_NOMATCH);
|
||||
EXPECT_EQ(regexec(®ex, "a hello friends b", 0, NULL, REG_NOTBOL | REG_NOTEOL | REG_SEARCH), REG_NOMATCH);
|
||||
|
||||
EXPECT_EQ(regexec(®ex2, "hello friends", 0, NULL, REG_NOTBOL), REG_NOMATCH);
|
||||
EXPECT_EQ(regexec(®ex2, "hello friends", 0, NULL, REG_NOTEOL), REG_NOMATCH);
|
||||
}
|
||||
|
||||
regfree(®ex);
|
||||
}
|
||||
# endif
|
||||
|
||||
# if defined(REGEX_BENCHMARK_OTHER)
|
||||
BENCHMARK_CASE(simple_notbol_noteol_benchmark_reference_stdcpp)
|
||||
{
|
||||
std::regex re1("^hello friends$", std::regex_constants::match_not_bol);
|
||||
std::regex re2("^hello friends$", std::regex_constants::match_not_eol);
|
||||
std::regex re3("^hello friends$", std::regex_constants::match_not_bol | std::regex_constants::match_not_eol);
|
||||
std::regex re4("hello friends", std::regex_constants::match_not_bol);
|
||||
std::regex re5("hello friends", std::regex_constants::match_not_eol);
|
||||
std::cmatch m;
|
||||
for (size_t i = 0; i < BENCHMARK_LOOP_ITERATIONS; ++i) {
|
||||
EXPECT_EQ(std::regex_match("hello friends", m, re1), false);
|
||||
EXPECT_EQ(std::regex_match("hello friends", m, re2), false);
|
||||
EXPECT_EQ(std::regex_match("hello friends", m, re3), false);
|
||||
|
||||
EXPECT_EQ(std::regex_match("a hello friends b", m, re1), false);
|
||||
EXPECT_EQ(std::regex_match("a hello friends", m, re1), false);
|
||||
EXPECT_EQ(std::regex_search("a hello friends", m, re1), true);
|
||||
EXPECT_EQ(std::regex_search("a hello friends b", m, re1), true);
|
||||
|
||||
EXPECT_EQ(std::regex_match("a hello friends b", m, re2), false);
|
||||
EXPECT_EQ(std::regex_match("hello friends b", m, re2), false);
|
||||
EXPECT_EQ(std::regex_search("hello friends b", m, re2), true);
|
||||
EXPECT_EQ(std::regex_search("a hello friends b", m, re2), false);
|
||||
|
||||
EXPECT_EQ(std::regex_match("a hello friends b", m, re3), false);
|
||||
EXPECT_EQ(std::regex_search("a hello friends b", m, re3), false);
|
||||
|
||||
EXPECT_EQ(std::regex_match("hello friends", m, re4), false);
|
||||
EXPECT_EQ(std::regex_match("hello friends", m, re5), false);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
#endif
|
|
@ -1,5 +0,0 @@
|
|||
file(GLOB TEST_SOURCES CONFIGURE_DEPENDS "*.cpp")
|
||||
|
||||
foreach(source ${TEST_SOURCES})
|
||||
serenity_test(${source} LibRegex LIBS LibRegex)
|
||||
endforeach()
|
|
@ -1,597 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020, Emanuel Sprung <emanuel.sprung@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibTest/TestCase.h> // import first, to prevent warning of VERIFY* redefinition
|
||||
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibRegex/Regex.h>
|
||||
#include <LibRegex/RegexDebug.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static ECMAScriptOptions match_test_api_options(const ECMAScriptOptions options)
|
||||
{
|
||||
return options;
|
||||
}
|
||||
|
||||
static PosixOptions match_test_api_options(const PosixOptions options)
|
||||
{
|
||||
return options;
|
||||
}
|
||||
|
||||
TEST_CASE(regex_options_ecmascript)
|
||||
{
|
||||
ECMAScriptOptions eo;
|
||||
eo |= ECMAScriptFlags::Global;
|
||||
|
||||
EXPECT(eo & ECMAScriptFlags::Global);
|
||||
EXPECT(!(eo & ECMAScriptFlags::Insensitive));
|
||||
|
||||
eo = match_test_api_options(ECMAScriptFlags::Global | ECMAScriptFlags::Insensitive | ECMAScriptFlags::Sticky);
|
||||
EXPECT(eo & ECMAScriptFlags::Global);
|
||||
EXPECT(eo & ECMAScriptFlags::Insensitive);
|
||||
EXPECT(eo & ECMAScriptFlags::Sticky);
|
||||
EXPECT(!(eo & ECMAScriptFlags::Unicode));
|
||||
EXPECT(!(eo & ECMAScriptFlags::Multiline));
|
||||
EXPECT(!(eo & ECMAScriptFlags::SingleLine));
|
||||
|
||||
eo &= ECMAScriptFlags::Insensitive;
|
||||
EXPECT(!(eo & ECMAScriptFlags::Global));
|
||||
EXPECT(eo & ECMAScriptFlags::Insensitive);
|
||||
EXPECT(!(eo & ECMAScriptFlags::Multiline));
|
||||
|
||||
eo &= ECMAScriptFlags::Sticky;
|
||||
EXPECT(!(eo & ECMAScriptFlags::Global));
|
||||
EXPECT(!(eo & ECMAScriptFlags::Insensitive));
|
||||
EXPECT(!(eo & ECMAScriptFlags::Multiline));
|
||||
EXPECT(!(eo & ECMAScriptFlags::Sticky));
|
||||
|
||||
eo = ~ECMAScriptFlags::Insensitive;
|
||||
EXPECT(eo & ECMAScriptFlags::Global);
|
||||
EXPECT(!(eo & ECMAScriptFlags::Insensitive));
|
||||
EXPECT(eo & ECMAScriptFlags::Multiline);
|
||||
EXPECT(eo & ECMAScriptFlags::Sticky);
|
||||
}
|
||||
|
||||
TEST_CASE(regex_options_posix)
|
||||
{
|
||||
PosixOptions eo;
|
||||
eo |= PosixFlags::Global;
|
||||
|
||||
EXPECT(eo & PosixFlags::Global);
|
||||
EXPECT(!(eo & PosixFlags::Insensitive));
|
||||
|
||||
eo = match_test_api_options(PosixFlags::Global | PosixFlags::Insensitive | PosixFlags::MatchNotBeginOfLine);
|
||||
EXPECT(eo & PosixFlags::Global);
|
||||
EXPECT(eo & PosixFlags::Insensitive);
|
||||
EXPECT(eo & PosixFlags::MatchNotBeginOfLine);
|
||||
EXPECT(!(eo & PosixFlags::Unicode));
|
||||
EXPECT(!(eo & PosixFlags::Multiline));
|
||||
|
||||
eo &= PosixFlags::Insensitive;
|
||||
EXPECT(!(eo & PosixFlags::Global));
|
||||
EXPECT(eo & PosixFlags::Insensitive);
|
||||
EXPECT(!(eo & PosixFlags::Multiline));
|
||||
|
||||
eo &= PosixFlags::MatchNotBeginOfLine;
|
||||
EXPECT(!(eo & PosixFlags::Global));
|
||||
EXPECT(!(eo & PosixFlags::Insensitive));
|
||||
EXPECT(!(eo & PosixFlags::Multiline));
|
||||
|
||||
eo = ~PosixFlags::Insensitive;
|
||||
EXPECT(eo & PosixFlags::Global);
|
||||
EXPECT(!(eo & PosixFlags::Insensitive));
|
||||
EXPECT(eo & PosixFlags::Multiline);
|
||||
}
|
||||
|
||||
TEST_CASE(regex_lexer)
|
||||
{
|
||||
Lexer l("/[.*+?^${}()|[\\]\\\\]/g");
|
||||
EXPECT(l.next().type() == regex::TokenType::Slash);
|
||||
EXPECT(l.next().type() == regex::TokenType::LeftBracket);
|
||||
EXPECT(l.next().type() == regex::TokenType::Period);
|
||||
EXPECT(l.next().type() == regex::TokenType::Asterisk);
|
||||
EXPECT(l.next().type() == regex::TokenType::Plus);
|
||||
EXPECT(l.next().type() == regex::TokenType::Questionmark);
|
||||
EXPECT(l.next().type() == regex::TokenType::Circumflex);
|
||||
EXPECT(l.next().type() == regex::TokenType::Dollar);
|
||||
EXPECT(l.next().type() == regex::TokenType::LeftCurly);
|
||||
EXPECT(l.next().type() == regex::TokenType::RightCurly);
|
||||
EXPECT(l.next().type() == regex::TokenType::LeftParen);
|
||||
EXPECT(l.next().type() == regex::TokenType::RightParen);
|
||||
EXPECT(l.next().type() == regex::TokenType::Pipe);
|
||||
EXPECT(l.next().type() == regex::TokenType::LeftBracket);
|
||||
EXPECT(l.next().type() == regex::TokenType::EscapeSequence);
|
||||
EXPECT(l.next().type() == regex::TokenType::EscapeSequence);
|
||||
EXPECT(l.next().type() == regex::TokenType::RightBracket);
|
||||
EXPECT(l.next().type() == regex::TokenType::Slash);
|
||||
EXPECT(l.next().type() == regex::TokenType::Char);
|
||||
}
|
||||
|
||||
TEST_CASE(parser_error_parens)
|
||||
{
|
||||
String pattern = "test()test";
|
||||
Lexer l(pattern);
|
||||
PosixExtendedParser p(l);
|
||||
p.parse();
|
||||
EXPECT(p.has_error());
|
||||
EXPECT(p.error() == Error::EmptySubExpression);
|
||||
}
|
||||
|
||||
TEST_CASE(parser_error_special_characters_used_at_wrong_place)
|
||||
{
|
||||
String pattern;
|
||||
Vector<char, 5> chars = { '*', '+', '?', '{' };
|
||||
StringBuilder b;
|
||||
|
||||
Lexer l;
|
||||
PosixExtended p(l);
|
||||
|
||||
for (auto& ch : chars) {
|
||||
// First in ere
|
||||
b.clear();
|
||||
b.append(ch);
|
||||
pattern = b.build();
|
||||
l.set_source(pattern);
|
||||
p.parse();
|
||||
EXPECT(p.has_error());
|
||||
EXPECT(p.error() == Error::InvalidRepetitionMarker);
|
||||
|
||||
// After vertical line
|
||||
b.clear();
|
||||
b.append("a|");
|
||||
b.append(ch);
|
||||
pattern = b.build();
|
||||
l.set_source(pattern);
|
||||
p.parse();
|
||||
EXPECT(p.has_error());
|
||||
EXPECT(p.error() == Error::InvalidRepetitionMarker);
|
||||
|
||||
// After circumflex
|
||||
b.clear();
|
||||
b.append("^");
|
||||
b.append(ch);
|
||||
pattern = b.build();
|
||||
l.set_source(pattern);
|
||||
p.parse();
|
||||
EXPECT(p.has_error());
|
||||
EXPECT(p.error() == Error::InvalidRepetitionMarker);
|
||||
|
||||
// After dollar
|
||||
b.clear();
|
||||
b.append("$");
|
||||
b.append(ch);
|
||||
pattern = b.build();
|
||||
l.set_source(pattern);
|
||||
p.parse();
|
||||
EXPECT(p.has_error());
|
||||
EXPECT(p.error() == Error::InvalidRepetitionMarker);
|
||||
|
||||
// After left parens
|
||||
b.clear();
|
||||
b.append("(");
|
||||
b.append(ch);
|
||||
b.append(")");
|
||||
pattern = b.build();
|
||||
l.set_source(pattern);
|
||||
p.parse();
|
||||
EXPECT(p.has_error());
|
||||
EXPECT(p.error() == Error::InvalidRepetitionMarker);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE(parser_error_vertical_line_used_at_wrong_place)
|
||||
{
|
||||
Lexer l;
|
||||
PosixExtended p(l);
|
||||
|
||||
// First in ere
|
||||
l.set_source("|asdf");
|
||||
p.parse();
|
||||
EXPECT(p.has_error());
|
||||
EXPECT(p.error() == Error::EmptySubExpression);
|
||||
|
||||
// Last in ere
|
||||
l.set_source("asdf|");
|
||||
p.parse();
|
||||
EXPECT(p.has_error());
|
||||
EXPECT(p.error() == Error::EmptySubExpression);
|
||||
|
||||
// After left parens
|
||||
l.set_source("(|asdf)");
|
||||
p.parse();
|
||||
EXPECT(p.has_error());
|
||||
EXPECT(p.error() == Error::EmptySubExpression);
|
||||
|
||||
// Proceed right parens
|
||||
l.set_source("(asdf)|");
|
||||
p.parse();
|
||||
EXPECT(p.has_error());
|
||||
EXPECT(p.error() == Error::EmptySubExpression);
|
||||
}
|
||||
|
||||
TEST_CASE(catch_all_first)
|
||||
{
|
||||
Regex<PosixExtended> re("^.*$");
|
||||
RegexResult m;
|
||||
re.match("Hello World", m);
|
||||
EXPECT(m.count == 1);
|
||||
EXPECT(re.match("Hello World", m));
|
||||
}
|
||||
|
||||
TEST_CASE(catch_all)
|
||||
{
|
||||
Regex<PosixExtended> re("^.*$", PosixFlags::Global);
|
||||
|
||||
EXPECT(re.has_match("Hello World"));
|
||||
EXPECT(re.match("Hello World").success);
|
||||
EXPECT(re.match("Hello World").count == 1);
|
||||
|
||||
EXPECT(has_match("Hello World", re));
|
||||
auto res = match("Hello World", re);
|
||||
EXPECT(res.success);
|
||||
EXPECT(res.count == 1);
|
||||
EXPECT(res.matches.size() == 1);
|
||||
EXPECT(res.matches.first().view == "Hello World");
|
||||
}
|
||||
|
||||
TEST_CASE(catch_all_again)
|
||||
{
|
||||
Regex<PosixExtended> re("^.*$", PosixFlags::Extra);
|
||||
EXPECT_EQ(has_match("Hello World", re), true);
|
||||
}
|
||||
|
||||
TEST_CASE(char_utf8)
|
||||
{
|
||||
Regex<PosixExtended> re("😀");
|
||||
RegexResult result;
|
||||
|
||||
EXPECT_EQ((result = match("Привет, мир! 😀 γειά σου κόσμος 😀 こんにちは世界", re, PosixFlags::Global)).success, true);
|
||||
EXPECT_EQ(result.count, 2u);
|
||||
}
|
||||
|
||||
TEST_CASE(catch_all_newline)
|
||||
{
|
||||
Regex<PosixExtended> re("^.*$", PosixFlags::Multiline | PosixFlags::StringCopyMatches);
|
||||
RegexResult result;
|
||||
auto lambda = [&result, &re]() {
|
||||
String aaa = "Hello World\nTest\n1234\n";
|
||||
result = match(aaa, re);
|
||||
EXPECT_EQ(result.success, true);
|
||||
};
|
||||
lambda();
|
||||
EXPECT_EQ(result.count, 3u);
|
||||
EXPECT_EQ(result.matches.at(0).view, "Hello World");
|
||||
EXPECT_EQ(result.matches.at(1).view, "Test");
|
||||
EXPECT_EQ(result.matches.at(2).view, "1234");
|
||||
}
|
||||
|
||||
TEST_CASE(catch_all_newline_view)
|
||||
{
|
||||
Regex<PosixExtended> re("^.*$", PosixFlags::Multiline);
|
||||
RegexResult result;
|
||||
|
||||
String aaa = "Hello World\nTest\n1234\n";
|
||||
result = match(aaa, re);
|
||||
EXPECT_EQ(result.success, true);
|
||||
EXPECT_EQ(result.count, 3u);
|
||||
String str = "Hello World";
|
||||
EXPECT_EQ(result.matches.at(0).view, str.view());
|
||||
EXPECT_EQ(result.matches.at(1).view, "Test");
|
||||
EXPECT_EQ(result.matches.at(2).view, "1234");
|
||||
}
|
||||
|
||||
TEST_CASE(catch_all_newline_2)
|
||||
{
|
||||
Regex<PosixExtended> re("^.*$");
|
||||
RegexResult result;
|
||||
result = match("Hello World\nTest\n1234\n", re, PosixFlags::Multiline | PosixFlags::StringCopyMatches);
|
||||
EXPECT_EQ(result.success, true);
|
||||
EXPECT_EQ(result.count, 3u);
|
||||
EXPECT_EQ(result.matches.at(0).view, "Hello World");
|
||||
EXPECT_EQ(result.matches.at(1).view, "Test");
|
||||
EXPECT_EQ(result.matches.at(2).view, "1234");
|
||||
|
||||
result = match("Hello World\nTest\n1234\n", re);
|
||||
EXPECT_EQ(result.success, true);
|
||||
EXPECT_EQ(result.count, 1u);
|
||||
EXPECT_EQ(result.matches.at(0).view, "Hello World\nTest\n1234\n");
|
||||
}
|
||||
|
||||
TEST_CASE(match_all_character_class)
|
||||
{
|
||||
Regex<PosixExtended> re("[[:alpha:]]");
|
||||
String str = "[Window]\nOpacity=255\nAudibleBeep=0\n";
|
||||
RegexResult result = match(str, re, PosixFlags::Global | PosixFlags::StringCopyMatches);
|
||||
|
||||
EXPECT_EQ(result.success, true);
|
||||
EXPECT_EQ(result.count, 24u);
|
||||
EXPECT_EQ(result.matches.at(0).view, "W");
|
||||
EXPECT_EQ(result.matches.at(1).view, "i");
|
||||
EXPECT_EQ(result.matches.at(2).view, "n");
|
||||
EXPECT(&result.matches.at(0).view.characters_without_null_termination()[0] != &str.view().characters_without_null_termination()[1]);
|
||||
}
|
||||
|
||||
TEST_CASE(match_character_class_with_assertion)
|
||||
{
|
||||
Regex<PosixExtended> re("[[:alpha:]]+$");
|
||||
String str = "abcdef";
|
||||
RegexResult result = match(str, re);
|
||||
|
||||
EXPECT_EQ(result.success, true);
|
||||
EXPECT_EQ(result.count, 1u);
|
||||
}
|
||||
|
||||
TEST_CASE(example_for_git_commit)
|
||||
{
|
||||
Regex<PosixExtended> re("^.*$");
|
||||
auto result = re.match("Well, hello friends!\nHello World!");
|
||||
|
||||
EXPECT(result.success);
|
||||
EXPECT(result.count == 1);
|
||||
EXPECT(result.matches.at(0).view.starts_with("Well"));
|
||||
EXPECT(result.matches.at(0).view.length() == 33);
|
||||
|
||||
EXPECT(re.has_match("Well,...."));
|
||||
|
||||
result = re.match("Well, hello friends!\nHello World!", PosixFlags::Multiline);
|
||||
|
||||
EXPECT(result.success);
|
||||
EXPECT(result.count == 2);
|
||||
EXPECT(result.matches.at(0).view == "Well, hello friends!");
|
||||
EXPECT(result.matches.at(1).view == "Hello World!");
|
||||
}
|
||||
|
||||
TEST_CASE(email_address)
|
||||
{
|
||||
Regex<PosixExtended> re("^[A-Z0-9a-z._%+-]{1,64}@([A-Za-z0-9-]{1,63}\\.){1,125}[A-Za-z]{2,63}$");
|
||||
EXPECT(re.has_match("hello.world@domain.tld"));
|
||||
EXPECT(re.has_match("this.is.a.very_long_email_address@world.wide.web"));
|
||||
}
|
||||
|
||||
TEST_CASE(ini_file_entries)
|
||||
{
|
||||
Regex<PosixExtended> re("[[:alpha:]]*=([[:digit:]]*)|\\[(.*)\\]");
|
||||
RegexResult result;
|
||||
|
||||
if constexpr (REGEX_DEBUG) {
|
||||
RegexDebug regex_dbg(stderr);
|
||||
regex_dbg.print_raw_bytecode(re);
|
||||
regex_dbg.print_header();
|
||||
regex_dbg.print_bytecode(re);
|
||||
}
|
||||
|
||||
String haystack = "[Window]\nOpacity=255\nAudibleBeep=0\n";
|
||||
EXPECT_EQ(re.search(haystack.view(), result, PosixFlags::Multiline), true);
|
||||
EXPECT_EQ(result.count, 3u);
|
||||
|
||||
if constexpr (REGEX_DEBUG) {
|
||||
for (auto& v : result.matches)
|
||||
fprintf(stderr, "%s\n", v.view.to_string().characters());
|
||||
}
|
||||
|
||||
EXPECT_EQ(result.matches.at(0).view, "[Window]");
|
||||
EXPECT_EQ(result.capture_group_matches.at(0).at(0).view, "Window");
|
||||
EXPECT_EQ(result.matches.at(1).view, "Opacity=255");
|
||||
EXPECT_EQ(result.matches.at(1).line, 1u);
|
||||
EXPECT_EQ(result.matches.at(1).column, 0u);
|
||||
EXPECT_EQ(result.capture_group_matches.at(1).at(0).view, "255");
|
||||
EXPECT_EQ(result.capture_group_matches.at(1).at(0).line, 1u);
|
||||
EXPECT_EQ(result.capture_group_matches.at(1).at(0).column, 8u);
|
||||
EXPECT_EQ(result.matches.at(2).view, "AudibleBeep=0");
|
||||
EXPECT_EQ(result.capture_group_matches.at(2).at(0).view, "0");
|
||||
EXPECT_EQ(result.capture_group_matches.at(2).at(0).line, 2u);
|
||||
EXPECT_EQ(result.capture_group_matches.at(2).at(0).column, 12u);
|
||||
}
|
||||
|
||||
TEST_CASE(ini_file_entries2)
|
||||
{
|
||||
Regex<PosixExtended> re("[[:alpha:]]*=([[:digit:]]*)");
|
||||
RegexResult result;
|
||||
|
||||
String haystack = "ViewMode=Icon";
|
||||
|
||||
EXPECT_EQ(re.match(haystack.view(), result), false);
|
||||
EXPECT_EQ(result.count, 0u);
|
||||
|
||||
EXPECT_EQ(re.search(haystack.view(), result), true);
|
||||
EXPECT_EQ(result.count, 1u);
|
||||
}
|
||||
|
||||
TEST_CASE(named_capture_group)
|
||||
{
|
||||
Regex<PosixExtended> re("[[:alpha:]]*=(?<Test>[[:digit:]]*)");
|
||||
RegexResult result;
|
||||
|
||||
if constexpr (REGEX_DEBUG) {
|
||||
RegexDebug regex_dbg(stderr);
|
||||
regex_dbg.print_raw_bytecode(re);
|
||||
regex_dbg.print_header();
|
||||
regex_dbg.print_bytecode(re);
|
||||
}
|
||||
|
||||
String haystack = "[Window]\nOpacity=255\nAudibleBeep=0\n";
|
||||
EXPECT_EQ(re.search(haystack, result, PosixFlags::Multiline), true);
|
||||
EXPECT_EQ(result.count, 2u);
|
||||
EXPECT_EQ(result.matches.at(0).view, "Opacity=255");
|
||||
EXPECT_EQ(result.named_capture_group_matches.at(0).ensure("Test").view, "255");
|
||||
EXPECT_EQ(result.matches.at(1).view, "AudibleBeep=0");
|
||||
EXPECT_EQ(result.named_capture_group_matches.at(1).ensure("Test").view, "0");
|
||||
}
|
||||
|
||||
TEST_CASE(a_star)
|
||||
{
|
||||
Regex<PosixExtended> re("a*");
|
||||
RegexResult result;
|
||||
|
||||
if constexpr (REGEX_DEBUG) {
|
||||
RegexDebug regex_dbg(stderr);
|
||||
regex_dbg.print_raw_bytecode(re);
|
||||
regex_dbg.print_header();
|
||||
regex_dbg.print_bytecode(re);
|
||||
}
|
||||
|
||||
String haystack = "[Window]\nOpacity=255\nAudibleBeep=0\n";
|
||||
EXPECT_EQ(re.search(haystack.view(), result, PosixFlags::Multiline), true);
|
||||
EXPECT_EQ(result.count, 32u);
|
||||
EXPECT_EQ(result.matches.at(0).view.length(), 0u);
|
||||
EXPECT_EQ(result.matches.at(10).view.length(), 1u);
|
||||
EXPECT_EQ(result.matches.at(10).view, "a");
|
||||
EXPECT_EQ(result.matches.at(31).view.length(), 0u);
|
||||
}
|
||||
|
||||
TEST_CASE(simple_period_end_benchmark)
|
||||
{
|
||||
Regex<PosixExtended> re("hello.$");
|
||||
RegexResult m;
|
||||
EXPECT_EQ(re.search("Hello1", m), false);
|
||||
EXPECT_EQ(re.search("hello1hello1", m), true);
|
||||
EXPECT_EQ(re.search("hello2hell", m), false);
|
||||
EXPECT_EQ(re.search("hello?", m), true);
|
||||
}
|
||||
|
||||
TEST_CASE(ECMA262_parse)
|
||||
{
|
||||
struct _test {
|
||||
const char* pattern;
|
||||
regex::Error expected_error { regex::Error::NoError };
|
||||
regex::ECMAScriptFlags flags {};
|
||||
};
|
||||
|
||||
constexpr _test tests[] {
|
||||
{ "^hello.$" },
|
||||
{ "^(hello.)$" },
|
||||
{ "^h{0,1}ello.$" },
|
||||
{ "^hello\\W$" },
|
||||
{ "^hell\\w.$" },
|
||||
{ "^hell\\x6f1$" }, // ^hello1$
|
||||
{ "^hel(?:l\\w).$" },
|
||||
{ "^hel(?<LO>l\\w).$" },
|
||||
{ "^[-a-zA-Z\\w\\s]+$" },
|
||||
{ "\\bhello\\B" },
|
||||
{ "^[\\w+/_-]+[=]{0,2}$" }, // #4189
|
||||
{ "^(?:[^<]*(<[\\w\\W]+>)[^>]*$|#([\\w\\-]*)$)" }, // #4189
|
||||
{ "\\/" }, // #4189
|
||||
{ ",/=-:" }, // #4243
|
||||
{ "\\x" }, // Even invalid escapes are allowed if ~unicode.
|
||||
{ "\\", regex::Error::InvalidTrailingEscape },
|
||||
{ "(?", regex::Error::InvalidCaptureGroup },
|
||||
{ "\\u1234", regex::Error::NoError, regex::ECMAScriptFlags::Unicode },
|
||||
{ "[\\u1234]", regex::Error::NoError, regex::ECMAScriptFlags::Unicode },
|
||||
{ ",(?", regex::Error::InvalidCaptureGroup }, // #4583
|
||||
{ "{1}", regex::Error::InvalidPattern },
|
||||
{ "{1,2}", regex::Error::InvalidPattern },
|
||||
};
|
||||
|
||||
for (auto& test : tests) {
|
||||
Regex<ECMA262> re(test.pattern);
|
||||
EXPECT_EQ(re.parser_result.error, test.expected_error);
|
||||
if constexpr (REGEX_DEBUG) {
|
||||
dbgln("\n");
|
||||
RegexDebug regex_dbg(stderr);
|
||||
regex_dbg.print_raw_bytecode(re);
|
||||
regex_dbg.print_header();
|
||||
regex_dbg.print_bytecode(re);
|
||||
dbgln("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE(ECMA262_match)
|
||||
{
|
||||
struct _test {
|
||||
const char* pattern;
|
||||
const char* subject;
|
||||
bool matches { true };
|
||||
ECMAScriptFlags options {};
|
||||
};
|
||||
// clang-format off
|
||||
constexpr _test tests[] {
|
||||
{ "^hello.$", "hello1" },
|
||||
{ "^(hello.)$", "hello1" },
|
||||
{ "^h{0,1}ello.$", "ello1" },
|
||||
{ "^hello\\W$", "hello!" },
|
||||
{ "^hell\\w.$", "hellx!" },
|
||||
{ "^hell\\x6f1$", "hello1" },
|
||||
{ "^hel(?<LO>l.)1$", "hello1" },
|
||||
{ "^hel(?<LO>l.)1*\\k<LO>.$", "hello1lo1" },
|
||||
{ "^[-a-z1-3\\s]+$", "hell2 o1" },
|
||||
{ "^[\\0-\\x1f]$", "\n" },
|
||||
{ .pattern = "\\bhello\\B", .subject = "hello1", .options = ECMAScriptFlags::Global },
|
||||
{ "\\b.*\\b", "hello1" },
|
||||
{ "[^\\D\\S]{2}", "1 " },
|
||||
{ "bar(?=f.)foo", "barfoo" },
|
||||
{ "bar(?=foo)bar", "barbar", false },
|
||||
{ "bar(?!foo)bar", "barbar", true },
|
||||
{ "bar(?!bar)bar", "barbar", false },
|
||||
{ "bar.*(?<=foo)", "barbar", false },
|
||||
{ "bar.*(?<!foo)", "barbar", true },
|
||||
{ "((...)X)+", "fooXbarXbazX", true },
|
||||
{ "(?:)", "", true },
|
||||
{ "\\^", "^" },
|
||||
// ECMA262, B.1.4. Regular Expression Pattern extensions for browsers
|
||||
{ "{", "{", true, ECMAScriptFlags::BrowserExtended },
|
||||
{ "\\5", "\5", true, ECMAScriptFlags::BrowserExtended },
|
||||
{ "\\05", "\5", true, ECMAScriptFlags::BrowserExtended },
|
||||
{ "\\455", "\45""5", true, ECMAScriptFlags::BrowserExtended },
|
||||
{ "\\314", "\314", true, ECMAScriptFlags::BrowserExtended },
|
||||
{ "\\cf", "\06", true, ECMAScriptFlags::BrowserExtended },
|
||||
{ "\\c1", "\\c1", true, ECMAScriptFlags::BrowserExtended },
|
||||
{ "[\\c1]", "\x11", true, ECMAScriptFlags::BrowserExtended },
|
||||
{ "[\\w-\\d]", "-", true, ECMAScriptFlags::BrowserExtended },
|
||||
{ "^(?:^^\\.?|[!+-]|!=|!==|#|%|%=|&|&&|&&=|&=|\\(|\\*|\\*=|\\+=|,|-=|->|\\/|\\/=|:|::|;|<|<<|<<=|<=|=|==|===|>|>=|>>|>>=|>>>|>>>=|[?@[^]|\\^=|\\^\\^|\\^\\^=|{|\\||\\|=|\\|\\||\\|\\|=|~|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\\s*(\\/(?=[^*/])(?:[^/[\\\\]|\\\\[\\S\\s]|\\[(?:[^\\\\\\]]|\\\\[\\S\\s])*(?:]|$))+\\/)",
|
||||
"return /xx/", true, ECMAScriptFlags::BrowserExtended
|
||||
}, // #5517, appears to be matching JS expressions that involve regular expressions...
|
||||
{ "a{2,}", "aaaa" }, // #5518
|
||||
};
|
||||
// clang-format on
|
||||
|
||||
for (auto& test : tests) {
|
||||
Regex<ECMA262> re(test.pattern, test.options);
|
||||
if constexpr (REGEX_DEBUG) {
|
||||
dbgln("\n");
|
||||
RegexDebug regex_dbg(stderr);
|
||||
regex_dbg.print_raw_bytecode(re);
|
||||
regex_dbg.print_header();
|
||||
regex_dbg.print_bytecode(re);
|
||||
dbgln("\n");
|
||||
}
|
||||
EXPECT_EQ(re.parser_result.error, Error::NoError);
|
||||
EXPECT_EQ(re.match(test.subject).success, test.matches);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE(replace)
|
||||
{
|
||||
struct _test {
|
||||
const char* pattern;
|
||||
const char* replacement;
|
||||
const char* subject;
|
||||
const char* expected;
|
||||
ECMAScriptFlags options {};
|
||||
};
|
||||
|
||||
constexpr _test tests[] {
|
||||
{ "foo(.+)", "aaa", "test", "test" },
|
||||
{ "foo(.+)", "test\\1", "foobar", "testbar" },
|
||||
{ "foo(.+)", "\\2\\1", "foobar", "\\2bar" },
|
||||
{ "foo(.+)", "\\\\\\1", "foobar", "\\bar" },
|
||||
{ "foo(.)", "a\\1", "fooxfooy", "axay", ECMAScriptFlags::Multiline },
|
||||
};
|
||||
|
||||
for (auto& test : tests) {
|
||||
Regex<ECMA262> re(test.pattern, test.options);
|
||||
if constexpr (REGEX_DEBUG) {
|
||||
dbgln("\n");
|
||||
RegexDebug regex_dbg(stderr);
|
||||
regex_dbg.print_raw_bytecode(re);
|
||||
regex_dbg.print_header();
|
||||
regex_dbg.print_bytecode(re);
|
||||
dbgln("\n");
|
||||
}
|
||||
EXPECT_EQ(re.parser_result.error, Error::NoError);
|
||||
EXPECT_EQ(re.replace(test.subject, test.replacement), test.expected);
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue