-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathregex.cpp
30 lines (25 loc) · 1.03 KB
/
regex.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
* Copyright (C) 2025 CESNET, https://photonics.cesnet.cz/
*
* Written by Jan Kundrát <[email protected]>
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <doctest/doctest.h>
#include <libyang-cpp/Regex.hpp>
#include <libyang-cpp/Utils.hpp>
TEST_CASE("regex")
{
using libyang::Regex;
using namespace std::string_literals;
REQUIRE_THROWS_WITH_AS(Regex{"\\"}, R"(Regular expression "\" is not valid ("": \ at end of pattern).: LY_EVALID)", libyang::ErrorWithCode);
Regex re{"ahoj"};
REQUIRE(re.matches("ahoj"));
REQUIRE(!re.matches("cau"));
REQUIRE(re.matches("ahoj")); // test repeated calls as well
REQUIRE(!re.matches("oj"));
REQUIRE(!re.matches("aho"));
// Testing runtime errors during pattern *matching* is tricky. There's a limit on backtracking,
// so testing a pattern like x+x+y on an obscenely long string of "x" characters *will* do the trick, eventually,
// but the PCRE2 library has a default limit of 10M attempts. That's a VERY big number to hit during a test :(.
}