diff options
author | Ruslan Kovalev <ruslan.a.kovalev@gmail.com> | 2022-02-10 16:46:45 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:45 +0300 |
commit | 9123176b341b6f2658cff5132482b8237c1416c8 (patch) | |
tree | 49e222ea1c5804306084bb3ae065bb702625360f /util/string/subst_ut.cpp | |
parent | 59e19371de37995fcb36beb16cd6ec030af960bc (diff) | |
download | ydb-9123176b341b6f2658cff5132482b8237c1416c8.tar.gz |
Restoring authorship annotation for Ruslan Kovalev <ruslan.a.kovalev@gmail.com>. Commit 2 of 2.
Diffstat (limited to 'util/string/subst_ut.cpp')
-rw-r--r-- | util/string/subst_ut.cpp | 180 |
1 files changed, 90 insertions, 90 deletions
diff --git a/util/string/subst_ut.cpp b/util/string/subst_ut.cpp index 2a966992be..21eccef779 100644 --- a/util/string/subst_ut.cpp +++ b/util/string/subst_ut.cpp @@ -1,124 +1,124 @@ -#include "join.h" +#include "join.h" #include "subst.h" #include <string> #include <library/cpp/testing/unittest/registar.h> Y_UNIT_TEST_SUITE(TStringSubst) { - static const size_t MIN_FROM_CTX = 4; + static const size_t MIN_FROM_CTX = 4; static const TVector<TString> ALL_FROM{TString("F"), TString("FF")}; static const TVector<TString> ALL_TO{TString(""), TString("T"), TString("TT"), TString("TTT")}; - + static void AssertSubstGlobal(const TString& sFrom, const TString& sTo, const TString& from, const TString& to, const size_t fromPos, const size_t numSubst) { TString s = sFrom; - size_t res = SubstGlobal(s, from, to, fromPos); - UNIT_ASSERT_VALUES_EQUAL_C(res, numSubst, - TStringBuilder() << "numSubst=" << numSubst << ", fromPos=" << fromPos << ", " << sFrom << " -> " << sTo); - if (numSubst) { - UNIT_ASSERT_STRINGS_EQUAL_C(s, sTo, - TStringBuilder() << "numSubst=" << numSubst << ", fromPos=" << fromPos << ", " << sFrom << " -> " << sTo); - } else { - // ensure s didn't trigger copy-on-write - UNIT_ASSERT_VALUES_EQUAL_C(s.c_str(), sFrom.c_str(), - TStringBuilder() << "numSubst=" << numSubst << ", fromPos=" << fromPos << ", " << sFrom << " -> " << sTo); - } - } - + size_t res = SubstGlobal(s, from, to, fromPos); + UNIT_ASSERT_VALUES_EQUAL_C(res, numSubst, + TStringBuilder() << "numSubst=" << numSubst << ", fromPos=" << fromPos << ", " << sFrom << " -> " << sTo); + if (numSubst) { + UNIT_ASSERT_STRINGS_EQUAL_C(s, sTo, + TStringBuilder() << "numSubst=" << numSubst << ", fromPos=" << fromPos << ", " << sFrom << " -> " << sTo); + } else { + // ensure s didn't trigger copy-on-write + UNIT_ASSERT_VALUES_EQUAL_C(s.c_str(), sFrom.c_str(), + TStringBuilder() << "numSubst=" << numSubst << ", fromPos=" << fromPos << ", " << sFrom << " -> " << sTo); + } + } + Y_UNIT_TEST(TestSubstGlobalNoSubstA) { - for (const auto& from : ALL_FROM) { + for (const auto& from : ALL_FROM) { const size_t fromSz = from.size(); - const size_t minSz = fromSz; - const size_t maxSz = fromSz + MIN_FROM_CTX; - for (size_t sz = minSz; sz <= maxSz; ++sz) { - for (size_t fromPos = 0; fromPos < sz; ++fromPos) { + const size_t minSz = fromSz; + const size_t maxSz = fromSz + MIN_FROM_CTX; + for (size_t sz = minSz; sz <= maxSz; ++sz) { + for (size_t fromPos = 0; fromPos < sz; ++fromPos) { TString s{sz, '.'}; - for (const auto& to : ALL_TO) { - AssertSubstGlobal(s, s, from, to, fromPos, 0); - } - } - } - } - } - + for (const auto& to : ALL_TO) { + AssertSubstGlobal(s, s, from, to, fromPos, 0); + } + } + } + } + } + Y_UNIT_TEST(TestSubstGlobalNoSubstB) { - for (const auto& from : ALL_FROM) { + for (const auto& from : ALL_FROM) { const size_t fromSz = from.size(); - const size_t minSz = fromSz; - const size_t maxSz = fromSz + MIN_FROM_CTX; - for (size_t sz = minSz; sz <= maxSz; ++sz) { - for (size_t fromPos = 0; fromPos <= sz - fromSz; ++fromPos) { - for (size_t fromBeg = 0; fromBeg < fromPos; ++fromBeg) { - const auto parts = { + const size_t minSz = fromSz; + const size_t maxSz = fromSz + MIN_FROM_CTX; + for (size_t sz = minSz; sz <= maxSz; ++sz) { + for (size_t fromPos = 0; fromPos <= sz - fromSz; ++fromPos) { + for (size_t fromBeg = 0; fromBeg < fromPos; ++fromBeg) { + const auto parts = { TString{fromBeg, '.'}, TString{sz - fromSz - fromBeg, '.'}}; TString s = JoinSeq(from, parts); - for (const auto& to : ALL_TO) { - AssertSubstGlobal(s, s, from, to, fromPos, 0); - } - } - } - } - } - } - + for (const auto& to : ALL_TO) { + AssertSubstGlobal(s, s, from, to, fromPos, 0); + } + } + } + } + } + } + static void DoTestSubstGlobal(TVector<TString>& parts, const size_t minBeg, const size_t sz, const TString& from, const size_t fromPos, const size_t numSubst) { - const size_t numLeft = numSubst - parts.size(); + const size_t numLeft = numSubst - parts.size(); for (size_t fromBeg = minBeg; fromBeg <= sz - numLeft * from.size(); ++fromBeg) { - if (parts.empty()) { - parts.emplace_back(fromBeg, '.'); - } else { - parts.emplace_back(fromBeg - minBeg, '.'); - } - - if (numLeft == 1) { + if (parts.empty()) { + parts.emplace_back(fromBeg, '.'); + } else { + parts.emplace_back(fromBeg - minBeg, '.'); + } + + if (numLeft == 1) { parts.emplace_back(sz - fromBeg - from.size(), '.'); TString sFrom = JoinSeq(from, parts); UNIT_ASSERT_VALUES_EQUAL_C(sFrom.size(), sz, sFrom); - for (const auto& to : ALL_TO) { + for (const auto& to : ALL_TO) { TString sTo = JoinSeq(to, parts); - AssertSubstGlobal(sFrom, sTo, from, to, fromPos, numSubst); - } - parts.pop_back(); - } else { + AssertSubstGlobal(sFrom, sTo, from, to, fromPos, numSubst); + } + parts.pop_back(); + } else { DoTestSubstGlobal(parts, fromBeg + from.size(), sz, from, fromPos, numSubst); - } - - parts.pop_back(); - } - } - - static void DoTestSubstGlobal(size_t numSubst) { + } + + parts.pop_back(); + } + } + + static void DoTestSubstGlobal(size_t numSubst) { TVector<TString> parts; - for (const auto& from : ALL_FROM) { + for (const auto& from : ALL_FROM) { const size_t fromSz = from.size(); - const size_t minSz = numSubst * fromSz; - const size_t maxSz = numSubst * (fromSz + MIN_FROM_CTX); - for (size_t sz = minSz; sz <= maxSz; ++sz) { - const size_t maxPos = sz - numSubst * fromSz; - for (size_t fromPos = 0; fromPos <= maxPos; ++fromPos) { - DoTestSubstGlobal(parts, fromPos, sz, from, fromPos, numSubst); - } - } - } - } - + const size_t minSz = numSubst * fromSz; + const size_t maxSz = numSubst * (fromSz + MIN_FROM_CTX); + for (size_t sz = minSz; sz <= maxSz; ++sz) { + const size_t maxPos = sz - numSubst * fromSz; + for (size_t fromPos = 0; fromPos <= maxPos; ++fromPos) { + DoTestSubstGlobal(parts, fromPos, sz, from, fromPos, numSubst); + } + } + } + } + Y_UNIT_TEST(TestSubstGlobalSubst1) { - DoTestSubstGlobal(1); - } - + DoTestSubstGlobal(1); + } + Y_UNIT_TEST(TestSubstGlobalSubst2) { - DoTestSubstGlobal(2); - } - + DoTestSubstGlobal(2); + } + Y_UNIT_TEST(TestSubstGlobalSubst3) { - DoTestSubstGlobal(3); - } - + DoTestSubstGlobal(3); + } + Y_UNIT_TEST(TestSubstGlobalSubst4) { - DoTestSubstGlobal(4); - } - + DoTestSubstGlobal(4); + } + Y_UNIT_TEST(TestSubstGlobalOld) { TString s; s = "aaa"; @@ -137,7 +137,7 @@ Y_UNIT_TEST_SUITE(TStringSubst) { SubstGlobal(s, " ~ ", " "); UNIT_ASSERT_EQUAL(s, TString("Москва Париж")); } - + Y_UNIT_TEST(TestSubstGlobalOldRet) { const TString s1 = "aaa"; const TString s2 = SubstGlobalCopy(s1, "a", "bb"); |