diff options
author | antoshkka <antoshkka@yandex-team.ru> | 2022-02-10 16:50:14 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:14 +0300 |
commit | 90277959ac43a22ec25e7b78b1a2b4f610530d51 (patch) | |
tree | 83f00e4f33f9a449c5f5a871ad9330211c595f5c | |
parent | 9a6b05f93140131e64aa069bad7092698970130d (diff) | |
download | ydb-90277959ac43a22ec25e7b78b1a2b4f610530d51.tar.gz |
Restoring authorship annotation for <antoshkka@yandex-team.ru>. Commit 1 of 2.
-rw-r--r-- | library/cpp/digest/md5/md5_ut.cpp | 2 | ||||
-rw-r--r-- | library/cpp/json/writer/json_value.cpp | 34 | ||||
-rw-r--r-- | library/cpp/json/writer/json_value.h | 22 | ||||
-rw-r--r-- | library/cpp/json/writer/json_value_ut.cpp | 26 | ||||
-rw-r--r-- | util/generic/algorithm_ut.cpp | 6 | ||||
-rw-r--r-- | util/generic/cast.h | 44 | ||||
-rw-r--r-- | util/generic/cast_ut.cpp | 50 | ||||
-rw-r--r-- | util/generic/strbuf_ut.cpp | 22 | ||||
-rw-r--r-- | ydb/library/yql/ast/yql_ast_ut.cpp | 2 |
9 files changed, 104 insertions, 104 deletions
diff --git a/library/cpp/digest/md5/md5_ut.cpp b/library/cpp/digest/md5/md5_ut.cpp index 1c3e4ad0a9..99841c43a8 100644 --- a/library/cpp/digest/md5/md5_ut.cpp +++ b/library/cpp/digest/md5/md5_ut.cpp @@ -50,7 +50,7 @@ Y_UNIT_TEST_SUITE(TMD5Test) { } Y_UNIT_TEST(TestIsMD5) { - UNIT_ASSERT_EQUAL(false, MD5::IsMD5(TStringBuf())); + UNIT_ASSERT_EQUAL(false, MD5::IsMD5(TStringBuf())); UNIT_ASSERT_EQUAL(false, MD5::IsMD5(TStringBuf("4136ebb0e4c45d21e2b09294c75cfa0"))); // length 31 UNIT_ASSERT_EQUAL(false, MD5::IsMD5(TStringBuf("4136ebb0e4c45d21e2b09294c75cfa000"))); // length 33 UNIT_ASSERT_EQUAL(false, MD5::IsMD5(TStringBuf("4136ebb0e4c45d21e2b09294c75cfa0g"))); // wrong character 'g' diff --git a/library/cpp/json/writer/json_value.cpp b/library/cpp/json/writer/json_value.cpp index c61e8d1dc4..2a45c7d7e8 100644 --- a/library/cpp/json/writer/json_value.cpp +++ b/library/cpp/json/writer/json_value.cpp @@ -118,7 +118,7 @@ namespace NJson { return *this; TJsonValue tmp(std::move(val)); tmp.Swap(*this); - return *this; + return *this; } TJsonValue::TJsonValue(const bool value) noexcept { @@ -165,7 +165,7 @@ namespace NJson { SetType(JSON_STRING); Value.String = std::move(value); } - + TJsonValue::TJsonValue(const TStringBuf value) { SetType(JSON_STRING); Value.String = value; @@ -222,7 +222,7 @@ namespace NJson { SetType(JSON_MAP); return (*Value.Map)[key] = value; } - + TJsonValue& TJsonValue::InsertValue(const TStringBuf key, const TJsonValue& value) { SetType(JSON_MAP); return (*Value.Map)[key] = value; @@ -242,17 +242,17 @@ namespace NJson { SetType(JSON_MAP); return (*Value.Map)[key] = std::move(value); } - + TJsonValue& TJsonValue::InsertValue(const char* key, TJsonValue&& value) { SetType(JSON_MAP); return (*Value.Map)[key] = std::move(value); } - + TJsonValue& TJsonValue::Back() { BackChecks(); return Value.Array->back(); } - + const TJsonValue& TJsonValue::Back() const { BackChecks(); return Value.Array->back(); @@ -277,7 +277,7 @@ namespace NJson { Value.Map->erase(it); } } - + void TJsonValue::EraseValue(const size_t index) { if (IsArray()) { if (index >= Value.Array->size()) { @@ -821,20 +821,20 @@ namespace NJson { TPtr* CreateOrNullptr(TPtr* p, T key, std::true_type /*create*/) { return &(*p)[key]; } - + template <class TPtr, class T> TPtr* CreateOrNullptr(const TPtr* p, T key, std::false_type /*create*/) noexcept { const TPtr* const next = &(*p)[key]; return next->IsDefined() ? const_cast<TPtr*>(next) : nullptr; } - + template <bool Create, class TJsonPtr> TJsonPtr GetValuePtrByPath(TJsonPtr currentJson, TStringBuf path, char delimiter) noexcept(!Create) { static_assert( !(Create && std::is_const<std::remove_pointer_t<TJsonPtr>>::value), "TJsonPtr must be a `TJsonValue*` if `Create` is true"); constexpr std::integral_constant<bool, Create> create_tag{}; - + while (!path.empty()) { size_t index = 0; const TStringBuf step = path.NextTok(delimiter); @@ -847,12 +847,12 @@ namespace NJson { if (!currentJson) { return nullptr; } - } - + } + return currentJson; } } // anonymous namespace - + bool TJsonValue::GetValueByPath(const TStringBuf path, TJsonValue& result, char delimiter) const { const TJsonValue* const ptr = GetValuePtrByPath<false>(this, path, delimiter); if (ptr) { @@ -887,7 +887,7 @@ namespace NJson { TJsonValue* TJsonValue::GetValueByPath(const TStringBuf key, char delim) noexcept { return GetValuePtrByPath<false>(this, key, delim); } - + void TJsonValue::DoScan(const TString& path, TJsonValue* parent, IScanCallback& callback) { if (!callback.Do(path, parent, *this)) { return; @@ -968,8 +968,8 @@ namespace NJson { Y_ASSERT(false && "Unknown type."); return false; } - } - + } + void TJsonValue::SwapWithUndefined(TJsonValue& output) noexcept { if (Type == JSON_STRING) { static_assert(std::is_nothrow_move_constructible<TString>::value, "noexcept violation! Add some try {} catch (...) logic"); @@ -982,7 +982,7 @@ namespace NJson { output.Type = Type; Type = JSON_UNDEFINED; } - + void TJsonValue::Swap(TJsonValue& rhs) noexcept { TJsonValue tmp(std::move(*this)); rhs.SwapWithUndefined(*this); diff --git a/library/cpp/json/writer/json_value.h b/library/cpp/json/writer/json_value.h index 3f0f50bc4c..e880fdae51 100644 --- a/library/cpp/json/writer/json_value.h +++ b/library/cpp/json/writer/json_value.h @@ -152,7 +152,7 @@ namespace NJson { bool GetValuePointer(size_t index, const TJsonValue** value) const noexcept; bool GetValuePointer(TStringBuf key, const TJsonValue** value) const noexcept; bool GetValuePointer(TStringBuf key, TJsonValue** value) noexcept; - + // Checking for defined non-null value bool IsDefined() const noexcept { return Type != JSON_UNDEFINED && Type != JSON_NULL; @@ -223,26 +223,26 @@ namespace NJson { inline bool GetBoolean(const TJsonValue& jv, size_t index, bool* value) noexcept { return jv[index].GetBoolean(value); } - + inline bool GetInteger(const TJsonValue& jv, size_t index, long long* value) noexcept { return jv[index].GetInteger(value); } - + inline bool GetUInteger(const TJsonValue& jv, size_t index, unsigned long long* value) noexcept { return jv[index].GetUInteger(value); } - + inline bool GetDouble(const TJsonValue& jv, size_t index, double* value) noexcept { return jv[index].GetDouble(value); } - + inline bool GetString(const TJsonValue& jv, size_t index, TString* value) { return jv[index].GetString(value); } - + bool GetMapPointer(const TJsonValue& jv, size_t index, const TJsonValue::TMapType** value); bool GetArrayPointer(const TJsonValue& jv, size_t index, const TJsonValue::TArray** value); - + inline bool GetBoolean(const TJsonValue& jv, TStringBuf key, bool* value) noexcept { return jv[key].GetBoolean(value); } @@ -254,15 +254,15 @@ namespace NJson { inline bool GetUInteger(const TJsonValue& jv, TStringBuf key, unsigned long long* value) noexcept { return jv[key].GetUInteger(value); } - + inline bool GetDouble(const TJsonValue& jv, TStringBuf key, double* value) noexcept { return jv[key].GetDouble(value); } - + inline bool GetString(const TJsonValue& jv, TStringBuf key, TString* value) { return jv[key].GetString(value); } - + bool GetMapPointer(const TJsonValue& jv, const TStringBuf key, const TJsonValue::TMapType** value); bool GetArrayPointer(const TJsonValue& jv, const TStringBuf key, const TJsonValue::TArray** value); @@ -291,4 +291,4 @@ namespace NJson { GetArraySafe() = TJsonValue::TArray(list); } }; -} +} diff --git a/library/cpp/json/writer/json_value_ut.cpp b/library/cpp/json/writer/json_value_ut.cpp index dc7f6affdf..c41a227cc9 100644 --- a/library/cpp/json/writer/json_value_ut.cpp +++ b/library/cpp/json/writer/json_value_ut.cpp @@ -608,21 +608,21 @@ Y_UNIT_TEST_SUITE(TJsonValueTest) { } Y_UNIT_TEST(MoveSubpartToSelf) { - TJsonValue json; - json[0] = "testing 0"; - json[1] = "testing 1"; - json[2] = "testing 2"; - json = std::move(json[1]); - UNIT_ASSERT_VALUES_EQUAL(json.GetString(), "testing 1"); - - const char* longTestString = - "Testing TJsonValue& operator=(TJsonValue&&) subpart self moving " + TJsonValue json; + json[0] = "testing 0"; + json[1] = "testing 1"; + json[2] = "testing 2"; + json = std::move(json[1]); + UNIT_ASSERT_VALUES_EQUAL(json.GetString(), "testing 1"); + + const char* longTestString = + "Testing TJsonValue& operator=(TJsonValue&&) subpart self moving " "after TJsonValue was constrcuted from TString&&."; - + json["hello"] = TString{longTestString}; - json = std::move(json["hello"]); - UNIT_ASSERT_VALUES_EQUAL(json.GetString(), longTestString); - } + json = std::move(json["hello"]); + UNIT_ASSERT_VALUES_EQUAL(json.GetString(), longTestString); + } Y_UNIT_TEST(TJsonArrayMapConstructor) { TJsonMap emptyMap; diff --git a/util/generic/algorithm_ut.cpp b/util/generic/algorithm_ut.cpp index 8d732fcc0c..f1a2786340 100644 --- a/util/generic/algorithm_ut.cpp +++ b/util/generic/algorithm_ut.cpp @@ -12,7 +12,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { UNIT_ASSERT(1 == AnyOf(TStringBuf("01"), isOne)); UNIT_ASSERT(1 == AnyOf(TStringBuf("10"), isOne)); UNIT_ASSERT(1 == AnyOf(TStringBuf("11"), isOne)); - UNIT_ASSERT(0 == AnyOf(TStringBuf(), isOne)); + UNIT_ASSERT(0 == AnyOf(TStringBuf(), isOne)); const char array00[]{'0', '0'}; UNIT_ASSERT(0 == AnyOf(array00, isOne)); @@ -25,7 +25,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { UNIT_ASSERT(0 == AllOf(TStringBuf("01"), isOne)); UNIT_ASSERT(0 == AllOf(TStringBuf("10"), isOne)); UNIT_ASSERT(1 == AllOf(TStringBuf("11"), isOne)); - UNIT_ASSERT(1 == AllOf(TStringBuf(), isOne)); + UNIT_ASSERT(1 == AllOf(TStringBuf(), isOne)); const char array01[]{'0', '1'}; UNIT_ASSERT(0 == AllOf(array01, isOne)); @@ -37,7 +37,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) { UNIT_ASSERT(3 == CountIf(TStringBuf("____1________1____1_______"), isOne)); UNIT_ASSERT(5 == CountIf(TStringBuf("1____1________1____1_______1"), isOne)); UNIT_ASSERT(0 == CountIf(TStringBuf("___________"), isOne)); - UNIT_ASSERT(0 == CountIf(TStringBuf(), isOne)); + UNIT_ASSERT(0 == CountIf(TStringBuf(), isOne)); UNIT_ASSERT(1 == CountIf(TStringBuf("1"), isOne)); const char array[] = "____1________1____1_______"; diff --git a/util/generic/cast.h b/util/generic/cast.h index 0d4a41f385..4c9590e7b8 100644 --- a/util/generic/cast.h +++ b/util/generic/cast.h @@ -88,37 +88,37 @@ constexpr bool IsNegative(const TType value) noexcept { } namespace NPrivate { - template <class T> - using TUnderlyingTypeOrSelf = typename std::conditional< - std::is_enum<T>::value, - std::underlying_type<T>, // Lazy evaluatuion: do not call ::type here, because underlying_type<T> is undefined if T is not an enum. - std::enable_if<true, T> // Wrapping T in a class, that has member ::type typedef. + template <class T> + using TUnderlyingTypeOrSelf = typename std::conditional< + std::is_enum<T>::value, + std::underlying_type<T>, // Lazy evaluatuion: do not call ::type here, because underlying_type<T> is undefined if T is not an enum. + std::enable_if<true, T> // Wrapping T in a class, that has member ::type typedef. >::type::type; // Left ::type is for std::conditional, right ::type is for underlying_type/enable_if - - template <class TSmall, class TLarge> + + template <class TSmall, class TLarge> struct TSafelyConvertible { - using TSmallInt = TUnderlyingTypeOrSelf<TSmall>; - using TLargeInt = TUnderlyingTypeOrSelf<TLarge>; - - static constexpr bool Result = std::is_integral<TSmallInt>::value && std::is_integral<TLargeInt>::value && - ((std::is_signed<TSmallInt>::value == std::is_signed<TLargeInt>::value && sizeof(TSmallInt) >= sizeof(TLargeInt)) || - (std::is_signed<TSmallInt>::value && sizeof(TSmallInt) > sizeof(TLargeInt))); + using TSmallInt = TUnderlyingTypeOrSelf<TSmall>; + using TLargeInt = TUnderlyingTypeOrSelf<TLarge>; + + static constexpr bool Result = std::is_integral<TSmallInt>::value && std::is_integral<TLargeInt>::value && + ((std::is_signed<TSmallInt>::value == std::is_signed<TLargeInt>::value && sizeof(TSmallInt) >= sizeof(TLargeInt)) || + (std::is_signed<TSmallInt>::value && sizeof(TSmallInt) > sizeof(TLargeInt))); }; } template <class TSmallInt, class TLargeInt> constexpr std::enable_if_t<::NPrivate::TSafelyConvertible<TSmallInt, TLargeInt>::Result, TSmallInt> SafeIntegerCast(TLargeInt largeInt) noexcept { - return static_cast<TSmallInt>(largeInt); + return static_cast<TSmallInt>(largeInt); } -template <class TSmall, class TLarge> +template <class TSmall, class TLarge> inline std::enable_if_t<!::NPrivate::TSafelyConvertible<TSmall, TLarge>::Result, TSmall> SafeIntegerCast(TLarge largeInt) { - using TSmallInt = ::NPrivate::TUnderlyingTypeOrSelf<TSmall>; - using TLargeInt = ::NPrivate::TUnderlyingTypeOrSelf<TLarge>; - + using TSmallInt = ::NPrivate::TUnderlyingTypeOrSelf<TSmall>; + using TLargeInt = ::NPrivate::TUnderlyingTypeOrSelf<TLarge>; + if (std::is_unsigned<TSmallInt>::value && std::is_signed<TLargeInt>::value) { if (IsNegative(largeInt)) { - ythrow TBadCastException() << "Conversion '" << TypeName<TLarge>() << '{' << TLargeInt(largeInt) << "}' to '" + ythrow TBadCastException() << "Conversion '" << TypeName<TLarge>() << '{' << TLargeInt(largeInt) << "}' to '" << TypeName<TSmallInt>() << "', negative value converted to unsigned"; } @@ -128,18 +128,18 @@ inline std::enable_if_t<!::NPrivate::TSafelyConvertible<TSmall, TLarge>::Result, if (std::is_signed<TSmallInt>::value && std::is_unsigned<TLargeInt>::value) { if (IsNegative(smallInt)) { - ythrow TBadCastException() << "Conversion '" << TypeName<TLarge>() << '{' << TLargeInt(largeInt) << "}' to '" + ythrow TBadCastException() << "Conversion '" << TypeName<TLarge>() << '{' << TLargeInt(largeInt) << "}' to '" << TypeName<TSmallInt>() << "', positive value converted to negative"; } } if (TLargeInt(smallInt) != largeInt) { - ythrow TBadCastException() << "Conversion '" << TypeName<TLarge>() << '{' << TLargeInt(largeInt) << "}' to '" + ythrow TBadCastException() << "Conversion '" << TypeName<TLarge>() << '{' << TLargeInt(largeInt) << "}' to '" << TypeName<TSmallInt>() << "', loss of data"; } - return static_cast<TSmall>(smallInt); + return static_cast<TSmall>(smallInt); } template <class TSmallInt, class TLargeInt> diff --git a/util/generic/cast_ut.cpp b/util/generic/cast_ut.cpp index 718a8de79d..9892029eb1 100644 --- a/util/generic/cast_ut.cpp +++ b/util/generic/cast_ut.cpp @@ -6,7 +6,7 @@ class TGenericCastsTest: public TTestBase { UNIT_TEST_SUITE(TGenericCastsTest); UNIT_TEST(TestVerifyDynamicCast) UNIT_TEST(TestIntegralCast) - UNIT_TEST(TestEnumCast) + UNIT_TEST(TestEnumCast) UNIT_TEST(TestToUnderlying) UNIT_TEST(TestBitCast) UNIT_TEST_SUITE_END(); @@ -29,32 +29,32 @@ private: UNIT_ASSERT_EXCEPTION(SafeIntegerCast<ui16>(static_cast<i32>(Max<ui16>() + 10)), TBadCastException); UNIT_ASSERT_EXCEPTION(SafeIntegerCast<ui16>(static_cast<ui32>(Max<ui16>() + 10)), TBadCastException); } - - inline void TestEnumCast() { - enum A { - AM1 = -1 - }; - + + inline void TestEnumCast() { + enum A { + AM1 = -1 + }; + enum B: int { - BM1 = -1 - }; - + BM1 = -1 + }; + enum class C: unsigned short { - CM1 = 1 - }; - - UNIT_ASSERT_EXCEPTION(SafeIntegerCast<unsigned int>(AM1), TBadCastException); - UNIT_ASSERT_EXCEPTION(SafeIntegerCast<unsigned int>(BM1), TBadCastException); - UNIT_ASSERT_EXCEPTION(SafeIntegerCast<C>(AM1), TBadCastException); - UNIT_ASSERT_EXCEPTION(static_cast<int>(SafeIntegerCast<C>(BM1)), TBadCastException); - UNIT_ASSERT(SafeIntegerCast<A>(BM1) == AM1); - UNIT_ASSERT(SafeIntegerCast<B>(AM1) == BM1); - UNIT_ASSERT(SafeIntegerCast<A>(C::CM1) == 1); - UNIT_ASSERT(SafeIntegerCast<B>(C::CM1) == 1); - UNIT_ASSERT(SafeIntegerCast<A>(-1) == AM1); - UNIT_ASSERT(SafeIntegerCast<B>(-1) == BM1); - UNIT_ASSERT(SafeIntegerCast<C>(1) == C::CM1); - } + CM1 = 1 + }; + + UNIT_ASSERT_EXCEPTION(SafeIntegerCast<unsigned int>(AM1), TBadCastException); + UNIT_ASSERT_EXCEPTION(SafeIntegerCast<unsigned int>(BM1), TBadCastException); + UNIT_ASSERT_EXCEPTION(SafeIntegerCast<C>(AM1), TBadCastException); + UNIT_ASSERT_EXCEPTION(static_cast<int>(SafeIntegerCast<C>(BM1)), TBadCastException); + UNIT_ASSERT(SafeIntegerCast<A>(BM1) == AM1); + UNIT_ASSERT(SafeIntegerCast<B>(AM1) == BM1); + UNIT_ASSERT(SafeIntegerCast<A>(C::CM1) == 1); + UNIT_ASSERT(SafeIntegerCast<B>(C::CM1) == 1); + UNIT_ASSERT(SafeIntegerCast<A>(-1) == AM1); + UNIT_ASSERT(SafeIntegerCast<B>(-1) == BM1); + UNIT_ASSERT(SafeIntegerCast<C>(1) == C::CM1); + } void TestToUnderlying() { enum A { diff --git a/util/generic/strbuf_ut.cpp b/util/generic/strbuf_ut.cpp index 69cde785af..cc392ea0f0 100644 --- a/util/generic/strbuf_ut.cpp +++ b/util/generic/strbuf_ut.cpp @@ -319,19 +319,19 @@ Y_UNIT_TEST_SUITE(TStrBufTest) { s.SplitAt(pos, l, r); UNIT_ASSERT(l == "abcabc" && r == ""); // modified } - - template <class T> - void PassByConstReference(const T& val) { - // In https://st.yandex-team.ru/IGNIETFERRO-294 was assumed that `const char[]` types are compile time strings + + template <class T> + void PassByConstReference(const T& val) { + // In https://st.yandex-team.ru/IGNIETFERRO-294 was assumed that `const char[]` types are compile time strings // and that CharTraits::Length may not be called for them. Unfortunately that is not true, `char[]` types - // are easily converted to `const char[]` if they are passed to a function accepting `const T&`. - UNIT_ASSERT(TStringBuf(val).size() == 5); - } - + // are easily converted to `const char[]` if they are passed to a function accepting `const T&`. + UNIT_ASSERT(TStringBuf(val).size() == 5); + } + Y_UNIT_TEST(TestPassingArraysByConstReference) { - char data[] = "Hello\0word"; - PassByConstReference(data); - } + char data[] = "Hello\0word"; + PassByConstReference(data); + } Y_UNIT_TEST(TestTruncate) { TStringBuf s = "123"; diff --git a/ydb/library/yql/ast/yql_ast_ut.cpp b/ydb/library/yql/ast/yql_ast_ut.cpp index 23e140653d..8226f398df 100644 --- a/ydb/library/yql/ast/yql_ast_ut.cpp +++ b/ydb/library/yql/ast/yql_ast_ut.cpp @@ -135,7 +135,7 @@ Y_UNIT_TEST_SUITE(TParseYqlAst) { } Y_UNIT_TEST(GoodArbitraryAtom) { - TestGoodArbitraryAtom("(\"\")", TStringBuf()); + TestGoodArbitraryAtom("(\"\")", TStringBuf()); TestGoodArbitraryAtom("(\" 1 a 3 b \")", TStringBuf(" 1 a 3 b ")); ui8 expectedHex[] = { 0xab, 'c', 'd', 0x00 }; |