diff options
author | pozhilov <pozhilov@yandex-team.ru> | 2022-02-10 16:49:27 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:27 +0300 |
commit | 23bf1d16dddf213a6aa8e8d5c8621e1242a1f118 (patch) | |
tree | ed030ff443eb83431f11e53b6460b1b73d035412 /util | |
parent | 7156b3713e77ce36387436e5558320917698b7a2 (diff) | |
download | ydb-23bf1d16dddf213a6aa8e8d5c8621e1242a1f118.tar.gz |
Restoring authorship annotation for <pozhilov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util')
-rw-r--r-- | util/datetime/base.h | 28 | ||||
-rw-r--r-- | util/datetime/base_ut.cpp | 4 | ||||
-rw-r--r-- | util/folder/path.h | 6 | ||||
-rw-r--r-- | util/folder/tempdir.h | 12 | ||||
-rw-r--r-- | util/generic/fwd.h | 14 | ||||
-rw-r--r-- | util/generic/hash.cpp | 16 | ||||
-rw-r--r-- | util/generic/hash.h | 26 | ||||
-rw-r--r-- | util/generic/hash_ut.cpp | 80 | ||||
-rw-r--r-- | util/generic/is_in.h | 4 | ||||
-rw-r--r-- | util/generic/is_in_ut.cpp | 14 | ||||
-rw-r--r-- | util/generic/maybe.h | 2 | ||||
-rw-r--r-- | util/generic/ptr_ut.cpp | 56 | ||||
-rw-r--r-- | util/generic/strbuf_ut.cpp | 6 | ||||
-rw-r--r-- | util/generic/typetraits_ut.cpp | 4 | ||||
-rw-r--r-- | util/generic/utility.h | 8 | ||||
-rw-r--r-- | util/generic/ylimits.h | 4 | ||||
-rw-r--r-- | util/generic/ymath.h | 2 | ||||
-rw-r--r-- | util/string/cast.h | 6 | ||||
-rw-r--r-- | util/string/cast.pxd | 6 | ||||
-rw-r--r-- | util/string/cast_ut.pyx | 12 | ||||
-rw-r--r-- | util/string/split.h | 24 | ||||
-rw-r--r-- | util/string/split_ut.cpp | 54 | ||||
-rw-r--r-- | util/tests/cython/test_generic.py | 2 | ||||
-rw-r--r-- | util/tests/cython/ya.make | 2 | ||||
-rw-r--r-- | util/ysaveload.h | 4 |
25 files changed, 198 insertions, 198 deletions
diff --git a/util/datetime/base.h b/util/datetime/base.h index 5e902b8f63..6a8710b3a6 100644 --- a/util/datetime/base.h +++ b/util/datetime/base.h @@ -45,7 +45,7 @@ class TDateTimeParseException: public yexception { const int DATE_BUF_LEN = 4 + 2 + 2 + 1; // [YYYYMMDD*] -constexpr long seconds(const struct tm& theTm) { +constexpr long seconds(const struct tm& theTm) { return 60 * (60 * theTm.tm_hour + theTm.tm_min) + theTm.tm_sec; } @@ -78,7 +78,7 @@ bool ParseHTTPDateTime(const char* date, size_t dateLen, time_t& utcTime); bool ParseX509ValidityDateTime(const char* date, time_t& utcTime); bool ParseX509ValidityDateTime(const char* date, size_t dateLen, time_t& utcTime); -constexpr long TVdiff(timeval r1, timeval r2) { +constexpr long TVdiff(timeval r1, timeval r2) { return (1000000 * (r2.tv_sec - r1.tv_sec) + (r2.tv_usec - r1.tv_usec)); } @@ -264,9 +264,9 @@ public: return TDuration(us); } - /* noexcept(false) as conversion from T might throw, for example FromString("abc") */ + /* noexcept(false) as conversion from T might throw, for example FromString("abc") */ template <typename T> - static constexpr TDuration MilliSeconds(T ms) noexcept(false) { + static constexpr TDuration MilliSeconds(T ms) noexcept(false) { return MicroSeconds((ui64)(typename NDateTimeHelpers::TPrecisionHelper<T>::THighPrecision(ms) * 1000)); } @@ -279,7 +279,7 @@ public: /// DeadLineFromTimeOut inline TInstant ToDeadLine() const; - constexpr TInstant ToDeadLine(TInstant now) const; + constexpr TInstant ToDeadLine(TInstant now) const; static constexpr TDuration Max() noexcept { return TDuration(::Max<TValue>()); @@ -289,9 +289,9 @@ public: return TDuration(); } - /* noexcept(false) as conversion from T might throw, for example FromString("abc") */ + /* noexcept(false) as conversion from T might throw, for example FromString("abc") */ template <typename T> - static constexpr TDuration Seconds(T s) noexcept(false) { + static constexpr TDuration Seconds(T s) noexcept(false) { return MilliSeconds(typename NDateTimeHelpers::TPrecisionHelper<T>::THighPrecision(s) * 1000); } @@ -571,7 +571,7 @@ namespace NPrivate { struct TPrintableLocalTime { TInstant MomentToPrint; - constexpr explicit TPrintableLocalTime(TInstant momentToPrint) + constexpr explicit TPrintableLocalTime(TInstant momentToPrint) : MomentToPrint(momentToPrint) { } @@ -633,17 +633,17 @@ static constexpr bool operator>=(const TTimeBase<S>& l, const TTimeBase<S>& r) n namespace NDateTimeHelpers { template <typename T> - static constexpr T SumWithSaturation(T a, T b) { + static constexpr T SumWithSaturation(T a, T b) { static_assert(!std::numeric_limits<T>::is_signed, "expect !std::numeric_limits<T>::is_signed"); - return Max<T>() - a < b ? Max<T>() : a + b; + return Max<T>() - a < b ? Max<T>() : a + b; } template <typename T> - static constexpr T DiffWithSaturation(T a, T b) { + static constexpr T DiffWithSaturation(T a, T b) { static_assert(!std::numeric_limits<T>::is_signed, "expect !std::numeric_limits<T>::is_signed"); - return a < b ? 0 : a - b; + return a < b ? 0 : a - b; } } @@ -803,11 +803,11 @@ constexpr double operator/(const TDuration& x, const TDuration& y) noexcept { return static_cast<double>(x.GetValue()) / static_cast<double>(y.GetValue()); } -inline TInstant TDuration::ToDeadLine() const { +inline TInstant TDuration::ToDeadLine() const { return ToDeadLine(TInstant::Now()); } -constexpr TInstant TDuration::ToDeadLine(TInstant now) const { +constexpr TInstant TDuration::ToDeadLine(TInstant now) const { return now + *this; } diff --git a/util/datetime/base_ut.cpp b/util/datetime/base_ut.cpp index afc3f802eb..0291c39329 100644 --- a/util/datetime/base_ut.cpp +++ b/util/datetime/base_ut.cpp @@ -491,11 +491,11 @@ Y_UNIT_TEST_SUITE(DateTimeTest) { Y_UNIT_TEST(TestDurationUnits) { TestTimeUnits<TDuration>(); } - + Y_UNIT_TEST(TestNoexceptConstruction) { UNIT_ASSERT_EXCEPTION(TDuration::MilliSeconds(FromString(TStringBuf("not a number"))), yexception); UNIT_ASSERT_EXCEPTION(TDuration::Seconds(FromString(TStringBuf("not a number"))), yexception); - } + } Y_UNIT_TEST(TestFromValueForTDuration) { // check that FromValue creates the same TDuration diff --git a/util/folder/path.h b/util/folder/path.h index 2fb4d6b4ef..62c9741d1b 100644 --- a/util/folder/path.h +++ b/util/folder/path.h @@ -62,9 +62,9 @@ public: TFsPath& operator/=(const TFsPath& that); - friend TFsPath operator/(const TFsPath& s, const TFsPath& p) { - TFsPath ret(s); - return ret /= p; + friend TFsPath operator/(const TFsPath& s, const TFsPath& p) { + TFsPath ret(s); + return ret /= p; } const TPathSplit& PathSplit() const; diff --git a/util/folder/tempdir.h b/util/folder/tempdir.h index ff458f83b9..0eef1c2e1f 100644 --- a/util/folder/tempdir.h +++ b/util/folder/tempdir.h @@ -1,7 +1,7 @@ #pragma once #include "fwd.h" -#include "path.h" +#include "path.h" #include <util/generic/string.h> class TTempDir { @@ -22,10 +22,10 @@ public: } const TString& Name() const { - return TempDir.GetPath(); - } - - const TFsPath& Path() const { + return TempDir.GetPath(); + } + + const TFsPath& Path() const { return TempDir; } @@ -38,6 +38,6 @@ private: // by requiring additional fake argument. TTempDir(const char* prefix, TCreationToken); - TFsPath TempDir; + TFsPath TempDir; bool Remove; }; diff --git a/util/generic/fwd.h b/util/generic/fwd.h index 5cc2da40e5..6bc808a8c2 100644 --- a/util/generic/fwd.h +++ b/util/generic/fwd.h @@ -132,7 +132,7 @@ class TSharedPtr; template <class T, class C = TCopyNew, class D = TDelete> class TCopyPtr; - + template <class TPtr, class TCopy = TCopyNew> class TCowPtr; @@ -151,13 +151,13 @@ using TArrayPtr = TAutoPtr<T, TDeleteArray>; template <typename T> using TMallocPtr = TAutoPtr<T, TFree>; -//maybe -namespace NMaybe { - struct TPolicyUndefinedExcept; -} +//maybe +namespace NMaybe { + struct TPolicyUndefinedExcept; +} -template <class T, class Policy = ::NMaybe::TPolicyUndefinedExcept> -class TMaybe; +template <class T, class Policy = ::NMaybe::TPolicyUndefinedExcept> +class TMaybe; struct TGUID; diff --git a/util/generic/hash.cpp b/util/generic/hash.cpp index a674ee4538..bbc922072e 100644 --- a/util/generic/hash.cpp +++ b/util/generic/hash.cpp @@ -1,18 +1,18 @@ #include "hash.h" -#include <util/string/escape.h> +#include <util/string/escape.h> #include <util/string/cast.h> const void* const _yhashtable_empty_data[] = {(void*)3, nullptr, (void*)1}; - + TString NPrivate::MapKeyToString(TStringBuf key) { - constexpr size_t HASH_KEY_MAX_LENGTH = 500; - try { - return EscapeC(key.substr(0, HASH_KEY_MAX_LENGTH)); - } catch (...) { + constexpr size_t HASH_KEY_MAX_LENGTH = 500; + try { + return EscapeC(key.substr(0, HASH_KEY_MAX_LENGTH)); + } catch (...) { return "TStringBuf"; - } -} + } +} TString NPrivate::MapKeyToString(unsigned short key) { return ToString(key); diff --git a/util/generic/hash.h b/util/generic/hash.h index e46db21fa9..30d00685e8 100644 --- a/util/generic/hash.h +++ b/util/generic/hash.h @@ -1390,12 +1390,12 @@ void THashTable<V, K, HF, Ex, Eq, A>::copy_from_dynamic(const THashTable& ht) { #endif /* __STL_USE_EXCEPTIONS */ } -namespace NPrivate { +namespace NPrivate { template <class Key> inline TString MapKeyToString(const Key&) { return TypeName<Key>(); - } - + } + TString MapKeyToString(TStringBuf key); TString MapKeyToString(unsigned short key); TString MapKeyToString(short key); @@ -1405,22 +1405,22 @@ namespace NPrivate { TString MapKeyToString(long key); TString MapKeyToString(unsigned long long key); TString MapKeyToString(long long key); - + inline TString MapKeyToString(const TString& key) { - return MapKeyToString(TStringBuf(key)); - } - + return MapKeyToString(TStringBuf(key)); + } + inline TString MapKeyToString(const char* key) { - return MapKeyToString(TStringBuf(key)); - } - + return MapKeyToString(TStringBuf(key)); + } + inline TString MapKeyToString(char* key) { - return MapKeyToString(TStringBuf(key)); - } + return MapKeyToString(TStringBuf(key)); + } [[noreturn]] void ThrowKeyNotFoundInHashTableException(const TStringBuf keyRepresentation); } - + template <class Key, class T, class HashFcn, class EqualKey, class Alloc> class THashMap: public TMapOps<THashMap<Key, T, HashFcn, EqualKey, Alloc>> { private: diff --git a/util/generic/hash_ut.cpp b/util/generic/hash_ut.cpp index 0551d58770..3df3371dbe 100644 --- a/util/generic/hash_ut.cpp +++ b/util/generic/hash_ut.cpp @@ -21,11 +21,11 @@ class THashTest: public TTestBase { UNIT_TEST(TestHMMap1); UNIT_TEST(TestHMMapHas); UNIT_TEST(TestHSetConstructorsAndAssignments); - UNIT_TEST(TestHSetSize); + UNIT_TEST(TestHSetSize); UNIT_TEST(TestHSet2); UNIT_TEST(TestHSetEqualityOperator); UNIT_TEST(TestHMSetConstructorsAndAssignments); - UNIT_TEST(TestHMSetSize); + UNIT_TEST(TestHMSetSize); UNIT_TEST(TestHMSet1); UNIT_TEST(TestHMSetEqualityOperator); UNIT_TEST(TestHMSetEmplace); @@ -52,7 +52,7 @@ class THashTest: public TTestBase { UNIT_TEST(TestValueInitialization); UNIT_TEST(TestAssignmentClear); UNIT_TEST(TestReleaseNodes); - UNIT_TEST(TestAt); + UNIT_TEST(TestAt); UNIT_TEST(TestHMapInitializerList); UNIT_TEST(TestHMMapInitializerList); UNIT_TEST(TestHSetInitializerList); @@ -72,11 +72,11 @@ protected: void TestHMMap1(); void TestHMMapHas(); void TestHSetConstructorsAndAssignments(); - void TestHSetSize(); + void TestHSetSize(); void TestHSet2(); void TestHSetEqualityOperator(); void TestHMSetConstructorsAndAssignments(); - void TestHMSetSize(); + void TestHMSetSize(); void TestHMSet1(); void TestHMSetEqualityOperator(); void TestHMSetEmplace(); @@ -103,7 +103,7 @@ protected: void TestValueInitialization(); void TestAssignmentClear(); void TestReleaseNodes(); - void TestAt(); + void TestAt(); void TestHMapInitializerList(); void TestHMMapInitializerList(); void TestHSetInitializerList(); @@ -407,20 +407,20 @@ void THashTest::TestHSetConstructorsAndAssignments() { UNIT_ASSERT(c4.contains(3)); } -void THashTest::TestHSetSize() { +void THashTest::TestHSetSize() { using container = THashSet<int>; - - container c; - c.insert(100); - c.insert(200); - - UNIT_ASSERT_VALUES_EQUAL(2, c.size()); - - c.insert(200); - - UNIT_ASSERT_VALUES_EQUAL(2, c.size()); -} - + + container c; + c.insert(100); + c.insert(200); + + UNIT_ASSERT_VALUES_EQUAL(2, c.size()); + + c.insert(200); + + UNIT_ASSERT_VALUES_EQUAL(2, c.size()); +} + void THashTest::TestHSet2() { THashSet<int, THash<int>, TEqualTo<int>> s; auto p = s.insert(42); @@ -492,20 +492,20 @@ void THashTest::TestHMSetConstructorsAndAssignments() { UNIT_ASSERT(c3.find(400) != c3.end()); } -void THashTest::TestHMSetSize() { +void THashTest::TestHMSetSize() { using container = THashMultiSet<int>; - - container c; - c.insert(100); - c.insert(200); - - UNIT_ASSERT_VALUES_EQUAL(2, c.size()); - - c.insert(200); - - UNIT_ASSERT_VALUES_EQUAL(3, c.size()); -} - + + container c; + c.insert(100); + c.insert(200); + + UNIT_ASSERT_VALUES_EQUAL(2, c.size()); + + c.insert(200); + + UNIT_ASSERT_VALUES_EQUAL(3, c.size()); +} + void THashTest::TestHMSet1() { hmset s; UNIT_ASSERT(s.count(star) == 0); @@ -1111,8 +1111,8 @@ void THashTest::TestReleaseNodes() { set2.insert(1); UNIT_ASSERT_VALUES_EQUAL(set2.size(), 1); } - -void THashTest::TestAt() { + +void THashTest::TestAt() { #define TEST_AT_THROWN_EXCEPTION(SRC_TYPE, DST_TYPE, KEY_TYPE, KEY, MESSAGE) \ { \ THashMap<SRC_TYPE, DST_TYPE> testMap; \ @@ -1125,8 +1125,8 @@ void THashTest::TestAt() { } catch (...) { \ UNIT_ASSERT_C(false, "THashMap::at(\"" << KEY << "\") should throw yexception"); \ } \ - } - + } + TEST_AT_THROWN_EXCEPTION(TString, TString, TString, "111", "111"); TEST_AT_THROWN_EXCEPTION(TString, TString, const TString, "111", "111"); TEST_AT_THROWN_EXCEPTION(TString, TString, TStringBuf, "111", "111"); @@ -1140,13 +1140,13 @@ void THashTest::TestAt() { TEST_AT_THROWN_EXCEPTION(int, int, unsigned int, 2, "2"); TEST_AT_THROWN_EXCEPTION(int, int, unsigned long, 131, "131"); TEST_AT_THROWN_EXCEPTION(int, int, unsigned long long, 1000000000000ll, "1000000000000"); - + char key[] = {11, 12, 0, 1, 2, 11, 0}; TEST_AT_THROWN_EXCEPTION(TString, TString, char*, key, "\\x0B\\x0C"); TEST_AT_THROWN_EXCEPTION(TString, TString, TStringBuf, TStringBuf(key, sizeof(key) - 1), "\\x0B\\x0C\\0\\1\\2\\x0B"); - -#undef TEST_AT_THROWN_EXCEPTION -} + +#undef TEST_AT_THROWN_EXCEPTION +} void THashTest::TestHMapInitializerList() { THashMap<TString, TString> h1 = {{"foo", "bar"}, {"bar", "baz"}, {"baz", "qux"}}; diff --git a/util/generic/is_in.h b/util/generic/is_in.h index 4f175ea5eb..a3277f173d 100644 --- a/util/generic/is_in.h +++ b/util/generic/is_in.h @@ -47,7 +47,7 @@ static inline bool IsIn(const C& c, const T& e) { return TIsInTraits<C, T, TIsAssocCont<C>::value>::IsIn(c, e); } -template <class T, class U> -static inline bool IsIn(std::initializer_list<T> l, const U& e) { +template <class T, class U> +static inline bool IsIn(std::initializer_list<T> l, const U& e) { return ::IsIn(l.begin(), l.end(), e); } diff --git a/util/generic/is_in_ut.cpp b/util/generic/is_in_ut.cpp index c668bce807..1306e427e7 100644 --- a/util/generic/is_in_ut.cpp +++ b/util/generic/is_in_ut.cpp @@ -70,7 +70,7 @@ Y_UNIT_TEST_SUITE(TIsIn) { UNIT_ASSERT(IsIn(b, 'f')); UNIT_ASSERT(!IsIn(b, 'z')); } - + Y_UNIT_TEST(IsInInitListTest) { const char* abc = "abc"; const char* def = "def"; @@ -88,22 +88,22 @@ Y_UNIT_TEST_SUITE(TIsIn) { UNIT_ASSERT(!IsIn({TStringBuf("abc"), TStringBuf("def")}, TStringBuf("ghi"))); UNIT_ASSERT(!IsIn({"abc", "def"}, TStringBuf("ghi"))); UNIT_ASSERT(!IsIn({"abc", "def"}, TString("ghi"))); - - const TStringBuf str = "abc////"; - + + const TStringBuf str = "abc////"; + UNIT_ASSERT(IsIn({"abc", "def"}, TStringBuf{str.data(), 3})); } Y_UNIT_TEST(ConfOfTest) { UNIT_ASSERT(IsIn({1, 2, 3}, 1)); UNIT_ASSERT(!IsIn({1, 2, 3}, 4)); - + const TString b = "b"; - + UNIT_ASSERT(!IsIn({"a", "b", "c"}, b.data())); // compares pointers by value. Whether it's good or not. UNIT_ASSERT(IsIn(TVector<TStringBuf>({"a", "b", "c"}), b.data())); UNIT_ASSERT(IsIn(TVector<TStringBuf>({"a", "b", "c"}), "b")); - } + } Y_UNIT_TEST(IsInArrayTest) { const TString array[] = {"a", "b", "d"}; diff --git a/util/generic/maybe.h b/util/generic/maybe.h index 34d21aebcd..f009fdb1e9 100644 --- a/util/generic/maybe.h +++ b/util/generic/maybe.h @@ -34,7 +34,7 @@ constexpr bool operator==(TNothing, TNothing) noexcept { return true; } -template <class T, class Policy /*= ::NMaybe::TPolicyUndefinedExcept*/> +template <class T, class Policy /*= ::NMaybe::TPolicyUndefinedExcept*/> class TMaybe: private TMaybeBase<T> { public: using TInPlace = NMaybe::TInPlace; diff --git a/util/generic/ptr_ut.cpp b/util/generic/ptr_ut.cpp index c2dcff23f6..b8429f7ca2 100644 --- a/util/generic/ptr_ut.cpp +++ b/util/generic/ptr_ut.cpp @@ -20,7 +20,7 @@ class TPointerTest: public TTestBase { UNIT_TEST(TestHolderPtrMoveAssignmentInheritance); UNIT_TEST(TestMakeHolder); UNIT_TEST(TestTrulePtr); - UNIT_TEST(TestAutoToHolder); + UNIT_TEST(TestAutoToHolder); UNIT_TEST(TestCopyPtr); UNIT_TEST(TestIntrPtr); UNIT_TEST(TestIntrusiveConvertion); @@ -72,7 +72,7 @@ private: void TestHolderPtrMoveAssignmentInheritance(); void TestMakeHolder(); void TestTrulePtr(); - void TestAutoToHolder(); + void TestAutoToHolder(); void TestCopyPtr(); void TestIntrPtr(); void TestIntrusiveConvertion(); @@ -136,7 +136,7 @@ void TPointerTest::TestSimpleIntrPtr() { a2 = a3; } - UNIT_ASSERT_VALUES_EQUAL(cnt, 0); + UNIT_ASSERT_VALUES_EQUAL(cnt, 0); } void TPointerTest::TestHolderPtr() { @@ -145,7 +145,7 @@ void TPointerTest::TestHolderPtr() { THolder<A> a2(a1.Release()); } - UNIT_ASSERT_VALUES_EQUAL(cnt, 0); + UNIT_ASSERT_VALUES_EQUAL(cnt, 0); } THolder<int> CreateInt(int value) { @@ -246,19 +246,19 @@ void TPointerTest::TestTrulePtr() { a1 = a2; } - UNIT_ASSERT_VALUES_EQUAL(cnt, 0); + UNIT_ASSERT_VALUES_EQUAL(cnt, 0); } void TPointerTest::TestAutoToHolder() { - { + { TAutoPtr<A> a1(MakeA()); - THolder<A> a2(a1); - - UNIT_ASSERT_EQUAL(a1.Get(), nullptr); - UNIT_ASSERT_VALUES_EQUAL(cnt, 1); - } - - UNIT_ASSERT_VALUES_EQUAL(cnt, 0); + THolder<A> a2(a1); + + UNIT_ASSERT_EQUAL(a1.Get(), nullptr); + UNIT_ASSERT_VALUES_EQUAL(cnt, 1); + } + + UNIT_ASSERT_VALUES_EQUAL(cnt, 0); { TAutoPtr<A> x(new A()); @@ -276,22 +276,22 @@ void TPointerTest::TestAutoToHolder() { } UNIT_ASSERT_VALUES_EQUAL(cnt, 0); -} - +} + void TPointerTest::TestCopyPtr() { TCopyPtr<A> a1(MakeA()); { TCopyPtr<A> a2(MakeA()); TCopyPtr<A> a3 = a2; - UNIT_ASSERT_VALUES_EQUAL(cnt, 3); + UNIT_ASSERT_VALUES_EQUAL(cnt, 3); a1 = a2; a2 = a3; } - UNIT_ASSERT_VALUES_EQUAL(cnt, 1); + UNIT_ASSERT_VALUES_EQUAL(cnt, 1); a1.Destroy(); - UNIT_ASSERT_VALUES_EQUAL(cnt, 0); + UNIT_ASSERT_VALUES_EQUAL(cnt, 0); } class TOp: public TSimpleRefCount<TOp>, public TNonCopyable { @@ -348,20 +348,20 @@ void TPointerTest::TestIntrPtr() { f2.push_back(p); Attach(&op3, &f2[1]); f1 = f2; - UNIT_ASSERT_VALUES_EQUAL(f1[0]->RefCount(), 2); - UNIT_ASSERT_VALUES_EQUAL(f1[1]->RefCount(), 3); + UNIT_ASSERT_VALUES_EQUAL(f1[0]->RefCount(), 2); + UNIT_ASSERT_VALUES_EQUAL(f1[1]->RefCount(), 3); UNIT_ASSERT_EQUAL(f1[1].Get(), op3.Op2.Get()); - UNIT_ASSERT_VALUES_EQUAL(op3.Op2->RefCount(), 3); - UNIT_ASSERT_VALUES_EQUAL(op3.Op2->Op->RefCount(), 2); - UNIT_ASSERT_VALUES_EQUAL(TOp::Cnt, 4); + UNIT_ASSERT_VALUES_EQUAL(op3.Op2->RefCount(), 3); + UNIT_ASSERT_VALUES_EQUAL(op3.Op2->Op->RefCount(), 2); + UNIT_ASSERT_VALUES_EQUAL(TOp::Cnt, 4); } p2 = p; } - UNIT_ASSERT_VALUES_EQUAL(op3.Op2->RefCount(), 1); - UNIT_ASSERT_VALUES_EQUAL(op3.Op2->Op->RefCount(), 3); - UNIT_ASSERT_VALUES_EQUAL(TOp::Cnt, 3); + UNIT_ASSERT_VALUES_EQUAL(op3.Op2->RefCount(), 1); + UNIT_ASSERT_VALUES_EQUAL(op3.Op2->Op->RefCount(), 3); + UNIT_ASSERT_VALUES_EQUAL(TOp::Cnt, 3); } - UNIT_ASSERT_VALUES_EQUAL(TOp::Cnt, 0); + UNIT_ASSERT_VALUES_EQUAL(TOp::Cnt, 0); } namespace NTestIntrusiveConvertion { @@ -424,7 +424,7 @@ void TPointerTest::TestMakeIntrusive() { UNIT_ASSERT_VALUES_EQUAL(1, p->RefCount()); UNIT_ASSERT_VALUES_EQUAL(1, TOp::Cnt); } - UNIT_ASSERT_VALUES_EQUAL(TOp::Cnt, 0); + UNIT_ASSERT_VALUES_EQUAL(TOp::Cnt, 0); } void TPointerTest::TestCopyOnWritePtr1() { diff --git a/util/generic/strbuf_ut.cpp b/util/generic/strbuf_ut.cpp index 69cde785af..28f6951b5f 100644 --- a/util/generic/strbuf_ut.cpp +++ b/util/generic/strbuf_ut.cpp @@ -197,10 +197,10 @@ Y_UNIT_TEST_SUITE(TStrBufTest) { UNIT_ASSERT_EQUAL(buf2.RNextTok("@@"), TStringBuf("b")); UNIT_ASSERT_EQUAL(buf2.RNextTok("@@"), TStringBuf("a")); UNIT_ASSERT_EQUAL(buf2, TStringBuf()); - - TStringBuf buf3("a@@b@@c"); + + TStringBuf buf3("a@@b@@c"); UNIT_ASSERT_EQUAL(buf3.RNextTok("@@@"), TStringBuf("a@@b@@c")); - UNIT_ASSERT_EQUAL(buf3, TStringBuf()); + UNIT_ASSERT_EQUAL(buf3, TStringBuf()); } Y_UNIT_TEST(TestReadLine) { diff --git a/util/generic/typetraits_ut.cpp b/util/generic/typetraits_ut.cpp index e7571c75ec..fe3c6059b4 100644 --- a/util/generic/typetraits_ut.cpp +++ b/util/generic/typetraits_ut.cpp @@ -227,9 +227,9 @@ Y_UNIT_TEST_SUITE(TTypeTraitsTest) { UNIT_ASSERT(!std::is_standard_layout<TNonStdLayoutClass4>::value); } - template <class T> + template <class T> using TTrySum = decltype(std::declval<T>() + std::declval<T>()); - + Y_UNIT_TEST(TestIsTriviallyCopyable) { struct TPod { int value; diff --git a/util/generic/utility.h b/util/generic/utility.h index 43b98eeafc..96061fe45c 100644 --- a/util/generic/utility.h +++ b/util/generic/utility.h @@ -5,22 +5,22 @@ #include <cstring> template <class T> -static constexpr const T& Min(const T& l, const T& r) { +static constexpr const T& Min(const T& l, const T& r) { return r < l ? r : l; } template <typename T, typename... Args> -static constexpr const T& Min(const T& a, const T& b, const Args&... args) { +static constexpr const T& Min(const T& a, const T& b, const Args&... args) { return Min(a, Min(b, args...)); } template <class T> -static constexpr const T& Max(const T& l, const T& r) { +static constexpr const T& Max(const T& l, const T& r) { return l < r ? r : l; } template <typename T, typename... Args> -static constexpr const T& Max(const T& a, const T& b, const Args&... args) { +static constexpr const T& Max(const T& a, const T& b, const Args&... args) { return Max(a, Max(b, args...)); } diff --git a/util/generic/ylimits.h b/util/generic/ylimits.h index fe42b4dfc0..46c6cd5ed5 100644 --- a/util/generic/ylimits.h +++ b/util/generic/ylimits.h @@ -19,14 +19,14 @@ static constexpr T Min() noexcept { namespace NPrivate { struct TMax { template <class T> - constexpr operator T() const { + constexpr operator T() const { return Max<T>(); } }; struct TMin { template <class T> - constexpr operator T() const { + constexpr operator T() const { return Min<T>(); } }; diff --git a/util/generic/ymath.h b/util/generic/ymath.h index 9ff9ae2abe..5998207f9f 100644 --- a/util/generic/ymath.h +++ b/util/generic/ymath.h @@ -18,7 +18,7 @@ constexpr double M_LN2_INV = M_LOG2E; // 1 / ln(2) == log2(e) * \returns Absolute value of the provided argument. */ template <class T> -constexpr T Abs(T value) { +constexpr T Abs(T value) { return std::abs(value); } diff --git a/util/string/cast.h b/util/string/cast.h index 90e925c194..48d4c5c5cd 100644 --- a/util/string/cast.h +++ b/util/string/cast.h @@ -119,9 +119,9 @@ inline const TUtf16String& ToWtring(TUtf16String& w) { return w; } -struct TFromStringException: public TBadCastException { -}; - +struct TFromStringException: public TBadCastException { +}; + /* * specialized for: * bool diff --git a/util/string/cast.pxd b/util/string/cast.pxd index dc23619e1e..b0fcc8123f 100644 --- a/util/string/cast.pxd +++ b/util/string/cast.pxd @@ -1,8 +1,8 @@ -from util.generic.string cimport TString - +from util.generic.string cimport TString + from libcpp cimport bool as bool_t -cdef extern from "<util/string/cast.h>" nogil: +cdef extern from "<util/string/cast.h>" nogil: T FromString[T](const TString&) except + bool_t TryFromString[T](const TString&, T&) except + TString ToString[T](const T&) except + diff --git a/util/string/cast_ut.pyx b/util/string/cast_ut.pyx index 88e86ef961..16bc90e5f5 100644 --- a/util/string/cast_ut.pyx +++ b/util/string/cast_ut.pyx @@ -1,13 +1,13 @@ # cython: c_string_type=str, c_string_encoding=utf8 from util.string.cast cimport FromString, ToString - -import unittest - + +import unittest + class TestFromString(unittest.TestCase): def test_from_int(self): self.assertEquals(FromString[int]("42"), 42) -class TestToString(unittest.TestCase): - def test_from_int(self): - self.assertEquals(ToString(42), "42") +class TestToString(unittest.TestCase): + def test_from_int(self): + self.assertEquals(ToString(42), "42") diff --git a/util/string/split.h b/util/string/split.h index bc46d9e64c..81607e0961 100644 --- a/util/string/split.h +++ b/util/string/split.h @@ -1,10 +1,10 @@ #pragma once #include "strspn.h" -#include "cast.h" +#include "cast.h" #include <util/generic/algorithm.h> -#include <util/generic/fwd.h> +#include <util/generic/fwd.h> #include <util/generic/iterator.h> #include <util/generic/iterator_range.h> #include <util/generic/store_policy.h> @@ -431,16 +431,16 @@ void GetNext(TStringBuf& s, D delim, P& param) { param = FromString<P>(next); } -template <class P, class D> -void GetNext(TStringBuf& s, D delim, TMaybe<P>& param) { - TStringBuf next = s.NextTok(delim); - if (next.IsInited()) { - param = FromString<P>(next); - } else { - param.Clear(); - } -} - +template <class P, class D> +void GetNext(TStringBuf& s, D delim, TMaybe<P>& param) { + TStringBuf next = s.NextTok(delim); + if (next.IsInited()) { + param = FromString<P>(next); + } else { + param.Clear(); + } +} + // example: // Split(TStringBuf("Sherlock,2014,36.6"), ',', name, year, temperature); template <class D, class P1, class P2> diff --git a/util/string/split_ut.cpp b/util/string/split_ut.cpp index 43e59f2d75..89c28258e5 100644 --- a/util/string/split_ut.cpp +++ b/util/string/split_ut.cpp @@ -5,7 +5,7 @@ #include <util/stream/output.h> #include <util/charset/wide.h> #include <util/datetime/cputimer.h> -#include <util/generic/maybe.h> +#include <util/generic/maybe.h> #include <string> #include <string_view> @@ -258,25 +258,25 @@ Y_UNIT_TEST_SUITE(SplitStringTest) { double num2 = 0; TStringBuf strBuf; Split(data, ' ', str, num1, num2, strBuf); - UNIT_ASSERT_VALUES_EQUAL(str, "abc"); - UNIT_ASSERT_VALUES_EQUAL(num1, 22); - UNIT_ASSERT_VALUES_EQUAL(num2, 33.5); - UNIT_ASSERT_VALUES_EQUAL(strBuf, "xyz"); + UNIT_ASSERT_VALUES_EQUAL(str, "abc"); + UNIT_ASSERT_VALUES_EQUAL(num1, 22); + UNIT_ASSERT_VALUES_EQUAL(num2, 33.5); + UNIT_ASSERT_VALUES_EQUAL(strBuf, "xyz"); } Y_UNIT_TEST(ConvenientSplitTestWithMaybe) { TString data("abc 42"); TString str; - TMaybe<double> num2 = 1; - TMaybe<double> maybe = 1; - - Split(data, ' ', str, num2, maybe); - - UNIT_ASSERT_VALUES_EQUAL(str, "abc"); - UNIT_ASSERT_VALUES_EQUAL(*num2, 42); - UNIT_ASSERT(!maybe); - } - + TMaybe<double> num2 = 1; + TMaybe<double> maybe = 1; + + Split(data, ' ', str, num2, maybe); + + UNIT_ASSERT_VALUES_EQUAL(str, "abc"); + UNIT_ASSERT_VALUES_EQUAL(*num2, 42); + UNIT_ASSERT(!maybe); + } + Y_UNIT_TEST(ConvenientSplitTestExceptions) { TString data("abc 22 33"); TString s1, s2, s3, s4; @@ -285,22 +285,22 @@ Y_UNIT_TEST_SUITE(SplitStringTest) { UNIT_ASSERT_NO_EXCEPTION(Split(data, ' ', s1, s2, s3)); UNIT_ASSERT_EXCEPTION(Split(data, ' ', s1, s2, s3, s4), yexception); } - + Y_UNIT_TEST(ConvenientSplitTestMaybeExceptions) { TString data("abc 22 33"); TString s1, s2; TMaybe<TString> m1, m2; - - UNIT_ASSERT_EXCEPTION(Split(data, ' ', s1, m1), yexception); - UNIT_ASSERT_EXCEPTION(Split(data, ' ', m1, m2), yexception); - UNIT_ASSERT_NO_EXCEPTION(Split(data, ' ', s1, s2, m1)); - - UNIT_ASSERT_NO_EXCEPTION(Split(data, ' ', s1, s2, m1, m2)); - UNIT_ASSERT_EXCEPTION(Split(data, ' ', m1, m2, s1, s2), yexception); - - UNIT_ASSERT_NO_EXCEPTION(Split(data, ' ', s1, s2, m1, m2, m1, m1, m1, m1)); - UNIT_ASSERT_EXCEPTION(Split(data, ' ', s1, s2, m1, m2, m1, m1, m1, m1, s1), yexception); - } + + UNIT_ASSERT_EXCEPTION(Split(data, ' ', s1, m1), yexception); + UNIT_ASSERT_EXCEPTION(Split(data, ' ', m1, m2), yexception); + UNIT_ASSERT_NO_EXCEPTION(Split(data, ' ', s1, s2, m1)); + + UNIT_ASSERT_NO_EXCEPTION(Split(data, ' ', s1, s2, m1, m2)); + UNIT_ASSERT_EXCEPTION(Split(data, ' ', m1, m2, s1, s2), yexception); + + UNIT_ASSERT_NO_EXCEPTION(Split(data, ' ', s1, s2, m1, m2, m1, m1, m1, m1)); + UNIT_ASSERT_EXCEPTION(Split(data, ' ', s1, s2, m1, m2, m1, m1, m1, m1, s1), yexception); + } } template <typename I, typename C> diff --git a/util/tests/cython/test_generic.py b/util/tests/cython/test_generic.py index a0d61339cc..0d257a4496 100644 --- a/util/tests/cython/test_generic.py +++ b/util/tests/cython/test_generic.py @@ -25,5 +25,5 @@ __all__ = [ 'TestStroka', 'TestVector', 'TestFromString', - 'TestToString', + 'TestToString', ] diff --git a/util/tests/cython/ya.make b/util/tests/cython/ya.make index b928c19026..c21bf92b5f 100644 --- a/util/tests/cython/ya.make +++ b/util/tests/cython/ya.make @@ -22,7 +22,7 @@ PY_SRCS( generic/hash_ut.pyx memory/blob_ut.pyx stream/str_ut.pyx - string/cast_ut.pyx + string/cast_ut.pyx system/types_ut.pyx digest/multi_ut.pyx ) diff --git a/util/ysaveload.h b/util/ysaveload.h index 02efb4049b..17ed83dd32 100644 --- a/util/ysaveload.h +++ b/util/ysaveload.h @@ -685,12 +685,12 @@ private: template <class T> static inline void SaveLoad(IOutputStream* out, const T& t) { - Save(out, t); + Save(out, t); } template <class T> static inline void SaveLoad(IInputStream* in, T& t) { - Load(in, t); + Load(in, t); } template <class S, class... Ts> |