diff options
| author | Alexander Smirnov <[email protected]> | 2025-01-11 00:21:49 +0000 |
|---|---|---|
| committer | Alexander Smirnov <[email protected]> | 2025-01-11 00:21:49 +0000 |
| commit | 457aacf7daabd8837feef98d1edcfe62420a1f47 (patch) | |
| tree | 3f8ca7735aac2ab4574833bf4ea5e1881a02ef84 /library/cpp/regex/hyperscan/ut/hyperscan_ut.cpp | |
| parent | af411bb10f1133d6e7f4c6324a89dde2f745d675 (diff) | |
| parent | 2d3b7f1966f9716551a0d7db72a9608addab8ecf (diff) | |
Merge branch 'rightlib' into merge-libs-250111-0020
Diffstat (limited to 'library/cpp/regex/hyperscan/ut/hyperscan_ut.cpp')
| -rw-r--r-- | library/cpp/regex/hyperscan/ut/hyperscan_ut.cpp | 59 |
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 75cd0bcc897..063ca3dd035 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( |
