aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/regex/hyperscan/ut/hyperscan_ut.cpp
diff options
context:
space:
mode:
authorartyasen <artyasen@yandex-team.com>2025-01-10 10:43:42 +0300
committerartyasen <artyasen@yandex-team.com>2025-01-10 11:54:42 +0300
commit215178650c519a89f29a47f942fe2be607a91e58 (patch)
tree58313a1490bf7d70dde00647915e468ae55e710d /library/cpp/regex/hyperscan/ut/hyperscan_ut.cpp
parent2677f7fd48473bd66e77dbf330dc9065db086e9f (diff)
downloadydb-215178650c519a89f29a47f942fe2be607a91e58.tar.gz
HyperScan literal compilation
add literal compilation commit_hash:29f6f2d5c4ec11ceb61add67bc4e697194a4efff
Diffstat (limited to 'library/cpp/regex/hyperscan/ut/hyperscan_ut.cpp')
-rw-r--r--library/cpp/regex/hyperscan/ut/hyperscan_ut.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/library/cpp/regex/hyperscan/ut/hyperscan_ut.cpp b/library/cpp/regex/hyperscan/ut/hyperscan_ut.cpp
index 75cd0bcc89..063ca3dd03 100644
--- a/library/cpp/regex/hyperscan/ut/hyperscan_ut.cpp
+++ b/library/cpp/regex/hyperscan/ut/hyperscan_ut.cpp
@@ -27,6 +27,22 @@ Y_UNIT_TEST_SUITE(HyperscanWrappers) {
UNIT_ASSERT_EQUAL(foundId, 0);
}
+ Y_UNIT_TEST(CompileLiteralAndScan) {
+ TDatabase db = CompileLiteral("a.c?[)", HS_FLAG_SINGLEMATCH);
+ TScratch scratch = MakeScratch(db);
+
+ unsigned int foundId = 42;
+ auto callback = [&](unsigned int id, unsigned long long /* from */, unsigned long long /* to */) {
+ foundId = id;
+ };
+ NHyperscan::Scan(
+ db,
+ scratch,
+ "a.c?[)",
+ callback);
+ UNIT_ASSERT_EQUAL(foundId, 0);
+ }
+
Y_UNIT_TEST(Matches) {
NHyperscan::TDatabase db = NHyperscan::Compile(
"a.c",
@@ -71,6 +87,49 @@ Y_UNIT_TEST_SUITE(HyperscanWrappers) {
UNIT_ASSERT(foundIds.contains(241));
}
+ Y_UNIT_TEST(MultiLiteral) {
+ static const TVector<TString> LITERALS = {
+ "foo.",
+ "bar.",
+ };
+ NHyperscan::TDatabase db = NHyperscan::CompileMultiLiteral(
+ {
+ LITERALS[0].c_str(),
+ LITERALS[1].c_str(),
+ },
+ {
+ HS_FLAG_SINGLEMATCH,
+ HS_FLAG_SINGLEMATCH | HS_FLAG_CASELESS,
+ },
+ {
+ 42,
+ 241,
+ },
+ {
+ LITERALS[0].size(),
+ LITERALS[1].size(),
+ });
+ NHyperscan::TScratch scratch = NHyperscan::MakeScratch(db);
+
+ UNIT_ASSERT(NHyperscan::Matches(db, scratch, "foo."));
+ UNIT_ASSERT(NHyperscan::Matches(db, scratch, "bar."));
+ UNIT_ASSERT(NHyperscan::Matches(db, scratch, "BAR."));
+ UNIT_ASSERT(!NHyperscan::Matches(db, scratch, "FOO."));
+
+ TSet<unsigned int> foundIds;
+ auto callback = [&](unsigned int id, unsigned long long /* from */, unsigned long long /* to */) {
+ foundIds.insert(id);
+ };
+ NHyperscan::Scan(
+ db,
+ scratch,
+ "foo.BaR.",
+ callback);
+ UNIT_ASSERT_EQUAL(foundIds.size(), 2);
+ UNIT_ASSERT(foundIds.contains(42));
+ UNIT_ASSERT(foundIds.contains(241));
+ }
+
// https://ml.yandex-team.ru/thread/2370000002965712422/
Y_UNIT_TEST(MultiRegression) {
NHyperscan::CompileMulti(