diff options
author | Vlad Yaroslavlev <vladon@vladon.com> | 2022-02-10 16:46:23 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:23 +0300 |
commit | 706b83ed7de5a473436620367af31fc0ceecde07 (patch) | |
tree | 103305d30dec77e8f6367753367f59b3cd68f9f1 /util/string/subst_ut.cpp | |
parent | 918e8a1574070d0ec733f0b76cfad8f8892ad2e5 (diff) | |
download | ydb-706b83ed7de5a473436620367af31fc0ceecde07.tar.gz |
Restoring authorship annotation for Vlad Yaroslavlev <vladon@vladon.com>. Commit 1 of 2.
Diffstat (limited to 'util/string/subst_ut.cpp')
-rw-r--r-- | util/string/subst_ut.cpp | 156 |
1 files changed, 78 insertions, 78 deletions
diff --git a/util/string/subst_ut.cpp b/util/string/subst_ut.cpp index 21eccef779..e1e76a82fe 100644 --- a/util/string/subst_ut.cpp +++ b/util/string/subst_ut.cpp @@ -6,11 +6,11 @@ Y_UNIT_TEST_SUITE(TStringSubst) { 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 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; + 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); @@ -31,7 +31,7 @@ Y_UNIT_TEST_SUITE(TStringSubst) { 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, '.'}; + TString s{sz, '.'}; for (const auto& to : ALL_TO) { AssertSubstGlobal(s, s, from, to, fromPos, 0); } @@ -49,9 +49,9 @@ Y_UNIT_TEST_SUITE(TStringSubst) { 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); + TString{fromBeg, '.'}, + TString{sz - fromSz - fromBeg, '.'}}; + TString s = JoinSeq(from, parts); for (const auto& to : ALL_TO) { AssertSubstGlobal(s, s, from, to, fromPos, 0); } @@ -62,7 +62,7 @@ Y_UNIT_TEST_SUITE(TStringSubst) { } 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 TString& from, const size_t fromPos, const size_t numSubst) { const size_t numLeft = numSubst - parts.size(); for (size_t fromBeg = minBeg; fromBeg <= sz - numLeft * from.size(); ++fromBeg) { if (parts.empty()) { @@ -73,10 +73,10 @@ Y_UNIT_TEST_SUITE(TStringSubst) { if (numLeft == 1) { parts.emplace_back(sz - fromBeg - from.size(), '.'); - TString sFrom = JoinSeq(from, parts); + TString sFrom = JoinSeq(from, parts); UNIT_ASSERT_VALUES_EQUAL_C(sFrom.size(), sz, sFrom); for (const auto& to : ALL_TO) { - TString sTo = JoinSeq(to, parts); + TString sTo = JoinSeq(to, parts); AssertSubstGlobal(sFrom, sTo, from, to, fromPos, numSubst); } parts.pop_back(); @@ -89,7 +89,7 @@ Y_UNIT_TEST_SUITE(TStringSubst) { } static void DoTestSubstGlobal(size_t numSubst) { - TVector<TString> parts; + TVector<TString> parts; for (const auto& from : ALL_FROM) { const size_t fromSz = from.size(); const size_t minSz = numSubst * fromSz; @@ -120,132 +120,132 @@ Y_UNIT_TEST_SUITE(TStringSubst) { } Y_UNIT_TEST(TestSubstGlobalOld) { - TString s; + TString s; s = "aaa"; SubstGlobal(s, "a", "bb"); - UNIT_ASSERT_EQUAL(s, TString("bbbbbb")); + UNIT_ASSERT_EQUAL(s, TString("bbbbbb")); s = "aaa"; SubstGlobal(s, "a", "b"); - UNIT_ASSERT_EQUAL(s, TString("bbb")); + UNIT_ASSERT_EQUAL(s, TString("bbb")); s = "aaa"; SubstGlobal(s, "a", ""); - UNIT_ASSERT_EQUAL(s, TString("")); + UNIT_ASSERT_EQUAL(s, TString("")); s = "abcdefbcbcdfb"; SubstGlobal(s, "bc", "bbc", 2); - UNIT_ASSERT_EQUAL(s, TString("abcdefbbcbbcdfb")); + UNIT_ASSERT_EQUAL(s, TString("abcdefbbcbbcdfb")); s = "Москва ~ Париж"; SubstGlobal(s, " ~ ", " "); UNIT_ASSERT_EQUAL(s, TString("Москва Париж")); } - Y_UNIT_TEST(TestSubstGlobalOldRet) { - const TString s1 = "aaa"; - const TString s2 = SubstGlobalCopy(s1, "a", "bb"); - UNIT_ASSERT_EQUAL(s2, TString("bbbbbb")); - - const TString s3 = "aaa"; - const TString s4 = SubstGlobalCopy(s3, "a", "b"); - UNIT_ASSERT_EQUAL(s4, TString("bbb")); - - const TString s5 = "aaa"; - const TString s6 = SubstGlobalCopy(s5, "a", ""); - UNIT_ASSERT_EQUAL(s6, TString("")); - - const TString s7 = "abcdefbcbcdfb"; - const TString s8 = SubstGlobalCopy(s7, "bc", "bbc", 2); - UNIT_ASSERT_EQUAL(s8, TString("abcdefbbcbbcdfb")); - - const TString s9 = "Москва ~ Париж"; - const TString s10 = SubstGlobalCopy(s9, " ~ ", " "); - UNIT_ASSERT_EQUAL(s10, TString("Москва Париж")); - } - + Y_UNIT_TEST(TestSubstGlobalOldRet) { + const TString s1 = "aaa"; + const TString s2 = SubstGlobalCopy(s1, "a", "bb"); + UNIT_ASSERT_EQUAL(s2, TString("bbbbbb")); + + const TString s3 = "aaa"; + const TString s4 = SubstGlobalCopy(s3, "a", "b"); + UNIT_ASSERT_EQUAL(s4, TString("bbb")); + + const TString s5 = "aaa"; + const TString s6 = SubstGlobalCopy(s5, "a", ""); + UNIT_ASSERT_EQUAL(s6, TString("")); + + const TString s7 = "abcdefbcbcdfb"; + const TString s8 = SubstGlobalCopy(s7, "bc", "bbc", 2); + UNIT_ASSERT_EQUAL(s8, TString("abcdefbbcbbcdfb")); + + const TString s9 = "Москва ~ Париж"; + const TString s10 = SubstGlobalCopy(s9, " ~ ", " "); + UNIT_ASSERT_EQUAL(s10, TString("Москва Париж")); + } + Y_UNIT_TEST(TestSubstCharGlobal) { TUtf16String w = u"abcdabcd"; SubstGlobal(w, wchar16('b'), wchar16('B'), 3); UNIT_ASSERT_EQUAL(w, u"abcdaBcd"); - TString s = "aaa"; + TString s = "aaa"; SubstGlobal(s, 'a', 'b', 1); - UNIT_ASSERT_EQUAL(s, TString("abb")); + UNIT_ASSERT_EQUAL(s, TString("abb")); } - Y_UNIT_TEST(TestSubstCharGlobalRet) { + Y_UNIT_TEST(TestSubstCharGlobalRet) { const TUtf16String w1 = u"abcdabcd"; const TUtf16String w2 = SubstGlobalCopy(w1, wchar16('b'), wchar16('B'), 3); UNIT_ASSERT_EQUAL(w2, u"abcdaBcd"); - - const TString s1 = "aaa"; - const TString s2 = SubstGlobalCopy(s1, 'a', 'b', 1); - UNIT_ASSERT_EQUAL(s2, TString("abb")); - } - + + const TString s1 = "aaa"; + const TString s2 = SubstGlobalCopy(s1, 'a', 'b', 1); + UNIT_ASSERT_EQUAL(s2, TString("abb")); + } + Y_UNIT_TEST(TestSubstStdString) { std::string s = "aaa"; SubstGlobal(s, "a", "b", 1); UNIT_ASSERT_EQUAL(s, "abb"); } - Y_UNIT_TEST(TestSubstStdStringRet) { - const std::string s1 = "aaa"; - const std::string s2 = SubstGlobalCopy(s1, "a", "b", 1); - UNIT_ASSERT_EQUAL(s2, "abb"); - } - + Y_UNIT_TEST(TestSubstStdStringRet) { + const std::string s1 = "aaa"; + const std::string s2 = SubstGlobalCopy(s1, "a", "b", 1); + UNIT_ASSERT_EQUAL(s2, "abb"); + } + Y_UNIT_TEST(TestSubstGlobalChar) { { - const TString s = "a"; - const TString st = "b"; - TString ss = s; + const TString s = "a"; + const TString st = "b"; + TString ss = s; UNIT_ASSERT_VALUES_EQUAL(s.size(), SubstGlobal(ss, 'a', 'b')); UNIT_ASSERT_VALUES_EQUAL(st, ss); } { - const TString s = "aa"; - const TString st = "bb"; - TString ss = s; + const TString s = "aa"; + const TString st = "bb"; + TString ss = s; UNIT_ASSERT_VALUES_EQUAL(s.size(), SubstGlobal(ss, 'a', 'b')); UNIT_ASSERT_VALUES_EQUAL(st, ss); } { - const TString s = "aaa"; - const TString st = "bbb"; - TString ss = s; + const TString s = "aaa"; + const TString st = "bbb"; + TString ss = s; UNIT_ASSERT_VALUES_EQUAL(s.size(), SubstGlobal(ss, 'a', 'b')); UNIT_ASSERT_VALUES_EQUAL(st, ss); } { - const TString s = "aaaa"; - const TString st = "bbbb"; - TString ss = s; + const TString s = "aaaa"; + const TString st = "bbbb"; + TString ss = s; UNIT_ASSERT_VALUES_EQUAL(s.size(), SubstGlobal(ss, 'a', 'b')); UNIT_ASSERT_VALUES_EQUAL(st, ss); } { - const TString s = "aaaaa"; - const TString st = "bbbbb"; - TString ss = s; + const TString s = "aaaaa"; + const TString st = "bbbbb"; + TString ss = s; UNIT_ASSERT_VALUES_EQUAL(s.size(), SubstGlobal(ss, 'a', 'b')); UNIT_ASSERT_VALUES_EQUAL(st, ss); } { - const TString s = "aaaaaa"; - const TString st = "bbbbbb"; - TString ss = s; + const TString s = "aaaaaa"; + const TString st = "bbbbbb"; + TString ss = s; UNIT_ASSERT_VALUES_EQUAL(s.size(), SubstGlobal(ss, 'a', 'b')); UNIT_ASSERT_VALUES_EQUAL(st, ss); } { - const TString s = "aaaaaaa"; - const TString st = "bbbbbbb"; - TString ss = s; + const TString s = "aaaaaaa"; + const TString st = "bbbbbbb"; + TString ss = s; UNIT_ASSERT_VALUES_EQUAL(s.size(), SubstGlobal(ss, 'a', 'b')); UNIT_ASSERT_VALUES_EQUAL(st, ss); } { - const TString s = "aaaaaaaa"; - const TString st = "bbbbbbbb"; - TString ss = s; + const TString s = "aaaaaaaa"; + const TString st = "bbbbbbbb"; + TString ss = s; UNIT_ASSERT_VALUES_EQUAL(s.size(), SubstGlobal(ss, 'a', 'b')); UNIT_ASSERT_VALUES_EQUAL(st, ss); } |