diff options
author | Alexey Salmin <alexey.salmin@gmail.com> | 2022-02-10 16:49:37 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:37 +0300 |
commit | 3c5b1607b38f637d2f3313791ed25c2e080d2647 (patch) | |
tree | 99be7b96e7c66612fbca94331100ef3b5fedcb88 /library/cpp | |
parent | de89752358147d7b25ef59a85b431bb564068a49 (diff) | |
download | ydb-3c5b1607b38f637d2f3313791ed25c2e080d2647.tar.gz |
Restoring authorship annotation for Alexey Salmin <alexey.salmin@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'library/cpp')
39 files changed, 743 insertions, 743 deletions
diff --git a/library/cpp/balloc/balloc.cpp b/library/cpp/balloc/balloc.cpp index fab489db4c..1635a2fab8 100644 --- a/library/cpp/balloc/balloc.cpp +++ b/library/cpp/balloc/balloc.cpp @@ -76,7 +76,7 @@ namespace NBalloc { static void Y_FORCE_INLINE Enable() { tls.Mode = ToBeEnabled; } - + static bool Y_FORCE_INLINE IsDisabled() { return tls.Mode == Disabled; } @@ -273,11 +273,11 @@ extern "C" void* realloc(void* oldPtr, size_t newSize) { } #endif -// Only for testing purposes. Never use in production. +// Only for testing purposes. Never use in production. extern "C" bool IsOwnedByBalloc(void* ptr) { - return NBalloc::IsOwnedByBalloc(ptr); -} - + return NBalloc::IsOwnedByBalloc(ptr); +} + extern "C" bool BallocDisabled() { return NBalloc::IsDisabled(); } @@ -286,10 +286,10 @@ extern "C" void DisableBalloc() { NBalloc::Disable(); } -extern "C" void EnableBalloc() { - NBalloc::Enable(); -} - +extern "C" void EnableBalloc() { + NBalloc::Enable(); +} + extern "C" void* memalign(size_t alignment, size_t size) { void* ptr; int res = posix_memalign(&ptr, alignment, size); diff --git a/library/cpp/balloc/malloc-info.cpp b/library/cpp/balloc/malloc-info.cpp index 604b1fb145..2fcebf7f81 100644 --- a/library/cpp/balloc/malloc-info.cpp +++ b/library/cpp/balloc/malloc-info.cpp @@ -5,18 +5,18 @@ using namespace NMalloc; extern "C" void DisableBalloc(); -extern "C" void EnableBalloc(); +extern "C" void EnableBalloc(); extern "C" bool BallocDisabled(); namespace { bool SetAllocParam(const char* name, const char* value) { if (strcmp(name, "disable") == 0) { if (value == nullptr || strcmp(value, "false") != 0) { - // all values other than "false" are considred to be "true" for compatibility - DisableBalloc(); - } else { - EnableBalloc(); - } + // all values other than "false" are considred to be "true" for compatibility + DisableBalloc(); + } else { + EnableBalloc(); + } return true; } return false; diff --git a/library/cpp/balloc/optional/operators.h b/library/cpp/balloc/optional/operators.h index 6107d28a6e..c4632089ea 100644 --- a/library/cpp/balloc/optional/operators.h +++ b/library/cpp/balloc/optional/operators.h @@ -10,7 +10,7 @@ inline bool BallocEnabled() { inline void ThreadDisableBalloc() { ::NMalloc::MallocInfo().SetParam("disable", "true"); } - -inline void ThreadEnableBalloc() { - ::NMalloc::MallocInfo().SetParam("disable", "false"); -} + +inline void ThreadEnableBalloc() { + ::NMalloc::MallocInfo().SetParam("disable", "false"); +} diff --git a/library/cpp/cgiparam/cgiparam.h b/library/cpp/cgiparam/cgiparam.h index 87d1ab0ad4..0c26a66f5d 100644 --- a/library/cpp/cgiparam/cgiparam.h +++ b/library/cpp/cgiparam/cgiparam.h @@ -88,13 +88,13 @@ public: void InsertEscaped(const TStringBuf name, const TStringBuf value); #if !defined(__GLIBCXX__) - template <typename TName, typename TValue> - inline void InsertUnescaped(TName&& name, TValue&& value) { + template <typename TName, typename TValue> + inline void InsertUnescaped(TName&& name, TValue&& value) { // TStringBuf use as TName or TValue is C++17 actually. // There is no pair constructor available in C++14 when required type // is not implicitly constructible from given type. // But libc++ pair allows this with C++14. - emplace(std::forward<TName>(name), std::forward<TValue>(value)); + emplace(std::forward<TName>(name), std::forward<TValue>(value)); } #else template <typename TName, typename TValue> @@ -103,19 +103,19 @@ public: } #endif - // replace all values for a given key with new values - template <typename TIter> - void ReplaceUnescaped(const TStringBuf key, TIter valuesBegin, const TIter valuesEnd); - - void ReplaceUnescaped(const TStringBuf key, std::initializer_list<TStringBuf> values) { - ReplaceUnescaped(key, values.begin(), values.end()); - } + // replace all values for a given key with new values + template <typename TIter> + void ReplaceUnescaped(const TStringBuf key, TIter valuesBegin, const TIter valuesEnd); - void ReplaceUnescaped(const TStringBuf key, const TStringBuf value) { + void ReplaceUnescaped(const TStringBuf key, std::initializer_list<TStringBuf> values) { + ReplaceUnescaped(key, values.begin(), values.end()); + } + + void ReplaceUnescaped(const TStringBuf key, const TStringBuf value) { ReplaceUnescaped(key, {value}); - } - - // join multiple values into a single one using a separator + } + + // join multiple values into a single one using a separator // if val is a [possibly empty] non-NULL string, append it as well void JoinUnescaped(const TStringBuf key, char sep, TStringBuf val = TStringBuf()); @@ -132,29 +132,29 @@ public: return it->second.data(); } }; - -template <typename TIter> -void TCgiParameters::ReplaceUnescaped(const TStringBuf key, TIter valuesBegin, const TIter valuesEnd) { - const auto oldRange = equal_range(key); - auto current = oldRange.first; - - // reuse as many existing nodes as possible (probably none) + +template <typename TIter> +void TCgiParameters::ReplaceUnescaped(const TStringBuf key, TIter valuesBegin, const TIter valuesEnd) { + const auto oldRange = equal_range(key); + auto current = oldRange.first; + + // reuse as many existing nodes as possible (probably none) for (; valuesBegin != valuesEnd && current != oldRange.second; ++valuesBegin, ++current) { - current->second = *valuesBegin; - } - - // if there were more nodes than we need to insert then erase remaining ones + current->second = *valuesBegin; + } + + // if there were more nodes than we need to insert then erase remaining ones for (; current != oldRange.second; erase(current++)) { - } - - // if there were less nodes than we need to insert then emplace the rest of the range + } + + // if there were less nodes than we need to insert then emplace the rest of the range if (valuesBegin != valuesEnd) { const TString keyStr = TString(key); for (; valuesBegin != valuesEnd; ++valuesBegin) { emplace_hint(oldRange.second, keyStr, TString(*valuesBegin)); } - } -} + } +} /** TQuickCgiParam is a faster non-editable version of TCgiParameters. * Care should be taken when replacing: diff --git a/library/cpp/cgiparam/cgiparam_ut.cpp b/library/cpp/cgiparam/cgiparam_ut.cpp index a562342084..deed188a42 100644 --- a/library/cpp/cgiparam/cgiparam_ut.cpp +++ b/library/cpp/cgiparam/cgiparam_ut.cpp @@ -132,56 +132,56 @@ Y_UNIT_TEST_SUITE(TCgiParametersTest) { Y_UNIT_TEST(TestReplaceUnescaped1) { TCgiParameters c; - c.ScanAddAll("many_keys=1&aaa=1&many_keys=2&bbb&many_keys=3"); - c.ReplaceUnescaped("many_keys", "new_value"); - - UNIT_ASSERT_VALUES_EQUAL(c.Print(), "aaa=1&bbb=&many_keys=new_value"); - } - + c.ScanAddAll("many_keys=1&aaa=1&many_keys=2&bbb&many_keys=3"); + c.ReplaceUnescaped("many_keys", "new_value"); + + UNIT_ASSERT_VALUES_EQUAL(c.Print(), "aaa=1&bbb=&many_keys=new_value"); + } + Y_UNIT_TEST(TestReplaceUnescaped2) { - TCgiParameters c; - c.ScanAddAll("par=1&only_one=1&par=2&bbb&par=3"); - c.ReplaceUnescaped("only_one", "new_value"); - - UNIT_ASSERT_VALUES_EQUAL(c.Print(), "bbb=&only_one=new_value&par=1&par=2&par=3"); - } - + TCgiParameters c; + c.ScanAddAll("par=1&only_one=1&par=2&bbb&par=3"); + c.ReplaceUnescaped("only_one", "new_value"); + + UNIT_ASSERT_VALUES_EQUAL(c.Print(), "bbb=&only_one=new_value&par=1&par=2&par=3"); + } + Y_UNIT_TEST(TestReplaceUnescaped3) { - TCgiParameters c; + TCgiParameters c; c.ScanAddAll("par=1&aaa=1&par=2&bbb&par=3"); - c.ReplaceUnescaped("no_such_key", "new_value"); - - UNIT_ASSERT_VALUES_EQUAL(c.Print(), "aaa=1&bbb=&no_such_key=new_value&par=1&par=2&par=3"); - } + c.ReplaceUnescaped("no_such_key", "new_value"); + UNIT_ASSERT_VALUES_EQUAL(c.Print(), "aaa=1&bbb=&no_such_key=new_value&par=1&par=2&par=3"); + } + Y_UNIT_TEST(TestReplaceUnescapedRange1) { - TCgiParameters c; - c.ScanAddAll("par=1&aaa=1&par=2&bbb&par=3"); - c.ReplaceUnescaped("par", {"x", "y", "z"}); // 3 old values, 3 new values - - UNIT_ASSERT_VALUES_EQUAL(c.Print(), "aaa=1&bbb=&par=x&par=y&par=z"); - } - + TCgiParameters c; + c.ScanAddAll("par=1&aaa=1&par=2&bbb&par=3"); + c.ReplaceUnescaped("par", {"x", "y", "z"}); // 3 old values, 3 new values + + UNIT_ASSERT_VALUES_EQUAL(c.Print(), "aaa=1&bbb=&par=x&par=y&par=z"); + } + Y_UNIT_TEST(TestReplaceUnescapedRange2) { - TCgiParameters c; - c.ScanAddAll("par=1&aaa=1&par=2&bbb"); - c.ReplaceUnescaped("par", {"x", "y", "z"}); // 2 old values, 3 new values - - UNIT_ASSERT_VALUES_EQUAL(c.Print(), "aaa=1&bbb=&par=x&par=y&par=z"); - } - + TCgiParameters c; + c.ScanAddAll("par=1&aaa=1&par=2&bbb"); + c.ReplaceUnescaped("par", {"x", "y", "z"}); // 2 old values, 3 new values + + UNIT_ASSERT_VALUES_EQUAL(c.Print(), "aaa=1&bbb=&par=x&par=y&par=z"); + } + Y_UNIT_TEST(TestReplaceUnescapedRange3) { - TCgiParameters c; - c.ScanAddAll("par=1&aaa=1&par=2&bbb&par=3"); - c.ReplaceUnescaped("par", {"x", "y"}); // 3 old values, 2 new values - - UNIT_ASSERT_VALUES_EQUAL(c.Print(), "aaa=1&bbb=&par=x&par=y"); - } - + TCgiParameters c; + c.ScanAddAll("par=1&aaa=1&par=2&bbb&par=3"); + c.ReplaceUnescaped("par", {"x", "y"}); // 3 old values, 2 new values + + UNIT_ASSERT_VALUES_EQUAL(c.Print(), "aaa=1&bbb=&par=x&par=y"); + } + Y_UNIT_TEST(TestNumOfValues) { - TCgiParameters c; - c.ScanAddAll("par=1&aaa=1&par=2&bbb&par=3"); - + TCgiParameters c; + c.ScanAddAll("par=1&aaa=1&par=2&bbb&par=3"); + UNIT_ASSERT_VALUES_EQUAL(c.NumOfValues("par"), 3u); } diff --git a/library/cpp/containers/sorted_vector/sorted_vector.h b/library/cpp/containers/sorted_vector/sorted_vector.h index 123539af9e..c7be8d9c90 100644 --- a/library/cpp/containers/sorted_vector/sorted_vector.h +++ b/library/cpp/containers/sorted_vector/sorted_vector.h @@ -323,7 +323,7 @@ namespace NSorted { using TBase::erase; }; - // The simplified map (a.k.a TFlatMap, flat_map), which is implemented by the sorted-vector. + // The simplified map (a.k.a TFlatMap, flat_map), which is implemented by the sorted-vector. // This structure has the side-effect: if you keep a reference to an existing element // and then inserts a new one, the existing reference can be broken (due to reallocation). // Please keep this in mind when using this structure. @@ -397,7 +397,7 @@ namespace NSorted { } }; - // The simplified set (a.k.a TFlatSet, flat_set), which is implemented by the sorted-vector. + // The simplified set (a.k.a TFlatSet, flat_set), which is implemented by the sorted-vector. // This structure has the same side-effect as TSimpleMap. // The value type must have TValueType(TKeyType) constructor in order to use [] operator template <typename TValueType, typename TKeyType = TValueType, class TKeyExtractor = TIdentity, diff --git a/library/cpp/deprecated/mapped_file/mapped_file.cpp b/library/cpp/deprecated/mapped_file/mapped_file.cpp index b0e4511299..fe8c56d370 100644 --- a/library/cpp/deprecated/mapped_file/mapped_file.cpp +++ b/library/cpp/deprecated/mapped_file/mapped_file.cpp @@ -11,7 +11,7 @@ TMappedFile::TMappedFile(TFileMap* map, const char* dbgName) { if (Hi32(len) != 0 && sizeof(size_t) <= sizeof(ui32)) ythrow yexception() << "File '" << dbgName << "' mapping error: " << len << " too large"; - Map_->Map(0, static_cast<size_t>(len)); + Map_->Map(0, static_cast<size_t>(len)); } TMappedFile::TMappedFile(const TFile& file, TFileMap::EOpenMode om, const char* dbgName) diff --git a/library/cpp/deprecated/mapped_file/ut/mapped_file_ut.cpp b/library/cpp/deprecated/mapped_file/ut/mapped_file_ut.cpp index afbd5b3358..3f3f77559e 100644 --- a/library/cpp/deprecated/mapped_file/ut/mapped_file_ut.cpp +++ b/library/cpp/deprecated/mapped_file/ut/mapped_file_ut.cpp @@ -1,8 +1,8 @@ #include <library/cpp/deprecated/mapped_file/mapped_file.h> #include <library/cpp/testing/unittest/registar.h> -#include <util/system/fs.h> - +#include <util/system/fs.h> + Y_UNIT_TEST_SUITE(TMappedFileTest) { static const char* FileName_("./mappped_file"); Y_UNIT_TEST(TestFileMapEmpty) { @@ -13,6 +13,6 @@ Y_UNIT_TEST_SUITE(TMappedFileTest) { map.init(FileName_); map.getData(0); - NFs::Remove(FileName_); + NFs::Remove(FileName_); } }; diff --git a/library/cpp/getopt/last_getopt_demo/demo.cpp b/library/cpp/getopt/last_getopt_demo/demo.cpp index 79426a9cc9..fcfe5ac3ea 100644 --- a/library/cpp/getopt/last_getopt_demo/demo.cpp +++ b/library/cpp/getopt/last_getopt_demo/demo.cpp @@ -92,7 +92,7 @@ protected: {"OPTIONS", "describe the communication options for the target resource"}, {"TRACE", "perform a message loop-back test"}, {"PATCH", "apply partial modifications to the specified resource"}})); - + opts.AddLongOption('U', "user-agent") .RequiredArgument("agent-string") .DefaultValue("LastGetoptDemo/1.0.0") @@ -202,8 +202,8 @@ protected: << colors.Cyan() << " $ last_getopt_demo -b -U 'Wget/1.0.0' https://wordpress.org/latest.zip" << colors.Reset()); - } - + } + int DoRun(NLastGetopt::TOptsParseResult&& parsedOptions) override { using namespace NColorizer; diff --git a/library/cpp/getopt/print.cpp b/library/cpp/getopt/print.cpp index 8cf1c62e4d..b9539a4400 100644 --- a/library/cpp/getopt/print.cpp +++ b/library/cpp/getopt/print.cpp @@ -31,7 +31,7 @@ namespace NLastGetoptPrivate { TString& ShortVersionString(); struct TInit { - TInit() { + TInit() { VersionString() = InitVersionString(); ShortVersionString() = InitShortVersionString(); } diff --git a/library/cpp/getopt/small/last_getopt.h b/library/cpp/getopt/small/last_getopt.h index 07687bc914..6778416cd0 100644 --- a/library/cpp/getopt/small/last_getopt.h +++ b/library/cpp/getopt/small/last_getopt.h @@ -4,7 +4,7 @@ #include "last_getopt_easy_setup.h" #include "last_getopt_parse_result.h" -#include <util/generic/function.h> +#include <util/generic/function.h> #include <util/string/split.h> /// see some documentation in @@ -17,7 +17,7 @@ namespace NLastGetopt { /// Handler to split option value by delimiter into a target container and allow ranges. - template <class Container> + template <class Container> struct TOptRangeSplitHandler: public IOptHandler { public: using TContainer = Container; @@ -26,9 +26,9 @@ namespace NLastGetopt { explicit TOptRangeSplitHandler(TContainer* target, const char elementsDelim, const char rangesDelim) : Target(target) , ElementsDelim(elementsDelim) - , RangesDelim(rangesDelim) - { - } + , RangesDelim(rangesDelim) + { + } void HandleOpt(const TOptsParser* parser) override { const TStringBuf curval(parser->CurValOrDef()); @@ -56,7 +56,7 @@ namespace NLastGetopt { char RangesDelim; }; - template <class Container> + template <class Container> struct TOptSplitHandler: public IOptHandler { public: using TContainer = Container; @@ -64,9 +64,9 @@ namespace NLastGetopt { explicit TOptSplitHandler(TContainer* target, const char delim) : Target(target) - , Delim(delim) - { - } + , Delim(delim) + { + } void HandleOpt(const TOptsParser* parser) override { const TStringBuf curval(parser->CurValOrDef()); @@ -82,36 +82,36 @@ namespace NLastGetopt { char Delim; }; - template <class TpFunc> + template <class TpFunc> struct TOptKVHandler: public IOptHandler { - public: - using TKey = typename TFunctionArgs<TpFunc>::template TGet<0>; - using TValue = typename TFunctionArgs<TpFunc>::template TGet<1>; - - explicit TOptKVHandler(TpFunc func, const char kvdelim = '=') - : Func(func) - , KVDelim(kvdelim) - { - } - - void HandleOpt(const TOptsParser* parser) override { - const TStringBuf curval(parser->CurValOrDef()); - const TOpt* curOpt(parser->CurOpt()); - if (curval.IsInited()) { - TStringBuf key, value; - if (!curval.TrySplit(KVDelim, key, value)) { + public: + using TKey = typename TFunctionArgs<TpFunc>::template TGet<0>; + using TValue = typename TFunctionArgs<TpFunc>::template TGet<1>; + + explicit TOptKVHandler(TpFunc func, const char kvdelim = '=') + : Func(func) + , KVDelim(kvdelim) + { + } + + void HandleOpt(const TOptsParser* parser) override { + const TStringBuf curval(parser->CurValOrDef()); + const TOpt* curOpt(parser->CurOpt()); + if (curval.IsInited()) { + TStringBuf key, value; + if (!curval.TrySplit(KVDelim, key, value)) { throw TUsageException() << "failed to parse opt " << NPrivate::OptToString(curOpt) << " value " << TString(curval).Quote() << ": expected key" << KVDelim << "value format"; - } - Func(NPrivate::OptFromString<TKey>(key, curOpt), NPrivate::OptFromString<TValue>(value, curOpt)); - } - } - - private: - TpFunc Func; - char KVDelim; - }; - + } + Func(NPrivate::OptFromString<TKey>(key, curOpt), NPrivate::OptFromString<TValue>(value, curOpt)); + } + } + + private: + TpFunc Func; + char KVDelim; + }; + namespace NPrivate { template <typename TpFunc, typename TpArg> void THandlerFunctor1<TpFunc, TpArg>::HandleOpt(const TOptsParser* parser) { diff --git a/library/cpp/getopt/small/last_getopt_handlers.h b/library/cpp/getopt/small/last_getopt_handlers.h index d35456ef34..5311fbbe42 100644 --- a/library/cpp/getopt/small/last_getopt_handlers.h +++ b/library/cpp/getopt/small/last_getopt_handlers.h @@ -7,17 +7,17 @@ namespace NLastGetopt { /// Handler to split option value by delimiter into a target container. - template <class Container> + template <class Container> struct TOptSplitHandler; /// Handler to split option value by delimiter into a target container and allow ranges. - template <class Container> + template <class Container> struct TOptRangeSplitHandler; - /// Handler to parse key-value pairs (default delimiter is '=') and apply user-supplied handler to each pair - template <class TpFunc> - struct TOptKVHandler; - + /// Handler to parse key-value pairs (default delimiter is '=') and apply user-supplied handler to each pair + template <class TpFunc> + struct TOptKVHandler; + [[noreturn]] void PrintUsageAndExit(const TOptsParser* parser); [[noreturn]] void PrintVersionAndExit(const TOptsParser* parser); [[noreturn]] void PrintShortVersionAndExit(const TString& appName); diff --git a/library/cpp/getopt/small/last_getopt_opt.h b/library/cpp/getopt/small/last_getopt_opt.h index a8dd5adca9..1f0820ed41 100644 --- a/library/cpp/getopt/small/last_getopt_opt.h +++ b/library/cpp/getopt/small/last_getopt_opt.h @@ -699,7 +699,7 @@ namespace NLastGetopt { TOpt& RangeSplitHandler(Container* target, const char elementsDelim, const char rangesDelim) { return Handler(new NLastGetopt::TOptRangeSplitHandler<Container>(target, elementsDelim, rangesDelim)); } - + template <class TpFunc> TOpt& KVHandler(TpFunc func, const char kvdelim = '=') { return Handler(new NLastGetopt::TOptKVHandler<TpFunc>(func, kvdelim)); diff --git a/library/cpp/getopt/small/last_getopt_parse_result.h b/library/cpp/getopt/small/last_getopt_parse_result.h index 1ab6f598c9..013bedc507 100644 --- a/library/cpp/getopt/small/last_getopt_parse_result.h +++ b/library/cpp/getopt/small/last_getopt_parse_result.h @@ -313,7 +313,7 @@ namespace NLastGetopt { } virtual ~TOptsParseResultException() = default; void HandleError() const override; - + protected: TOptsParseResultException() = default; }; diff --git a/library/cpp/getopt/small/last_getopt_support.h b/library/cpp/getopt/small/last_getopt_support.h index 17bed3e614..5fdb145dfe 100644 --- a/library/cpp/getopt/small/last_getopt_support.h +++ b/library/cpp/getopt/small/last_getopt_support.h @@ -47,7 +47,7 @@ namespace NLastGetopt { Func_(); } }; - + template <typename TpFunc, typename TpArg = const TOptsParser*> class THandlerFunctor1 : public IOptHandler { @@ -62,7 +62,7 @@ namespace NLastGetopt { , HasDef_(false) { } - + template <typename T> THandlerFunctor1(const TpFunc& func, const T& def) : Func_(func) @@ -70,7 +70,7 @@ namespace NLastGetopt { , HasDef_(true) { } - + void HandleOpt(const TOptsParser* parser) override; }; @@ -78,7 +78,7 @@ namespace NLastGetopt { class THandlerFunctor1<TpFunc, const TOptsParser*> : public IOptHandler { TpFunc Func_; - + public: THandlerFunctor1(TpFunc func) : Func_(func) @@ -89,7 +89,7 @@ namespace NLastGetopt { Func_(parser); } }; - + template <typename T, typename TpVal = T> class TStoreResultFunctor { private: @@ -100,7 +100,7 @@ namespace NLastGetopt { : Target_(target) { } - + void operator()(const TpVal& val) { *Target_ = val; } @@ -118,7 +118,7 @@ namespace NLastGetopt { , Func_(func) { } - + void operator()(const TpVal& val) { *Target_ = Func_(val); } diff --git a/library/cpp/getopt/small/modchooser.cpp b/library/cpp/getopt/small/modchooser.cpp index 2fa5cfd070..b0d80adef3 100644 --- a/library/cpp/getopt/small/modchooser.cpp +++ b/library/cpp/getopt/small/modchooser.cpp @@ -16,9 +16,9 @@ class PtrWrapper: public TMainClass { public: explicit PtrWrapper(const TMainFunctionPtr main) - : Main(main) - { - } + : Main(main) + { + } int operator()(const int argc, const char** argv) override { return Main(argc, argv); @@ -31,9 +31,9 @@ private: class PtrvWrapper: public TMainClass { public: explicit PtrvWrapper(const TMainFunctionPtrV main) - : Main(main) - { - } + : Main(main) + { + } int operator()(const int argc, const char** argv) override { TVector<TString> nargv(argv, argv + argc); @@ -47,9 +47,9 @@ private: class ClassWrapper: public TMainClass { public: explicit ClassWrapper(TMainClassV* main) - : Main(main) - { - } + : Main(main) + { + } int operator()(const int argc, const char** argv) override { TVector<TString> nargv(argv, argv + argc); diff --git a/library/cpp/getopt/small/modchooser.h b/library/cpp/getopt/small/modchooser.h index 0a8de6d50b..07ece740e8 100644 --- a/library/cpp/getopt/small/modchooser.h +++ b/library/cpp/getopt/small/modchooser.h @@ -112,8 +112,8 @@ public: TMode() : Main(nullptr) - { - } + { + } TMode(const TString& name, TMainClass* main, const TString& descr, bool hidden, bool noCompletion); diff --git a/library/cpp/getopt/small/opt.cpp b/library/cpp/getopt/small/opt.cpp index 744501765c..d6282dfd3b 100644 --- a/library/cpp/getopt/small/opt.cpp +++ b/library/cpp/getopt/small/opt.cpp @@ -8,10 +8,10 @@ using namespace NLastGetopt; namespace { struct TOptsNoDefault: public TOpts { - TOptsNoDefault(const TStringBuf& optstring = TStringBuf()) - : TOpts(optstring) - { - } + TOptsNoDefault(const TStringBuf& optstring = TStringBuf()) + : TOpts(optstring) + { + } }; } diff --git a/library/cpp/getopt/small/opt.h b/library/cpp/getopt/small/opt.h index ecb57439bc..2767124dbb 100644 --- a/library/cpp/getopt/small/opt.h +++ b/library/cpp/getopt/small/opt.h @@ -85,7 +85,7 @@ public: // Get() means next int Get(); int Get(int* longOptionIndex); - int operator()() { + int operator()() { return Get(); } diff --git a/library/cpp/getopt/small/opt2.h b/library/cpp/getopt/small/opt2.h index 4d9d943237..7d649beaa3 100644 --- a/library/cpp/getopt/small/opt2.h +++ b/library/cpp/getopt/small/opt2.h @@ -35,38 +35,38 @@ struct Opt2Param { TString HelpUsage; TVector<const char*> ActualValue; const char* LongOptName; - Opt2Param() - : HasArg(false) - , IsFound(0) - , IsNumeric(0) - , IsRequired(0) - , MultipleUse(0) - , DefValue(nullptr) - , LongOptName(nullptr) - { - } + Opt2Param() + : HasArg(false) + , IsFound(0) + , IsNumeric(0) + , IsRequired(0) + , MultipleUse(0) + , DefValue(nullptr) + , LongOptName(nullptr) + { + } }; struct IntRange { int Left, Right; - IntRange() = delete; - IntRange(int both) - : Left(both) - , Right(both) - { - } - - IntRange(int left, int right) - : Left(left) - , Right(right) - { - } + IntRange() = delete; + IntRange(int both) + : Left(both) + , Right(both) + { + } + + IntRange(int left, int right) + : Left(left) + , Right(right) + { + } }; class Opt2 { public: - Opt2() = default; - + Opt2() = default; + Opt2(int argc, char* const* argv, const char* optspec, IntRange free_args_num = -1, const char* long_alias = nullptr) { Init(argc, argv, optspec, free_args_num, long_alias); } diff --git a/library/cpp/getopt/ut/last_getopt_ut.cpp b/library/cpp/getopt/ut/last_getopt_ut.cpp index c99a1d053d..7ccf25f3af 100644 --- a/library/cpp/getopt/ut/last_getopt_ut.cpp +++ b/library/cpp/getopt/ut/last_getopt_ut.cpp @@ -3,7 +3,7 @@ #include <library/cpp/colorizer/colors.h> #include <library/cpp/testing/unittest/registar.h> -#include <util/generic/array_size.h> +#include <util/generic/array_size.h> #include <util/string/subst.h> #include <util/string/vector.h> #include <util/string/split.h> @@ -12,23 +12,23 @@ using namespace NLastGetopt; namespace { struct TOptsNoDefault: public TOpts { - TOptsNoDefault(const TStringBuf& optstring = TStringBuf()) - : TOpts(optstring) - { - } + TOptsNoDefault(const TStringBuf& optstring = TStringBuf()) + : TOpts(optstring) + { + } }; class TOptsParseResultTestWrapper: public TOptsParseResultException { TVector<const char*> Argv_; - - public: + + public: TOptsParseResultTestWrapper(const TOpts* opts, TVector<const char*> argv) - : Argv_(argv) - { + : Argv_(argv) + { Init(opts, (int)Argv_.size(), Argv_.data()); - } - }; - + } + }; + using V = TVector<const char*>; } @@ -137,7 +137,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { TOptsNoDefault opts; opts.AddLongOption("from"); opts.AddLongOption("to"); - TOptsParseResultTestWrapper r(&opts, V({"copy", "--from=/", "--to=/etc"})); + TOptsParseResultTestWrapper r(&opts, V({"copy", "--from=/", "--to=/etc"})); UNIT_ASSERT_VALUES_EQUAL("copy", r.GetProgramName()); UNIT_ASSERT_VALUES_EQUAL("/", r.Get("from")); @@ -154,7 +154,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { opts.AddCharOption('R', NO_ARGUMENT); opts.AddCharOption('l', NO_ARGUMENT); opts.AddCharOption('h', NO_ARGUMENT); - TOptsParseResultTestWrapper r(&opts, V({"cp", "/etc", "-Rl", "/tmp/etc"})); + TOptsParseResultTestWrapper r(&opts, V({"cp", "/etc", "-Rl", "/tmp/etc"})); UNIT_ASSERT(r.Has('R')); UNIT_ASSERT(r.Has('l')); UNIT_ASSERT(!r.Has('h')); @@ -168,20 +168,20 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { Y_UNIT_TEST(TestFreeArgs) { TOptsNoDefault opts; opts.SetFreeArgsNum(1, 3); - TOptsParseResultTestWrapper r11(&opts, V({"cp", "/etc"})); - TOptsParseResultTestWrapper r12(&opts, V({"cp", "/etc", "/tmp/etc"})); - TOptsParseResultTestWrapper r13(&opts, V({"cp", "/etc", "/tmp/etc", "verbose"})); + TOptsParseResultTestWrapper r11(&opts, V({"cp", "/etc"})); + TOptsParseResultTestWrapper r12(&opts, V({"cp", "/etc", "/tmp/etc"})); + TOptsParseResultTestWrapper r13(&opts, V({"cp", "/etc", "/tmp/etc", "verbose"})); UNIT_ASSERT_EXCEPTION( - TOptsParseResultTestWrapper(&opts, V({"cp", "/etc", "/tmp/etc", "verbose", "nosymlink"})), + TOptsParseResultTestWrapper(&opts, V({"cp", "/etc", "/tmp/etc", "verbose", "nosymlink"})), yexception); UNIT_ASSERT_EXCEPTION( - TOptsParseResultTestWrapper(&opts, V({"cp"})), + TOptsParseResultTestWrapper(&opts, V({"cp"})), yexception); opts.SetFreeArgsNum(2); - TOptsParseResultTestWrapper r22(&opts, V({"cp", "/etc", "/var/tmp"})); + TOptsParseResultTestWrapper r22(&opts, V({"cp", "/etc", "/var/tmp"})); } Y_UNIT_TEST(TestCharOptionsRequiredOptional) { @@ -191,7 +191,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { opts.AddCharOption('x', REQUIRED_ARGUMENT); opts.AddCharOption('y', REQUIRED_ARGUMENT); opts.AddCharOption('l', NO_ARGUMENT); - TOptsParseResultTestWrapper r(&opts, V({"cmd", "-ld11", "-e", "22", "-lllx33", "-y", "44"})); + TOptsParseResultTestWrapper r(&opts, V({"cmd", "-ld11", "-e", "22", "-lllx33", "-y", "44"})); UNIT_ASSERT_VALUES_EQUAL("11", r.Get('d')); UNIT_ASSERT_VALUES_EQUAL("22", r.Get('e')); UNIT_ASSERT_VALUES_EQUAL("33", r.Get('x')); @@ -446,7 +446,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { opts.AddLongOption('b', "beta").NoArgument().StoreValue(&b, 24); opts.AddLongOption('e', "enum").NoArgument().StoreValue(&e, REQUIRED_ARGUMENT).StoreValue(&c, 12345); - TOptsParseResultTestWrapper r(&opts, V({"cmd", "-a", "-e"})); + TOptsParseResultTestWrapper r(&opts, V({"cmd", "-a", "-e"})); UNIT_ASSERT_VALUES_EQUAL(42, a); UNIT_ASSERT_VALUES_EQUAL(0, b); @@ -476,7 +476,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { opts.AddLongOption("path").DefaultValue("/etc"); int value = 42; opts.AddLongOption("value").StoreResult(&value).DefaultValue(32); - TOptsParseResultTestWrapper r(&opts, V({"cmd", "dfdf"})); + TOptsParseResultTestWrapper r(&opts, V({"cmd", "dfdf"})); UNIT_ASSERT_VALUES_EQUAL("/etc", r.Get("path")); UNIT_ASSERT_VALUES_EQUAL(32, value); } @@ -485,7 +485,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { TOptsNoDefault opts; TVector<TString> vals; opts.AddLongOption('s', "split").SplitHandler(&vals, ','); - TOptsParseResultTestWrapper r(&opts, V({"prog", "--split=a,b,c"})); + TOptsParseResultTestWrapper r(&opts, V({"prog", "--split=a,b,c"})); UNIT_ASSERT_EQUAL(vals.size(), 3); UNIT_ASSERT_EQUAL(vals[0], "a"); UNIT_ASSERT_EQUAL(vals[1], "b"); @@ -496,7 +496,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { TOptsNoDefault opts; TVector<ui32> vals; opts.AddLongOption('s', "split").RangeSplitHandler(&vals, ',', '-'); - TOptsParseResultTestWrapper r(&opts, V({"prog", "--split=1,8-10", "--split=12-14"})); + TOptsParseResultTestWrapper r(&opts, V({"prog", "--split=1,8-10", "--split=12-14"})); UNIT_ASSERT_EQUAL(vals.size(), 7); UNIT_ASSERT_EQUAL(vals[0], 1); UNIT_ASSERT_EQUAL(vals[1], 8); @@ -523,15 +523,15 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { // test 'not required' // makes sure that the problem will only be in 'required' - TOptsParseResultTestWrapper r1(&opts, V({"cmd"})); + TOptsParseResultTestWrapper r1(&opts, V({"cmd"})); // test 'required' opt_d.Required(); UNIT_ASSERT_EXCEPTION( - TOptsParseResultTestWrapper(&opts, V({"cmd"})), + TOptsParseResultTestWrapper(&opts, V({"cmd"})), TUsageException); - TOptsParseResultTestWrapper r3(&opts, V({"cmd", "-d11"})); + TOptsParseResultTestWrapper r3(&opts, V({"cmd", "-d11"})); UNIT_ASSERT_VALUES_EQUAL("11", r3.Get('d')); } @@ -541,8 +541,8 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { public: HandlerStoreTrue(bool* flag) : Flag(flag) - { - } + { + } void operator()() { *Flag = true; } @@ -552,7 +552,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { TOptsNoDefault opts; bool flag = false; opts.AddLongOption("flag").Handler0(HandlerStoreTrue(&flag)).NoArgument(); - TOptsParseResultTestWrapper r(&opts, V({"cmd", "--flag"})); + TOptsParseResultTestWrapper r(&opts, V({"cmd", "--flag"})); UNIT_ASSERT(flag); } { @@ -564,11 +564,11 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { opts.AddLongOption("flag3").RequiredArgument().StoreMappedResult(&fval, (double (*)(double))fabs); opts.AddLongOption("flag4").RequiredArgument().StoreMappedResult(&fval, (double (*)(double))sqrt); UNIT_ASSERT_EXCEPTION( - TOptsParseResultTestWrapper(&opts, V({"cmd", "--flag3", "-2.0", "--flag1", "-1"})), + TOptsParseResultTestWrapper(&opts, V({"cmd", "--flag3", "-2.0", "--flag1", "-1"})), yexception); UNIT_ASSERT_VALUES_EQUAL(uval, 5u); UNIT_ASSERT_VALUES_EQUAL(fval, 2.0); - TOptsParseResultTestWrapper r1(&opts, V({"cmd", "--flag4", "9.0", "--flag2", "-1"})); + TOptsParseResultTestWrapper r1(&opts, V({"cmd", "--flag4", "9.0", "--flag2", "-1"})); UNIT_ASSERT_VALUES_EQUAL(uval, Max<unsigned>()); UNIT_ASSERT_VALUES_EQUAL(fval, 3.0); } @@ -706,7 +706,7 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { TOptsNoDefault opts; opts.AddLongOption("size").AppendTo(&ints); - TOptsParseResultTestWrapper r(&opts, V({"cmd", "--size=17", "--size=19"})); + TOptsParseResultTestWrapper r(&opts, V({"cmd", "--size=17", "--size=19"})); UNIT_ASSERT_VALUES_EQUAL(size_t(2), ints.size()); UNIT_ASSERT_VALUES_EQUAL(17, ints.at(0)); @@ -727,16 +727,16 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { } Y_UNIT_TEST(TestKVHandler) { - TStringBuilder keyvals; - - TOptsNoDefault opts; + TStringBuilder keyvals; + + TOptsNoDefault opts; opts.AddLongOption("set").KVHandler([&keyvals](TString k, TString v) { keyvals << k << ":" << v << ","; }); - - TOptsParseResultTestWrapper r(&opts, V({"cmd", "--set", "x=1", "--set", "y=2", "--set=z=3"})); - - UNIT_ASSERT_VALUES_EQUAL(keyvals, "x:1,y:2,z:3,"); - } - + + TOptsParseResultTestWrapper r(&opts, V({"cmd", "--set", "x=1", "--set", "y=2", "--set=z=3"})); + + UNIT_ASSERT_VALUES_EQUAL(keyvals, "x:1,y:2,z:3,"); + } + Y_UNIT_TEST(TestEasySetup) { TEasySetup opts; bool flag = false; @@ -744,41 +744,41 @@ Y_UNIT_TEST_SUITE(TLastGetoptTests) { { gSimpleFlag = false; - TOptsParseResultTestWrapper r(&opts, V({"cmd", "--abstract"})); + TOptsParseResultTestWrapper r(&opts, V({"cmd", "--abstract"})); UNIT_ASSERT(!flag); UNIT_ASSERT(!gSimpleFlag); } { - TOptsParseResultTestWrapper r(&opts, V({"cmd", "--abstract", "--global", "-t"})); + TOptsParseResultTestWrapper r(&opts, V({"cmd", "--abstract", "--global", "-t"})); UNIT_ASSERT(flag); UNIT_ASSERT(gSimpleFlag); } { UNIT_ASSERT_EXCEPTION( - TOptsParseResultTestWrapper(&opts, V({"cmd", "--true"})), + TOptsParseResultTestWrapper(&opts, V({"cmd", "--true"})), TUsageException); } { - TOptsParseResultTestWrapper r(&opts, V({"cmd", "--abstract", "--buffer=512"})); + TOptsParseResultTestWrapper r(&opts, V({"cmd", "--abstract", "--buffer=512"})); UNIT_ASSERT(r.Has('b')); UNIT_ASSERT_VALUES_EQUAL(r.Get('b', 0), "512"); } } Y_UNIT_TEST(TestTOptsParseResultException) { - // verify that TOptsParseResultException actually throws a TUsageException instead of exit() - // not using wrapper here because it can hide bugs (see review #243810 and r2737774) - TOptsNoDefault opts; - opts.AddLongOption("required-opt").Required(); - const char* argv[] = {"cmd"}; - // Should throw TUsageException. Other exception types, no exceptions at all and exit(1) are failures - UNIT_ASSERT_EXCEPTION( - TOptsParseResultException(&opts, Y_ARRAY_SIZE(argv), argv), + // verify that TOptsParseResultException actually throws a TUsageException instead of exit() + // not using wrapper here because it can hide bugs (see review #243810 and r2737774) + TOptsNoDefault opts; + opts.AddLongOption("required-opt").Required(); + const char* argv[] = {"cmd"}; + // Should throw TUsageException. Other exception types, no exceptions at all and exit(1) are failures + UNIT_ASSERT_EXCEPTION( + TOptsParseResultException(&opts, Y_ARRAY_SIZE(argv), argv), TUsageException); - } + } Y_UNIT_TEST(TestFreeArgsStoreResult) { TOptsNoDefault opts; diff --git a/library/cpp/http/server/http_ut.cpp b/library/cpp/http/server/http_ut.cpp index cc62bb988e..dae9a2f36d 100644 --- a/library/cpp/http/server/http_ut.cpp +++ b/library/cpp/http/server/http_ut.cpp @@ -4,10 +4,10 @@ #include <library/cpp/testing/unittest/registar.h> #include <library/cpp/testing/unittest/tests_data.h> -#include <util/generic/cast.h> +#include <util/generic/cast.h> #include <util/stream/output.h> #include <util/stream/zlib.h> -#include <util/system/datetime.h> +#include <util/system/datetime.h> #include <util/system/sem.h> Y_UNIT_TEST_SUITE(THttpServerTest) { @@ -139,9 +139,9 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { static const TString CrLf = "\r\n"; struct TTestRequest { - TTestRequest(ui16 port, TString content = TString()) + TTestRequest(ui16 port, TString content = TString()) : Port(port) - , Content(std::move(content)) + , Content(std::move(content)) { } @@ -369,59 +369,59 @@ Y_UNIT_TEST_SUITE(THttpServerTest) { } Y_UNIT_TEST(TestReusePortEnabled) { - if (!IsReusePortAvailable()) { + if (!IsReusePortAvailable()) { return; // skip test - } - TString res = TestData(); - TPortManager pm; - const ui16 port = pm.GetPort(); - - TEchoServer serverImpl(res); + } + TString res = TestData(); + TPortManager pm; + const ui16 port = pm.GetPort(); + + TEchoServer serverImpl(res); TVector<THolder<THttpServer>> servers; - for (ui32 i = 0; i < 10; i++) { - servers.push_back(MakeHolder<THttpServer>(&serverImpl, THttpServer::TOptions(port).EnableReusePort(true))); - } - - for (ui32 testRun = 0; testRun < 3; testRun++) { + for (ui32 i = 0; i < 10; i++) { + servers.push_back(MakeHolder<THttpServer>(&serverImpl, THttpServer::TOptions(port).EnableReusePort(true))); + } + + for (ui32 testRun = 0; testRun < 3; testRun++) { for (auto& server : servers) { - // start servers one at a time and check at least one of them is replying - UNIT_ASSERT(server->Start()); - - TTestRequest r(port, res); - UNIT_ASSERT_C(r.Execute() == res, "diff echo response for request:\n" + r.GetDescription()); - } - + // start servers one at a time and check at least one of them is replying + UNIT_ASSERT(server->Start()); + + TTestRequest r(port, res); + UNIT_ASSERT_C(r.Execute() == res, "diff echo response for request:\n" + r.GetDescription()); + } + for (auto& server : servers) { - // ping servers and stop them one at a time - // at the last iteration only one server is still working and then gets stopped as well - - TTestRequest r(port, res); - UNIT_ASSERT_C(r.Execute() == res, "diff echo response for request:\n" + r.GetDescription()); - - server->Stop(); - } - } - } - + // ping servers and stop them one at a time + // at the last iteration only one server is still working and then gets stopped as well + + TTestRequest r(port, res); + UNIT_ASSERT_C(r.Execute() == res, "diff echo response for request:\n" + r.GetDescription()); + + server->Stop(); + } + } + } + Y_UNIT_TEST(TestReusePortDisabled) { - // check that with the ReusePort option disabled it's impossible to start two servers on the same port - // check that ReusePort option is disabled by default (don't set it explicitly in the test) - TPortManager pm; - const ui16 port = pm.GetPort(); - - TEchoServer serverImpl(TString{}); - THttpServer server1(&serverImpl, THttpServer::TOptions(port)); - THttpServer server2(&serverImpl, THttpServer::TOptions(port)); - - UNIT_ASSERT(true == server1.Start()); - UNIT_ASSERT(false == server2.Start()); - - server1.Stop(); - // Stop() is a sync call, port should be free by now - UNIT_ASSERT(true == server2.Start()); - UNIT_ASSERT(false == server1.Start()); - } - + // check that with the ReusePort option disabled it's impossible to start two servers on the same port + // check that ReusePort option is disabled by default (don't set it explicitly in the test) + TPortManager pm; + const ui16 port = pm.GetPort(); + + TEchoServer serverImpl(TString{}); + THttpServer server1(&serverImpl, THttpServer::TOptions(port)); + THttpServer server2(&serverImpl, THttpServer::TOptions(port)); + + UNIT_ASSERT(true == server1.Start()); + UNIT_ASSERT(false == server2.Start()); + + server1.Stop(); + // Stop() is a sync call, port should be free by now + UNIT_ASSERT(true == server2.Start()); + UNIT_ASSERT(false == server1.Start()); + } + Y_UNIT_TEST(TestFailServer) { /** * Emulate request processing failures diff --git a/library/cpp/http/server/options.h b/library/cpp/http/server/options.h index 38eda0e5e7..9b9c7d3fe5 100644 --- a/library/cpp/http/server/options.h +++ b/library/cpp/http/server/options.h @@ -50,12 +50,12 @@ public: return *this; } - inline THttpServerOptions& EnableReusePort(bool enable) noexcept { - ReusePort = enable; - - return *this; - } - + inline THttpServerOptions& EnableReusePort(bool enable) noexcept { + ReusePort = enable; + + return *this; + } + inline THttpServerOptions& EnableReuseAddress(bool enable) noexcept { ReuseAddress = enable; diff --git a/library/cpp/json/json_prettifier.cpp b/library/cpp/json/json_prettifier.cpp index bb16aab44e..2f0615a2d9 100644 --- a/library/cpp/json/json_prettifier.cpp +++ b/library/cpp/json/json_prettifier.cpp @@ -150,7 +150,7 @@ namespace NJson { void AfterVal() { Out.Hold(','); - } + } template <typename T> bool WriteVal(const T& t) { diff --git a/library/cpp/json/json_prettifier.h b/library/cpp/json/json_prettifier.h index 27d611b0b4..4c67a9893a 100644 --- a/library/cpp/json/json_prettifier.h +++ b/library/cpp/json/json_prettifier.h @@ -2,8 +2,8 @@ #include "json_reader.h" -#include <util/generic/ylimits.h> - +#include <util/generic/ylimits.h> + namespace NJson { struct TJsonPrettifier { bool Unquote = false; diff --git a/library/cpp/json/ut/json_prettifier_ut.cpp b/library/cpp/json/ut/json_prettifier_ut.cpp index ae5f8dd81a..ff2a2a00b6 100644 --- a/library/cpp/json/ut/json_prettifier_ut.cpp +++ b/library/cpp/json/ut/json_prettifier_ut.cpp @@ -1,5 +1,5 @@ #include <library/cpp/json/json_prettifier.h> - + #include <library/cpp/testing/unittest/registar.h> Y_UNIT_TEST_SUITE(JsonPrettifier) { @@ -20,22 +20,22 @@ Y_UNIT_TEST_SUITE(JsonPrettifier) { UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("{}"), "{ }"); UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("{}"), "{ }"); UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("{k:v}", false, 2, true), "{\n 'k' : 'v'\n}"); - - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("Test545", true, 2), "Test545"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("'null'", true, 2, true), "'null'"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("'true'", true, 2, true), "'true'"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("'false'", true, 2, true), "'false'"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("'\"'", true, 2, true), "'\"'"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("'\"'", true, 2, false), "\"\\\"\""); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("'\\\''", true, 2, true), "'\\u0027'"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("'\\\''", true, 2, false), "\"'\""); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("'1b'", true, 2, true), "'1b'"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("'Test*545'", true, 2, true), "'Test*545'"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("{k:v}", true, 2), "{\n k : v\n}"); - } - + + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("Test545", true, 2), "Test545"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("'null'", true, 2, true), "'null'"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("'true'", true, 2, true), "'true'"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("'false'", true, 2, true), "'false'"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("'\"'", true, 2, true), "'\"'"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("'\"'", true, 2, false), "\"\\\"\""); + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("'\\\''", true, 2, true), "'\\u0027'"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("'\\\''", true, 2, false), "\"'\""); + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("'1b'", true, 2, true), "'1b'"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("'Test*545'", true, 2, true), "'Test*545'"); + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("{k:v}", true, 2), "{\n k : v\n}"); + } + Y_UNIT_TEST(PrettifyJsonLong) { - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("[{k:v},{a:b}]", false, 2, true), + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("[{k:v},{a:b}]", false, 2, true), "[\n" " {\n" " 'k' : 'v'\n" @@ -44,7 +44,7 @@ Y_UNIT_TEST_SUITE(JsonPrettifier) { " 'a' : 'b'\n" " }\n" "]"); - + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("{k:v,a:b,x:[1,2,3]}", false, 2, true), "{\n" " 'k' : 'v',\n" @@ -55,7 +55,7 @@ Y_UNIT_TEST_SUITE(JsonPrettifier) { " 3\n" " ]\n" "}"); - + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("{k:v,a:b,x:[1,{f:b},3],m:n}", false, 2, true), "{\n" " 'k' : 'v',\n" @@ -70,9 +70,9 @@ Y_UNIT_TEST_SUITE(JsonPrettifier) { " 'm' : 'n'\n" "}"); - NJson::TJsonPrettifier prettifierMaxLevel1 = NJson::TJsonPrettifier::Prettifier(false, 2, true); - prettifierMaxLevel1.MaxPaddingLevel = 1; - UNIT_ASSERT_STRINGS_EQUAL(prettifierMaxLevel1.Prettify("{k:v,a:b,x:[1,{f:b},3],m:n}"), + NJson::TJsonPrettifier prettifierMaxLevel1 = NJson::TJsonPrettifier::Prettifier(false, 2, true); + prettifierMaxLevel1.MaxPaddingLevel = 1; + UNIT_ASSERT_STRINGS_EQUAL(prettifierMaxLevel1.Prettify("{k:v,a:b,x:[1,{f:b},3],m:n}"), "{\n" " 'k' : 'v',\n" " 'a' : 'b',\n" @@ -95,10 +95,10 @@ Y_UNIT_TEST_SUITE(JsonPrettifier) { " y : fff\n" " }\n" "}"); - - NJson::TJsonPrettifier prettifierMaxLevel3 = NJson::TJsonPrettifier::Prettifier(true, 2); - prettifierMaxLevel3.MaxPaddingLevel = 3; - UNIT_ASSERT_STRINGS_EQUAL(prettifierMaxLevel3.Prettify("{g:{x:{a:{b:c,e:f},q:{x:y}},y:fff}}"), + + NJson::TJsonPrettifier prettifierMaxLevel3 = NJson::TJsonPrettifier::Prettifier(true, 2); + prettifierMaxLevel3.MaxPaddingLevel = 3; + UNIT_ASSERT_STRINGS_EQUAL(prettifierMaxLevel3.Prettify("{g:{x:{a:{b:c,e:f},q:{x:y}},y:fff}}"), "{\n" " g : {\n" " x : {\n" @@ -111,18 +111,18 @@ Y_UNIT_TEST_SUITE(JsonPrettifier) { } Y_UNIT_TEST(PrettifyJsonInvalid) { - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("}"), ""); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("}}"), ""); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("{}}"), ""); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("{}}}"), ""); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("]"), ""); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("]]"), ""); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("[]]"), ""); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("[]]]"), ""); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("[,,,]"), ""); - UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("{,,,}"), ""); - } - + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("}"), ""); + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("}}"), ""); + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("{}}"), ""); + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("{}}}"), ""); + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("]"), ""); + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("]]"), ""); + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("[]]"), ""); + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("[]]]"), ""); + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("[,,,]"), ""); + UNIT_ASSERT_STRINGS_EQUAL(NJson::PrettifyJson("{,,,}"), ""); + } + Y_UNIT_TEST(CompactifyJsonShort) { UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson(""), ""); UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson("null"), "null"); @@ -140,8 +140,8 @@ Y_UNIT_TEST_SUITE(JsonPrettifier) { UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson("[\n { },\n { }\n]", true), "[{},{}]"); UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson("{ }"), "{}"); UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson("{\n 'k' : 'v'\n}", true), "{k:v}"); - } - + } + Y_UNIT_TEST(CompactifyJsonLong) { UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson( "[\n" @@ -154,7 +154,7 @@ Y_UNIT_TEST_SUITE(JsonPrettifier) { "]", true), "[{k:v},{a:b}]"); - UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson( + UNIT_ASSERT_STRINGS_EQUAL(NJson::CompactifyJson( "{\n" " 'k' : 'v',\n" " 'a' : 'b',\n" @@ -201,4 +201,4 @@ Y_UNIT_TEST_SUITE(JsonPrettifier) { true), "{g:{x:{a:{b:c,e:f},q:{x:y}},y:fff}}"); } -} +} diff --git a/library/cpp/json/ut/ya.make b/library/cpp/json/ut/ya.make index 8e0362d84b..8989cbc2e8 100644 --- a/library/cpp/json/ut/ya.make +++ b/library/cpp/json/ut/ya.make @@ -9,7 +9,7 @@ PEERDIR( SRCS( json_reader_fast_ut.cpp json_reader_ut.cpp - json_prettifier_ut.cpp + json_prettifier_ut.cpp json_writer_ut.cpp json_saveload_ut.cpp ) diff --git a/library/cpp/logger/global/rty_formater.cpp b/library/cpp/logger/global/rty_formater.cpp index 305f8470c5..cce0070dcb 100644 --- a/library/cpp/logger/global/rty_formater.cpp +++ b/library/cpp/logger/global/rty_formater.cpp @@ -1,53 +1,53 @@ #include "rty_formater.h" #include <util/datetime/base.h> -#include <util/datetime/systime.h> +#include <util/datetime/systime.h> #include <util/stream/str.h> #include <util/stream/printf.h> #include <util/system/mem_info.h> -#include <util/system/yassert.h> +#include <util/system/yassert.h> #include <inttypes.h> -#include <cstdio> - -namespace { - constexpr size_t LocalTimeSBufferSize = sizeof("2017-07-24 12:20:34.313 +0300"); - - size_t PrintLocalTimeS(const TInstant instant, char* const begin, const char* const end) { - Y_VERIFY(static_cast<size_t>(end - begin) >= LocalTimeSBufferSize); +#include <cstdio> +namespace { + constexpr size_t LocalTimeSBufferSize = sizeof("2017-07-24 12:20:34.313 +0300"); + + size_t PrintLocalTimeS(const TInstant instant, char* const begin, const char* const end) { + Y_VERIFY(static_cast<size_t>(end - begin) >= LocalTimeSBufferSize); + struct tm tm; - instant.LocalTime(&tm); - - // both stftime and sprintf exclude the terminating null byte from the return value + instant.LocalTime(&tm); + + // both stftime and sprintf exclude the terminating null byte from the return value char* pos = begin; - pos += strftime(pos, end - pos, "%Y-%m-%d %H:%M:%S.", &tm); - pos += sprintf(pos, "%03" PRIu32, instant.MilliSecondsOfSecond()); - pos += strftime(pos, end - pos, " %z", &tm); - Y_VERIFY(LocalTimeSBufferSize - 1 == pos - begin); // together with Y_VERIFY above this also implies pos<=end - return (pos - begin); + pos += strftime(pos, end - pos, "%Y-%m-%d %H:%M:%S.", &tm); + pos += sprintf(pos, "%03" PRIu32, instant.MilliSecondsOfSecond()); + pos += strftime(pos, end - pos, " %z", &tm); + Y_VERIFY(LocalTimeSBufferSize - 1 == pos - begin); // together with Y_VERIFY above this also implies pos<=end + return (pos - begin); } -} +} -namespace NLoggingImpl { +namespace NLoggingImpl { IOutputStream& operator<<(IOutputStream& out, TLocalTimeS localTimeS) { - char buffer[LocalTimeSBufferSize]; - size_t len = PrintLocalTimeS(localTimeS.GetInstant(), buffer, buffer + sizeof(buffer)); - out.Write(buffer, len); - return out; - } - - TLocalTimeS::operator TString() const { - TString res; - res.reserve(LocalTimeSBufferSize); - res.ReserveAndResize(PrintLocalTimeS(Instant, res.begin(), res.begin() + res.capacity())); - return res; - } - - TString TLocalTimeS::operator+(const TStringBuf right) const { - TString res(*this); - res += right; - return res; - } - + char buffer[LocalTimeSBufferSize]; + size_t len = PrintLocalTimeS(localTimeS.GetInstant(), buffer, buffer + sizeof(buffer)); + out.Write(buffer, len); + return out; + } + + TLocalTimeS::operator TString() const { + TString res; + res.reserve(LocalTimeSBufferSize); + res.ReserveAndResize(PrintLocalTimeS(Instant, res.begin(), res.begin() + res.capacity())); + return res; + } + + TString TLocalTimeS::operator+(const TStringBuf right) const { + TString res(*this); + res += right; + return res; + } + TStringBuf StripFileName(TStringBuf string) { return string.RNextTok(LOCSLASH_C); } diff --git a/library/cpp/logger/global/rty_formater.h b/library/cpp/logger/global/rty_formater.h index 6532e1d769..637e5ae1a1 100644 --- a/library/cpp/logger/global/rty_formater.h +++ b/library/cpp/logger/global/rty_formater.h @@ -16,30 +16,30 @@ public: ILoggerFormatter* CreateRtyLoggerFormatter(); namespace NLoggingImpl { - class TLocalTimeS { - public: - TLocalTimeS(TInstant instant = TInstant::Now()) - : Instant(instant) - { - } - - TInstant GetInstant() const { - return Instant; - } - - operator TString() const; - TString operator+(TStringBuf right) const; - - private: - TInstant Instant; - }; - + class TLocalTimeS { + public: + TLocalTimeS(TInstant instant = TInstant::Now()) + : Instant(instant) + { + } + + TInstant GetInstant() const { + return Instant; + } + + operator TString() const; + TString operator+(TStringBuf right) const; + + private: + TInstant Instant; + }; + IOutputStream& operator<<(IOutputStream& out, TLocalTimeS localTimeS); - - inline TLocalTimeS GetLocalTimeS() { - return TLocalTimeS(); - } - + + inline TLocalTimeS GetLocalTimeS() { + return TLocalTimeS(); + } + TString GetSystemResources(); TString PrintSystemResources(const NMemInfo::TMemInfo& info); diff --git a/library/cpp/logger/global/rty_formater_ut.cpp b/library/cpp/logger/global/rty_formater_ut.cpp index 551a97c5bf..af1a8a861a 100644 --- a/library/cpp/logger/global/rty_formater_ut.cpp +++ b/library/cpp/logger/global/rty_formater_ut.cpp @@ -1,31 +1,31 @@ -#include "rty_formater.h" - +#include "rty_formater.h" + #include <library/cpp/testing/unittest/registar.h> - -namespace { - const TStringBuf SampleISO8601("2017-07-25T19:26:09.894000+03:00"); - const TStringBuf SampleRtyLog("2017-07-25 19:26:09.894 +0300"); -} - + +namespace { + const TStringBuf SampleISO8601("2017-07-25T19:26:09.894000+03:00"); + const TStringBuf SampleRtyLog("2017-07-25 19:26:09.894 +0300"); +} + Y_UNIT_TEST_SUITE(NLoggingImplTest) { Y_UNIT_TEST(TestTLocalTimeSToStream) { NLoggingImpl::TLocalTimeS lt(TInstant::ParseIso8601Deprecated(SampleISO8601)); - TStringStream ss; - ss << lt; - UNIT_ASSERT_EQUAL(ss.Str(), SampleRtyLog); - } + TStringStream ss; + ss << lt; + UNIT_ASSERT_EQUAL(ss.Str(), SampleRtyLog); + } Y_UNIT_TEST(TestTLocalTimeSToString) { NLoggingImpl::TLocalTimeS lt(TInstant::ParseIso8601Deprecated(SampleISO8601)); - UNIT_ASSERT_EQUAL(TString(lt), SampleRtyLog); - } + UNIT_ASSERT_EQUAL(TString(lt), SampleRtyLog); + } Y_UNIT_TEST(TestTLocalTimeSAddLeft) { NLoggingImpl::TLocalTimeS lt(TInstant::ParseIso8601Deprecated(SampleISO8601)); - TStringBuf suffix("suffix"); - UNIT_ASSERT_EQUAL(lt + suffix, TString(SampleRtyLog) + suffix); - } + TStringBuf suffix("suffix"); + UNIT_ASSERT_EQUAL(lt + suffix, TString(SampleRtyLog) + suffix); + } Y_UNIT_TEST(TestTLocalTimeSAddRight) { NLoggingImpl::TLocalTimeS lt(TInstant::ParseIso8601Deprecated(SampleISO8601)); - TString prefix("prefix"); + TString prefix("prefix"); UNIT_ASSERT_EQUAL(prefix + lt, prefix + SampleRtyLog); - } -} + } +} diff --git a/library/cpp/logger/global/ut/ya.make b/library/cpp/logger/global/ut/ya.make index 8aea38906f..777c4ba22b 100644 --- a/library/cpp/logger/global/ut/ya.make +++ b/library/cpp/logger/global/ut/ya.make @@ -1,15 +1,15 @@ -UNITTEST() - -OWNER(salmin) - -PEERDIR( +UNITTEST() + +OWNER(salmin) + +PEERDIR( library/cpp/logger/global -) - +) + SRCDIR(library/cpp/logger/global) - -SRCS( - rty_formater_ut.cpp -) - -END() + +SRCS( + rty_formater_ut.cpp +) + +END() diff --git a/library/cpp/retry/retry.cpp b/library/cpp/retry/retry.cpp index 92466cdeca..eb589832eb 100644 --- a/library/cpp/retry/retry.cpp +++ b/library/cpp/retry/retry.cpp @@ -5,17 +5,17 @@ void DoWithRetry(std::function<void()> func, TRetryOptions retryOptions) { DoWithRetry(func, retryOptions, true); } - -bool DoWithRetryOnRetCode(std::function<bool()> func, TRetryOptions retryOptions) { - for (ui32 attempt = 0; attempt <= retryOptions.RetryCount; ++attempt) { - if (func()) { - return true; - } + +bool DoWithRetryOnRetCode(std::function<bool()> func, TRetryOptions retryOptions) { + for (ui32 attempt = 0; attempt <= retryOptions.RetryCount; ++attempt) { + if (func()) { + return true; + } auto sleep = retryOptions.SleepFunction; sleep(retryOptions.GetTimeToSleep(attempt)); - } - return false; -} + } + return false; +} TRetryOptions MakeRetryOptions(const NRetry::TRetryOptionsPB& retryOptions) { return TRetryOptions(retryOptions.GetMaxTries(), diff --git a/library/cpp/retry/retry.h b/library/cpp/retry/retry.h index c47ff5070f..d8c70bf099 100644 --- a/library/cpp/retry/retry.h +++ b/library/cpp/retry/retry.h @@ -126,8 +126,8 @@ bool DoWithRetry(std::function<void()> func, TRetryOptions retryOptions, bool th void DoWithRetry(std::function<void()> func, TRetryOptions retryOptions); -bool DoWithRetryOnRetCode(std::function<bool()> func, TRetryOptions retryOptions); - +bool DoWithRetryOnRetCode(std::function<bool()> func, TRetryOptions retryOptions); + Y_DECLARE_PODTYPE(TRetryOptions); TRetryOptions MakeRetryOptions(const NRetry::TRetryOptionsPB& retryOptions); diff --git a/library/cpp/retry/retry_ut.cpp b/library/cpp/retry/retry_ut.cpp index 92153e987e..f9eb58867b 100644 --- a/library/cpp/retry/retry_ut.cpp +++ b/library/cpp/retry/retry_ut.cpp @@ -1,36 +1,36 @@ -#include "retry.h" - +#include "retry.h" + #include <library/cpp/testing/unittest/registar.h> + +namespace { + class TDoOnSecondOrThrow { + public: + ui32 operator()() { + if (attempt++ != 1) { + throw yexception(); + } + return 42; + } -namespace { - class TDoOnSecondOrThrow { - public: - ui32 operator()() { - if (attempt++ != 1) { - throw yexception(); - } - return 42; - } - - private: - ui32 attempt = 0; - }; - - class TDoOnSecondOrFail { - public: - bool operator()() { - return (attempt++ == 1); - } - - private: - ui32 attempt = 0; - }; -} + private: + ui32 attempt = 0; + }; + + class TDoOnSecondOrFail { + public: + bool operator()() { + return (attempt++ == 1); + } + private: + ui32 attempt = 0; + }; +} + Y_UNIT_TEST_SUITE(Retry) { Y_UNIT_TEST(RetryOnExceptionSuccess) { - UNIT_ASSERT_NO_EXCEPTION(DoWithRetry(TDoOnSecondOrThrow{}, TRetryOptions(1, TDuration::Zero()))); - } + UNIT_ASSERT_NO_EXCEPTION(DoWithRetry(TDoOnSecondOrThrow{}, TRetryOptions(1, TDuration::Zero()))); + } Y_UNIT_TEST(RetryOnExceptionSuccessWithOnFail) { ui32 value = 0; std::function<void(const yexception&)> cb = [&value](const yexception&){ value += 1; }; @@ -38,19 +38,19 @@ Y_UNIT_TEST_SUITE(Retry) { UNIT_ASSERT_EQUAL(value, 1); } Y_UNIT_TEST(RetryOnExceptionFail) { - UNIT_ASSERT_EXCEPTION(DoWithRetry(TDoOnSecondOrThrow{}, TRetryOptions(0, TDuration::Zero())), yexception); - } + UNIT_ASSERT_EXCEPTION(DoWithRetry(TDoOnSecondOrThrow{}, TRetryOptions(0, TDuration::Zero())), yexception); + } Y_UNIT_TEST(RetryOnExceptionFailWithOnFail) { ui32 value = 0; std::function<void(const yexception&)> cb = [&value](const yexception&) { value += 1; }; UNIT_ASSERT_EXCEPTION(DoWithRetry<ui32>(TDoOnSecondOrThrow{}, cb, TRetryOptions(0, TDuration::Zero()), true), yexception); UNIT_ASSERT_EQUAL(value, 1); } - + Y_UNIT_TEST(RetryOnExceptionSuccessWithValue) { - std::function<ui32()> f = TDoOnSecondOrThrow{}; - UNIT_ASSERT(42 == *DoWithRetry<ui32>(f, TRetryOptions(1, TDuration::Zero()), false)); - } + std::function<ui32()> f = TDoOnSecondOrThrow{}; + UNIT_ASSERT(42 == *DoWithRetry<ui32>(f, TRetryOptions(1, TDuration::Zero()), false)); + } Y_UNIT_TEST(RetryOnExceptionSuccessWithValueWithOnFail) { ui32 value = 0; std::function<ui32()> f = TDoOnSecondOrThrow{}; @@ -59,9 +59,9 @@ Y_UNIT_TEST_SUITE(Retry) { UNIT_ASSERT_EQUAL(value, 1); } Y_UNIT_TEST(RetryOnExceptionFailWithValue) { - std::function<ui32()> f = TDoOnSecondOrThrow{}; - UNIT_ASSERT(!DoWithRetry<ui32>(f, TRetryOptions(0, TDuration::Zero()), false).Defined()); - } + std::function<ui32()> f = TDoOnSecondOrThrow{}; + UNIT_ASSERT(!DoWithRetry<ui32>(f, TRetryOptions(0, TDuration::Zero()), false).Defined()); + } Y_UNIT_TEST(RetryOnExceptionFailWithValueWithOnFail) { ui32 value = 0; std::function<ui32()> f = TDoOnSecondOrThrow{}; @@ -69,11 +69,11 @@ Y_UNIT_TEST_SUITE(Retry) { UNIT_ASSERT(!DoWithRetry<ui32>(f, cb, TRetryOptions(0, TDuration::Zero()), false).Defined()); UNIT_ASSERT_EQUAL(value, 1); } - + Y_UNIT_TEST(RetryOnExceptionSuccessWithValueAndRethrow) { - std::function<ui32()> f = TDoOnSecondOrThrow{}; - UNIT_ASSERT(42 == *DoWithRetry<ui32>(f, TRetryOptions(1, TDuration::Zero()), true)); - } + std::function<ui32()> f = TDoOnSecondOrThrow{}; + UNIT_ASSERT(42 == *DoWithRetry<ui32>(f, TRetryOptions(1, TDuration::Zero()), true)); + } Y_UNIT_TEST(RetryOnExceptionSuccessWithValueAndRethrowWithOnFail) { ui32 value = 0; std::function<ui32()> f = TDoOnSecondOrThrow{}; @@ -82,9 +82,9 @@ Y_UNIT_TEST_SUITE(Retry) { UNIT_ASSERT_EQUAL(value, 1); } Y_UNIT_TEST(RetryOnExceptionFailWithValueAndRethrow) { - std::function<ui32()> f = TDoOnSecondOrThrow{}; - UNIT_ASSERT_EXCEPTION(DoWithRetry<ui32>(f, TRetryOptions(0, TDuration::Zero()), true), yexception); - } + std::function<ui32()> f = TDoOnSecondOrThrow{}; + UNIT_ASSERT_EXCEPTION(DoWithRetry<ui32>(f, TRetryOptions(0, TDuration::Zero()), true), yexception); + } Y_UNIT_TEST(RetryOnExceptionFailWithValueAndRethrowWithOnFail) { ui32 value = 0; std::function<ui32()> f = TDoOnSecondOrThrow{}; @@ -92,13 +92,13 @@ Y_UNIT_TEST_SUITE(Retry) { UNIT_ASSERT_EXCEPTION(42 == *DoWithRetry<ui32>(f, cb, TRetryOptions(0, TDuration::Zero()), true), yexception); UNIT_ASSERT_EQUAL(value, 1); } - + Y_UNIT_TEST(RetryOnRetCodeSuccess) { - UNIT_ASSERT(true == DoWithRetryOnRetCode(TDoOnSecondOrFail{}, TRetryOptions(1, TDuration::Zero()))); - } + UNIT_ASSERT(true == DoWithRetryOnRetCode(TDoOnSecondOrFail{}, TRetryOptions(1, TDuration::Zero()))); + } Y_UNIT_TEST(RetryOnRetCodeFail) { - UNIT_ASSERT(false == DoWithRetryOnRetCode(TDoOnSecondOrFail{}, TRetryOptions(0, TDuration::Zero()))); - } + UNIT_ASSERT(false == DoWithRetryOnRetCode(TDoOnSecondOrFail{}, TRetryOptions(0, TDuration::Zero()))); + } Y_UNIT_TEST(MakeRetryOptionsFromProto) { NRetry::TRetryOptionsPB protoOptions; protoOptions.SetMaxTries(1); @@ -114,4 +114,4 @@ Y_UNIT_TEST_SUITE(Retry) { UNIT_ASSERT_EQUAL(options.SleepRandomDelta, TDuration::MilliSeconds(4)); UNIT_ASSERT_EQUAL(options.SleepExponentialMultiplier, TDuration::MilliSeconds(5)); } -} +} diff --git a/library/cpp/retry/ut/ya.make b/library/cpp/retry/ut/ya.make index ff8259bfdb..d47f1c5cc3 100644 --- a/library/cpp/retry/ut/ya.make +++ b/library/cpp/retry/ut/ya.make @@ -1,13 +1,13 @@ UNITTEST_FOR(library/cpp/retry) - + OWNER( salmin osado g:yabs-small ) - -SRCS( - retry_ut.cpp -) - -END() + +SRCS( + retry_ut.cpp +) + +END() diff --git a/library/cpp/string_utils/base64/base64.cpp b/library/cpp/string_utils/base64/base64.cpp index 05c201f0de..d368156033 100644 --- a/library/cpp/string_utils/base64/base64.cpp +++ b/library/cpp/string_utils/base64/base64.cpp @@ -95,46 +95,46 @@ static_assert(Y_ARRAY_SIZE(base64_bkw) == 256, "wrong size"); // Base64 for url encoding, RFC3548 static const char base64_etab_url[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; -static inline unsigned char GetBase64EncodedIndex0(unsigned char octet0) { - return (octet0 >> 2); -} - -static inline unsigned char GetBase64EncodedIndex1(unsigned char octet0, unsigned char octet1) { - return (((octet0 << 4) & 0x30) | ((octet1 >> 4) & 0x0f)); -} - -static inline unsigned char GetBase64EncodedIndex2(unsigned char octet1, unsigned char octet2) { - return (((octet1 << 2) & 0x3c) | ((octet2 >> 6) & 0x03)); -} - -static inline unsigned char GetBase64EncodedIndex3(unsigned char octet2) { - return (octet2 & 0x3f); -} - +static inline unsigned char GetBase64EncodedIndex0(unsigned char octet0) { + return (octet0 >> 2); +} + +static inline unsigned char GetBase64EncodedIndex1(unsigned char octet0, unsigned char octet1) { + return (((octet0 << 4) & 0x30) | ((octet1 >> 4) & 0x0f)); +} + +static inline unsigned char GetBase64EncodedIndex2(unsigned char octet1, unsigned char octet2) { + return (((octet1 << 2) & 0x3c) | ((octet2 >> 6) & 0x03)); +} + +static inline unsigned char GetBase64EncodedIndex3(unsigned char octet2) { + return (octet2 & 0x3f); +} + template <bool urlVersion> static inline char* Base64EncodeImpl(char* outstr, const unsigned char* instr, size_t len) { - const char* const base64_etab = (urlVersion ? base64_etab_url : base64_etab_std); - const char pad = (urlVersion ? ',' : '='); + const char* const base64_etab = (urlVersion ? base64_etab_url : base64_etab_std); + const char pad = (urlVersion ? ',' : '='); size_t idx = 0; - while (idx + 2 < len) { - *outstr++ = base64_etab[GetBase64EncodedIndex0(instr[idx])]; - *outstr++ = base64_etab[GetBase64EncodedIndex1(instr[idx], instr[idx + 1])]; - *outstr++ = base64_etab[GetBase64EncodedIndex2(instr[idx + 1], instr[idx + 2])]; - *outstr++ = base64_etab[GetBase64EncodedIndex3(instr[idx + 2])]; - idx += 3; - } - if (idx < len) { - *outstr++ = base64_etab[GetBase64EncodedIndex0(instr[idx])]; - if (idx + 1 < len) { - *outstr++ = base64_etab[GetBase64EncodedIndex1(instr[idx], instr[idx + 1])]; - *outstr++ = base64_etab[GetBase64EncodedIndex2(instr[idx + 1], '\0')]; + while (idx + 2 < len) { + *outstr++ = base64_etab[GetBase64EncodedIndex0(instr[idx])]; + *outstr++ = base64_etab[GetBase64EncodedIndex1(instr[idx], instr[idx + 1])]; + *outstr++ = base64_etab[GetBase64EncodedIndex2(instr[idx + 1], instr[idx + 2])]; + *outstr++ = base64_etab[GetBase64EncodedIndex3(instr[idx + 2])]; + idx += 3; + } + if (idx < len) { + *outstr++ = base64_etab[GetBase64EncodedIndex0(instr[idx])]; + if (idx + 1 < len) { + *outstr++ = base64_etab[GetBase64EncodedIndex1(instr[idx], instr[idx + 1])]; + *outstr++ = base64_etab[GetBase64EncodedIndex2(instr[idx + 1], '\0')]; } else { - *outstr++ = base64_etab[GetBase64EncodedIndex1(instr[idx], '\0')]; - *outstr++ = pad; + *outstr++ = base64_etab[GetBase64EncodedIndex1(instr[idx], '\0')]; + *outstr++ = pad; } - *outstr++ = pad; + *outstr++ = pad; } *outstr = 0; diff --git a/library/cpp/string_utils/base64/bench/main.cpp b/library/cpp/string_utils/base64/bench/main.cpp index 10e09bc1c7..f6da3de328 100644 --- a/library/cpp/string_utils/base64/bench/main.cpp +++ b/library/cpp/string_utils/base64/bench/main.cpp @@ -105,19 +105,19 @@ static inline void BenchEncode(T& d, const NBench::NCpu::TParams& iface) { } template <typename T> -static inline void BenchEncodeUrl(T& d, const NBench::NCpu::TParams& iface) { - for (const auto it : xrange(iface.Iterations())) { - Y_UNUSED(it); - for (size_t i = 0; i < d.Size; ++i) { +static inline void BenchEncodeUrl(T& d, const NBench::NCpu::TParams& iface) { + for (const auto it : xrange(iface.Iterations())) { + Y_UNUSED(it); + for (size_t i = 0; i < d.Size; ++i) { NBench::Escape(d.PlaceToEncode[i].data()); - Y_DO_NOT_OPTIMIZE_AWAY( + Y_DO_NOT_OPTIMIZE_AWAY( Base64EncodeUrl(d.PlaceToEncode[i].data(), (const unsigned char*)d.Data[i].data(), d.Data[i].size())); - NBench::Clobber(); - } - } -} - -template <typename T> + NBench::Clobber(); + } + } +} + +template <typename T> static inline void BenchDecode(T& d, const NBench::NCpu::TParams& iface) { for (const auto it : xrange(iface.Iterations())) { Y_UNUSED(it); @@ -259,68 +259,68 @@ Y_CPU_BENCHMARK(DecodeF10485760, iface) { auto& d = *Singleton<FSRDH_10485760>(); BenchDecode(d, iface); } - -Y_CPU_BENCHMARK(EncodeUrlF1, iface) { - auto& d = *Singleton<FSRDH_1>(); - BenchEncodeUrl(d, iface); -} - -Y_CPU_BENCHMARK(EncodeUrlF2, iface) { - auto& d = *Singleton<FSRDH_2>(); - BenchEncodeUrl(d, iface); -} - -Y_CPU_BENCHMARK(EncodeUrlF4, iface) { - auto& d = *Singleton<FSRDH_4>(); - BenchEncodeUrl(d, iface); -} - -Y_CPU_BENCHMARK(EncodeUrlF8, iface) { - auto& d = *Singleton<FSRDH_8>(); - BenchEncodeUrl(d, iface); -} - -Y_CPU_BENCHMARK(EncodeUrlF16, iface) { - auto& d = *Singleton<FSRDH_16>(); - BenchEncodeUrl(d, iface); -} - -Y_CPU_BENCHMARK(EncodeUrlF32, iface) { - auto& d = *Singleton<FSRDH_32>(); - BenchEncodeUrl(d, iface); -} - -Y_CPU_BENCHMARK(EncodeUrlF64, iface) { - auto& d = *Singleton<FSRDH_64>(); - BenchEncodeUrl(d, iface); -} - -Y_CPU_BENCHMARK(EncodeUrlF128, iface) { - auto& d = *Singleton<FSRDH_128>(); - BenchEncodeUrl(d, iface); -} - -Y_CPU_BENCHMARK(EncodeUrlF1024, iface) { - auto& d = *Singleton<FSRDH_1024>(); - BenchEncodeUrl(d, iface); -} - -Y_CPU_BENCHMARK(EncodeUrlF10240, iface) { - auto& d = *Singleton<FSRDH_10240>(); - BenchEncodeUrl(d, iface); -} - -Y_CPU_BENCHMARK(EncodeUrlF102400, iface) { - auto& d = *Singleton<FSRDH_102400>(); - BenchEncodeUrl(d, iface); -} - -Y_CPU_BENCHMARK(EncodeUrlF1048576, iface) { - auto& d = *Singleton<FSRDH_1048576>(); - BenchEncodeUrl(d, iface); -} - -Y_CPU_BENCHMARK(EncodeUrlF10485760, iface) { - auto& d = *Singleton<FSRDH_10485760>(); - BenchEncodeUrl(d, iface); -} + +Y_CPU_BENCHMARK(EncodeUrlF1, iface) { + auto& d = *Singleton<FSRDH_1>(); + BenchEncodeUrl(d, iface); +} + +Y_CPU_BENCHMARK(EncodeUrlF2, iface) { + auto& d = *Singleton<FSRDH_2>(); + BenchEncodeUrl(d, iface); +} + +Y_CPU_BENCHMARK(EncodeUrlF4, iface) { + auto& d = *Singleton<FSRDH_4>(); + BenchEncodeUrl(d, iface); +} + +Y_CPU_BENCHMARK(EncodeUrlF8, iface) { + auto& d = *Singleton<FSRDH_8>(); + BenchEncodeUrl(d, iface); +} + +Y_CPU_BENCHMARK(EncodeUrlF16, iface) { + auto& d = *Singleton<FSRDH_16>(); + BenchEncodeUrl(d, iface); +} + +Y_CPU_BENCHMARK(EncodeUrlF32, iface) { + auto& d = *Singleton<FSRDH_32>(); + BenchEncodeUrl(d, iface); +} + +Y_CPU_BENCHMARK(EncodeUrlF64, iface) { + auto& d = *Singleton<FSRDH_64>(); + BenchEncodeUrl(d, iface); +} + +Y_CPU_BENCHMARK(EncodeUrlF128, iface) { + auto& d = *Singleton<FSRDH_128>(); + BenchEncodeUrl(d, iface); +} + +Y_CPU_BENCHMARK(EncodeUrlF1024, iface) { + auto& d = *Singleton<FSRDH_1024>(); + BenchEncodeUrl(d, iface); +} + +Y_CPU_BENCHMARK(EncodeUrlF10240, iface) { + auto& d = *Singleton<FSRDH_10240>(); + BenchEncodeUrl(d, iface); +} + +Y_CPU_BENCHMARK(EncodeUrlF102400, iface) { + auto& d = *Singleton<FSRDH_102400>(); + BenchEncodeUrl(d, iface); +} + +Y_CPU_BENCHMARK(EncodeUrlF1048576, iface) { + auto& d = *Singleton<FSRDH_1048576>(); + BenchEncodeUrl(d, iface); +} + +Y_CPU_BENCHMARK(EncodeUrlF10485760, iface) { + auto& d = *Singleton<FSRDH_10485760>(); + BenchEncodeUrl(d, iface); +} diff --git a/library/cpp/testing/unittest/registar.h b/library/cpp/testing/unittest/registar.h index 44517a0092..c2f0d6b1aa 100644 --- a/library/cpp/testing/unittest/registar.h +++ b/library/cpp/testing/unittest/registar.h @@ -506,36 +506,36 @@ public: \ UNIT_FAIL_IMPL("less-than assertion failed", Sprintf("%s < %s %s", #A, #B, (::TStringBuilder() << C).data())); \ } \ } while (false) - -#define UNIT_ASSERT_LT(A, B) UNIT_ASSERT_LT_C(A, B, "") - + +#define UNIT_ASSERT_LT(A, B) UNIT_ASSERT_LT_C(A, B, "") + #define UNIT_ASSERT_LE_C(A, B, C) \ do { \ if (!((A) <= (B))) { \ UNIT_FAIL_IMPL("less-or-equal assertion failed", Sprintf("%s <= %s %s", #A, #B, (::TStringBuilder() << C).data())); \ } \ } while (false) - -#define UNIT_ASSERT_LE(A, B) UNIT_ASSERT_LE_C(A, B, "") - + +#define UNIT_ASSERT_LE(A, B) UNIT_ASSERT_LE_C(A, B, "") + #define UNIT_ASSERT_GT_C(A, B, C) \ do { \ if (!((A) > (B))) { \ UNIT_FAIL_IMPL("greater-than assertion failed", Sprintf("%s > %s %s", #A, #B, (::TStringBuilder() << C).data())); \ } \ } while (false) - -#define UNIT_ASSERT_GT(A, B) UNIT_ASSERT_GT_C(A, B, "") - -#define UNIT_ASSERT_GE_C(A, B, C) \ + +#define UNIT_ASSERT_GT(A, B) UNIT_ASSERT_GT_C(A, B, "") + +#define UNIT_ASSERT_GE_C(A, B, C) \ do { \ if (!((A) >= (B))) { \ UNIT_FAIL_IMPL("greater-or-equal assertion failed", Sprintf("%s >= %s %s", #A, #B, (::TStringBuilder() << C).data())); \ } \ } while (false) - -#define UNIT_ASSERT_GE(A, B) UNIT_ASSERT_GE_C(A, B, "") - + +#define UNIT_ASSERT_GE(A, B) UNIT_ASSERT_GE_C(A, B, "") + #define UNIT_CHECK_GENERATED_EXCEPTION_C(A, E, C) \ do { \ try { \ diff --git a/library/cpp/testing/unittest/registar_ut.cpp b/library/cpp/testing/unittest/registar_ut.cpp index 1f36d53abb..0426f366f2 100644 --- a/library/cpp/testing/unittest/registar_ut.cpp +++ b/library/cpp/testing/unittest/registar_ut.cpp @@ -127,114 +127,114 @@ Y_UNIT_TEST_SUITE(TUnitTestMacroTest) { UNIT_ASSERT_UNEQUAL(33, 50); } - Y_UNIT_TEST(LessThan) { - auto lt = [](auto v1, auto v2) { - UNIT_ASSERT_LT(v1, v2); - }; - - // less than - UNIT_ASSERT_LT(TStringBuf("1"), "2"); - UNIT_ASSERT_LT("2", TString("3")); - UNIT_ASSERT_LT("abc", TString("azz")); - UNIT_ASSERT_LT(2, 4); - UNIT_ASSERT_LT(42ul, static_cast<unsigned short>(48)); - - // equals - UNIT_ASSERT_TEST_FAILS(lt(TStringBuf("2"), "2")); - UNIT_ASSERT_TEST_FAILS(lt("2", TString("2"))); - UNIT_ASSERT_TEST_FAILS(lt("abc", TString("abc"))); - UNIT_ASSERT_TEST_FAILS(lt(2, 2)); - UNIT_ASSERT_TEST_FAILS(lt(42ul, static_cast<unsigned short>(42))); - - // greater than - UNIT_ASSERT_TEST_FAILS(lt(TStringBuf("2"), "1")); - UNIT_ASSERT_TEST_FAILS(lt("3", TString("2"))); - UNIT_ASSERT_TEST_FAILS(lt("azz", TString("abc"))); - UNIT_ASSERT_TEST_FAILS(lt(5, 2)); - UNIT_ASSERT_TEST_FAILS(lt(100ul, static_cast<unsigned short>(42))); - } - - Y_UNIT_TEST(LessOrEqual) { - auto le = [](auto v1, auto v2) { - UNIT_ASSERT_LE(v1, v2); - }; - - // less than - UNIT_ASSERT_LE(TStringBuf("1"), "2"); - UNIT_ASSERT_LE("2", TString("3")); - UNIT_ASSERT_LE("abc", TString("azz")); - UNIT_ASSERT_LE(2, 4); - UNIT_ASSERT_LE(42ul, static_cast<unsigned short>(48)); - - // equals - UNIT_ASSERT_LE(TStringBuf("2"), "2"); - UNIT_ASSERT_LE("2", TString("2")); - UNIT_ASSERT_LE("abc", TString("abc")); - UNIT_ASSERT_LE(2, 2); - UNIT_ASSERT_LE(42ul, static_cast<unsigned short>(42)); - - // greater than - UNIT_ASSERT_TEST_FAILS(le(TStringBuf("2"), "1")); - UNIT_ASSERT_TEST_FAILS(le("3", TString("2"))); - UNIT_ASSERT_TEST_FAILS(le("azz", TString("abc"))); - UNIT_ASSERT_TEST_FAILS(le(5, 2)); - UNIT_ASSERT_TEST_FAILS(le(100ul, static_cast<unsigned short>(42))); - } - - Y_UNIT_TEST(GreaterThan) { - auto gt = [](auto v1, auto v2) { - UNIT_ASSERT_GT(v1, v2); - }; - - // less than - UNIT_ASSERT_TEST_FAILS(gt(TStringBuf("1"), "2")); - UNIT_ASSERT_TEST_FAILS(gt("2", TString("3"))); - UNIT_ASSERT_TEST_FAILS(gt("abc", TString("azz"))); - UNIT_ASSERT_TEST_FAILS(gt(2, 4)); - UNIT_ASSERT_TEST_FAILS(gt(42ul, static_cast<unsigned short>(48))); - - // equals - UNIT_ASSERT_TEST_FAILS(gt(TStringBuf("2"), "2")); - UNIT_ASSERT_TEST_FAILS(gt("2", TString("2"))); - UNIT_ASSERT_TEST_FAILS(gt("abc", TString("abc"))); - UNIT_ASSERT_TEST_FAILS(gt(2, 2)); - UNIT_ASSERT_TEST_FAILS(gt(42ul, static_cast<unsigned short>(42))); - - // greater than - UNIT_ASSERT_GT(TStringBuf("2"), "1"); - UNIT_ASSERT_GT("3", TString("2")); - UNIT_ASSERT_GT("azz", TString("abc")); - UNIT_ASSERT_GT(5, 2); - UNIT_ASSERT_GT(100ul, static_cast<unsigned short>(42)); - } - - Y_UNIT_TEST(GreaterOrEqual) { - auto ge = [](auto v1, auto v2) { - UNIT_ASSERT_GE(v1, v2); - }; - - // less than - UNIT_ASSERT_TEST_FAILS(ge(TStringBuf("1"), "2")); - UNIT_ASSERT_TEST_FAILS(ge("2", TString("3"))); - UNIT_ASSERT_TEST_FAILS(ge("abc", TString("azz"))); - UNIT_ASSERT_TEST_FAILS(ge(2, 4)); - UNIT_ASSERT_TEST_FAILS(ge(42ul, static_cast<unsigned short>(48))); - - // equals - UNIT_ASSERT_GE(TStringBuf("2"), "2"); - UNIT_ASSERT_GE("2", TString("2")); - UNIT_ASSERT_GE("abc", TString("abc")); - UNIT_ASSERT_GE(2, 2); - UNIT_ASSERT_GE(42ul, static_cast<unsigned short>(42)); - - // greater than - UNIT_ASSERT_GE(TStringBuf("2"), "1"); - UNIT_ASSERT_GE("3", TString("2")); - UNIT_ASSERT_GE("azz", TString("abc")); - UNIT_ASSERT_GE(5, 2); - UNIT_ASSERT_GE(100ul, static_cast<unsigned short>(42)); - } - + Y_UNIT_TEST(LessThan) { + auto lt = [](auto v1, auto v2) { + UNIT_ASSERT_LT(v1, v2); + }; + + // less than + UNIT_ASSERT_LT(TStringBuf("1"), "2"); + UNIT_ASSERT_LT("2", TString("3")); + UNIT_ASSERT_LT("abc", TString("azz")); + UNIT_ASSERT_LT(2, 4); + UNIT_ASSERT_LT(42ul, static_cast<unsigned short>(48)); + + // equals + UNIT_ASSERT_TEST_FAILS(lt(TStringBuf("2"), "2")); + UNIT_ASSERT_TEST_FAILS(lt("2", TString("2"))); + UNIT_ASSERT_TEST_FAILS(lt("abc", TString("abc"))); + UNIT_ASSERT_TEST_FAILS(lt(2, 2)); + UNIT_ASSERT_TEST_FAILS(lt(42ul, static_cast<unsigned short>(42))); + + // greater than + UNIT_ASSERT_TEST_FAILS(lt(TStringBuf("2"), "1")); + UNIT_ASSERT_TEST_FAILS(lt("3", TString("2"))); + UNIT_ASSERT_TEST_FAILS(lt("azz", TString("abc"))); + UNIT_ASSERT_TEST_FAILS(lt(5, 2)); + UNIT_ASSERT_TEST_FAILS(lt(100ul, static_cast<unsigned short>(42))); + } + + Y_UNIT_TEST(LessOrEqual) { + auto le = [](auto v1, auto v2) { + UNIT_ASSERT_LE(v1, v2); + }; + + // less than + UNIT_ASSERT_LE(TStringBuf("1"), "2"); + UNIT_ASSERT_LE("2", TString("3")); + UNIT_ASSERT_LE("abc", TString("azz")); + UNIT_ASSERT_LE(2, 4); + UNIT_ASSERT_LE(42ul, static_cast<unsigned short>(48)); + + // equals + UNIT_ASSERT_LE(TStringBuf("2"), "2"); + UNIT_ASSERT_LE("2", TString("2")); + UNIT_ASSERT_LE("abc", TString("abc")); + UNIT_ASSERT_LE(2, 2); + UNIT_ASSERT_LE(42ul, static_cast<unsigned short>(42)); + + // greater than + UNIT_ASSERT_TEST_FAILS(le(TStringBuf("2"), "1")); + UNIT_ASSERT_TEST_FAILS(le("3", TString("2"))); + UNIT_ASSERT_TEST_FAILS(le("azz", TString("abc"))); + UNIT_ASSERT_TEST_FAILS(le(5, 2)); + UNIT_ASSERT_TEST_FAILS(le(100ul, static_cast<unsigned short>(42))); + } + + Y_UNIT_TEST(GreaterThan) { + auto gt = [](auto v1, auto v2) { + UNIT_ASSERT_GT(v1, v2); + }; + + // less than + UNIT_ASSERT_TEST_FAILS(gt(TStringBuf("1"), "2")); + UNIT_ASSERT_TEST_FAILS(gt("2", TString("3"))); + UNIT_ASSERT_TEST_FAILS(gt("abc", TString("azz"))); + UNIT_ASSERT_TEST_FAILS(gt(2, 4)); + UNIT_ASSERT_TEST_FAILS(gt(42ul, static_cast<unsigned short>(48))); + + // equals + UNIT_ASSERT_TEST_FAILS(gt(TStringBuf("2"), "2")); + UNIT_ASSERT_TEST_FAILS(gt("2", TString("2"))); + UNIT_ASSERT_TEST_FAILS(gt("abc", TString("abc"))); + UNIT_ASSERT_TEST_FAILS(gt(2, 2)); + UNIT_ASSERT_TEST_FAILS(gt(42ul, static_cast<unsigned short>(42))); + + // greater than + UNIT_ASSERT_GT(TStringBuf("2"), "1"); + UNIT_ASSERT_GT("3", TString("2")); + UNIT_ASSERT_GT("azz", TString("abc")); + UNIT_ASSERT_GT(5, 2); + UNIT_ASSERT_GT(100ul, static_cast<unsigned short>(42)); + } + + Y_UNIT_TEST(GreaterOrEqual) { + auto ge = [](auto v1, auto v2) { + UNIT_ASSERT_GE(v1, v2); + }; + + // less than + UNIT_ASSERT_TEST_FAILS(ge(TStringBuf("1"), "2")); + UNIT_ASSERT_TEST_FAILS(ge("2", TString("3"))); + UNIT_ASSERT_TEST_FAILS(ge("abc", TString("azz"))); + UNIT_ASSERT_TEST_FAILS(ge(2, 4)); + UNIT_ASSERT_TEST_FAILS(ge(42ul, static_cast<unsigned short>(48))); + + // equals + UNIT_ASSERT_GE(TStringBuf("2"), "2"); + UNIT_ASSERT_GE("2", TString("2")); + UNIT_ASSERT_GE("abc", TString("abc")); + UNIT_ASSERT_GE(2, 2); + UNIT_ASSERT_GE(42ul, static_cast<unsigned short>(42)); + + // greater than + UNIT_ASSERT_GE(TStringBuf("2"), "1"); + UNIT_ASSERT_GE("3", TString("2")); + UNIT_ASSERT_GE("azz", TString("abc")); + UNIT_ASSERT_GE(5, 2); + UNIT_ASSERT_GE(100ul, static_cast<unsigned short>(42)); + } + Y_UNIT_TEST(ValuesEqual) { auto valuesEqual = [](auto v1, auto v2) { UNIT_ASSERT_VALUES_EQUAL(v1, v2); |