diff options
author | bnagaev <bnagaev@yandex-team.ru> | 2022-02-10 16:47:04 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:04 +0300 |
commit | d6449ba66291ff0c0d352c82e6eb3efb4c8a7e8d (patch) | |
tree | d5dca6d44593f5e52556a1cc7b1ab0386e096ebe /library/cpp/regex/hyperscan/ut | |
parent | 1861d4c1402bb2c67a3e6b43b51706081b74508a (diff) | |
download | ydb-d6449ba66291ff0c0d352c82e6eb3efb4c8a7e8d.tar.gz |
Restoring authorship annotation for <bnagaev@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/regex/hyperscan/ut')
-rw-r--r-- | library/cpp/regex/hyperscan/ut/hyperscan_ut.cpp | 188 | ||||
-rw-r--r-- | library/cpp/regex/hyperscan/ut/ya.make | 14 |
2 files changed, 101 insertions, 101 deletions
diff --git a/library/cpp/regex/hyperscan/ut/hyperscan_ut.cpp b/library/cpp/regex/hyperscan/ut/hyperscan_ut.cpp index 9caa53f2e7f..28232b69822 100644 --- a/library/cpp/regex/hyperscan/ut/hyperscan_ut.cpp +++ b/library/cpp/regex/hyperscan/ut/hyperscan_ut.cpp @@ -1,125 +1,125 @@ #include <library/cpp/regex/hyperscan/hyperscan.h> - + #include <library/cpp/testing/unittest/registar.h> - -#include <util/generic/set.h> - + +#include <util/generic/set.h> + #include <array> #include <algorithm> Y_UNIT_TEST_SUITE(HyperscanWrappers) { - using namespace NHyperscan; + using namespace NHyperscan; using namespace NHyperscan::NPrivate; - + Y_UNIT_TEST(CompileAndScan) { - TDatabase db = Compile("a.c", HS_FLAG_DOTALL | HS_FLAG_SINGLEMATCH); - TScratch scratch = MakeScratch(db); - - unsigned int foundId = 42; + TDatabase db = Compile("a.c", HS_FLAG_DOTALL | 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, - "abc", + foundId = id; + }; + NHyperscan::Scan( + db, + scratch, + "abc", callback); - UNIT_ASSERT_EQUAL(foundId, 0); - } - + UNIT_ASSERT_EQUAL(foundId, 0); + } + Y_UNIT_TEST(Matches) { - NHyperscan::TDatabase db = NHyperscan::Compile( - "a.c", + NHyperscan::TDatabase db = NHyperscan::Compile( + "a.c", HS_FLAG_DOTALL | HS_FLAG_SINGLEMATCH); - NHyperscan::TScratch scratch = NHyperscan::MakeScratch(db); - UNIT_ASSERT(NHyperscan::Matches(db, scratch, "abc")); - UNIT_ASSERT(!NHyperscan::Matches(db, scratch, "foo")); - } - + NHyperscan::TScratch scratch = NHyperscan::MakeScratch(db); + UNIT_ASSERT(NHyperscan::Matches(db, scratch, "abc")); + UNIT_ASSERT(!NHyperscan::Matches(db, scratch, "foo")); + } + Y_UNIT_TEST(Multi) { - NHyperscan::TDatabase db = NHyperscan::CompileMulti( - { - "foo", - "bar", - }, - { - HS_FLAG_DOTALL | HS_FLAG_SINGLEMATCH, - HS_FLAG_DOTALL | HS_FLAG_SINGLEMATCH | HS_FLAG_CASELESS, - }, - { - 42, - 241, + NHyperscan::TDatabase db = NHyperscan::CompileMulti( + { + "foo", + "bar", + }, + { + HS_FLAG_DOTALL | HS_FLAG_SINGLEMATCH, + HS_FLAG_DOTALL | HS_FLAG_SINGLEMATCH | HS_FLAG_CASELESS, + }, + { + 42, + 241, }); - 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")); - + 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, - "fooBaR", + foundIds.insert(id); + }; + NHyperscan::Scan( + db, + scratch, + "fooBaR", callback); - UNIT_ASSERT_EQUAL(foundIds.size(), 2); + UNIT_ASSERT_EQUAL(foundIds.size(), 2); UNIT_ASSERT(foundIds.contains(42)); UNIT_ASSERT(foundIds.contains(241)); - } - - // https://ml.yandex-team.ru/thread/2370000002965712422/ + } + + // https://ml.yandex-team.ru/thread/2370000002965712422/ Y_UNIT_TEST(MultiRegression) { - NHyperscan::CompileMulti( - { - "aa.bb/cc.dd", - }, - { - HS_FLAG_UTF8, - }, - { - 0, + NHyperscan::CompileMulti( + { + "aa.bb/cc.dd", + }, + { + HS_FLAG_UTF8, + }, + { + 0, }); - } - + } + Y_UNIT_TEST(Serialize) { - NHyperscan::TDatabase db = NHyperscan::Compile( - "foo", + NHyperscan::TDatabase db = NHyperscan::Compile( + "foo", HS_FLAG_DOTALL | HS_FLAG_SINGLEMATCH); TString serialization = Serialize(db); - db.Reset(); - TDatabase db2 = Deserialize(serialization); - NHyperscan::TScratch scratch = NHyperscan::MakeScratch(db2); - - UNIT_ASSERT(NHyperscan::Matches(db2, scratch, "foo")); - UNIT_ASSERT(!NHyperscan::Matches(db2, scratch, "FOO")); - } - + db.Reset(); + TDatabase db2 = Deserialize(serialization); + NHyperscan::TScratch scratch = NHyperscan::MakeScratch(db2); + + UNIT_ASSERT(NHyperscan::Matches(db2, scratch, "foo")); + UNIT_ASSERT(!NHyperscan::Matches(db2, scratch, "FOO")); + } + Y_UNIT_TEST(GrowScratch) { - NHyperscan::TDatabase db1 = NHyperscan::Compile( - "foo", + NHyperscan::TDatabase db1 = NHyperscan::Compile( + "foo", HS_FLAG_DOTALL | HS_FLAG_SINGLEMATCH); - NHyperscan::TDatabase db2 = NHyperscan::Compile( - "longer\\w\\w\\wpattern", + NHyperscan::TDatabase db2 = NHyperscan::Compile( + "longer\\w\\w\\wpattern", HS_FLAG_DOTALL | HS_FLAG_SINGLEMATCH | HS_FLAG_UTF8); - NHyperscan::TScratch scratch = NHyperscan::MakeScratch(db1); - NHyperscan::GrowScratch(scratch, db2); - UNIT_ASSERT(NHyperscan::Matches(db1, scratch, "foo")); - UNIT_ASSERT(NHyperscan::Matches(db2, scratch, "longerWWWpattern")); - } - + NHyperscan::TScratch scratch = NHyperscan::MakeScratch(db1); + NHyperscan::GrowScratch(scratch, db2); + UNIT_ASSERT(NHyperscan::Matches(db1, scratch, "foo")); + UNIT_ASSERT(NHyperscan::Matches(db2, scratch, "longerWWWpattern")); + } + Y_UNIT_TEST(CloneScratch) { - NHyperscan::TDatabase db = NHyperscan::Compile( - "foo", + NHyperscan::TDatabase db = NHyperscan::Compile( + "foo", HS_FLAG_DOTALL | HS_FLAG_SINGLEMATCH); - NHyperscan::TScratch scratch1 = NHyperscan::MakeScratch(db); - NHyperscan::TScratch scratch2 = NHyperscan::CloneScratch(scratch1); - scratch1.Reset(); - UNIT_ASSERT(NHyperscan::Matches(db, scratch2, "foo")); - } + NHyperscan::TScratch scratch1 = NHyperscan::MakeScratch(db); + NHyperscan::TScratch scratch2 = NHyperscan::CloneScratch(scratch1); + scratch1.Reset(); + UNIT_ASSERT(NHyperscan::Matches(db, scratch2, "foo")); + } class TSimpleSingleRegex { public: @@ -228,4 +228,4 @@ Y_UNIT_TEST_SUITE(HyperscanWrappers) { TestCrossPlatformCompile<TAvx2SingleRegex>(); TestCrossPlatformCompile<TSimpleMultiRegex>(); } -} +} diff --git a/library/cpp/regex/hyperscan/ut/ya.make b/library/cpp/regex/hyperscan/ut/ya.make index da67b88672a..c255408521a 100644 --- a/library/cpp/regex/hyperscan/ut/ya.make +++ b/library/cpp/regex/hyperscan/ut/ya.make @@ -1,13 +1,13 @@ UNITTEST() - + PEERDIR( library/cpp/regex/hyperscan ) OWNER(g:antiinfra) - -SRCS( - hyperscan_ut.cpp -) - -END() + +SRCS( + hyperscan_ut.cpp +) + +END() |