diff options
author | Alexander Smirnov <alex@ydb.tech> | 2025-04-16 21:15:40 +0000 |
---|---|---|
committer | Alexander Smirnov <alex@ydb.tech> | 2025-04-16 21:15:40 +0000 |
commit | 86cc1622df88a9a9d1372a0db64faf4db6eb760c (patch) | |
tree | 2f91a47403dc034a0603698db757a656cce74d4d /library/cpp | |
parent | a30e65bc695ebb642c9a25ad7b1c12134171ce30 (diff) | |
parent | 1da0c06adbe3fddcd5cf81c3ff0922a38644c62e (diff) | |
download | ydb-86cc1622df88a9a9d1372a0db64faf4db6eb760c.tar.gz |
Merge branch 'rightlib' into merge-libs-250416-2114
Diffstat (limited to 'library/cpp')
-rw-r--r-- | library/cpp/protobuf/json/ut/proto2json_ut.cpp | 4 | ||||
-rw-r--r-- | library/cpp/yt/string/format-inl.h | 4 | ||||
-rw-r--r-- | library/cpp/yt/string/format.h | 4 | ||||
-rw-r--r-- | library/cpp/yt/string/unittests/format_ut.cpp | 13 |
4 files changed, 19 insertions, 6 deletions
diff --git a/library/cpp/protobuf/json/ut/proto2json_ut.cpp b/library/cpp/protobuf/json/ut/proto2json_ut.cpp index f5bcfac49db..ce7d119be72 100644 --- a/library/cpp/protobuf/json/ut/proto2json_ut.cpp +++ b/library/cpp/protobuf/json/ut/proto2json_ut.cpp @@ -968,10 +968,10 @@ Y_UNIT_TEST(TestMapAsObject) { auto& items = *proto.MutableItems(); items["key1"] = "value1"; - items["key2"] = "value2"; + items[""] = "value2"; items["key3"] = "value3"; - TString modelStr(R"_({"Items":{"key3":"value3","key2":"value2","key1":"value1"}})_"); + TString modelStr(R"_({"Items":{"key3":"value3","":"value2","key1":"value1"}})_"); TStringStream jsonStr; TProto2JsonConfig config; diff --git a/library/cpp/yt/string/format-inl.h b/library/cpp/yt/string/format-inl.h index 01214399e8e..5b49fc5925c 100644 --- a/library/cpp/yt/string/format-inl.h +++ b/library/cpp/yt/string/format-inl.h @@ -316,7 +316,7 @@ typename TFormattableView<TRange, TFormatter>::TEnd TFormattableView<TRange, TFo } template <class TRange, class TFormatter> -TFormattableView<TRange, TFormatter> MakeFormattableView( +TFormattableView<TRange, std::decay_t<TFormatter>> MakeFormattableView( const TRange& range, TFormatter&& formatter) { @@ -324,7 +324,7 @@ TFormattableView<TRange, TFormatter> MakeFormattableView( } template <class TRange, class TFormatter> -TFormattableView<TRange, TFormatter> MakeShrunkFormattableView( +TFormattableView<TRange, std::decay_t<TFormatter>> MakeShrunkFormattableView( const TRange& range, TFormatter&& formatter, size_t limit) diff --git a/library/cpp/yt/string/format.h b/library/cpp/yt/string/format.h index d15127fae05..fa45f39e5ac 100644 --- a/library/cpp/yt/string/format.h +++ b/library/cpp/yt/string/format.h @@ -91,12 +91,12 @@ struct TFormattableView //! Annotates a given #range with #formatter to be applied to each item. template <class TRange, class TFormatter> -TFormattableView<TRange, TFormatter> MakeFormattableView( +TFormattableView<TRange, std::decay_t<TFormatter>> MakeFormattableView( const TRange& range, TFormatter&& formatter); template <class TRange, class TFormatter> -TFormattableView<TRange, TFormatter> MakeShrunkFormattableView( +TFormattableView<TRange, std::decay_t<TFormatter>> MakeShrunkFormattableView( const TRange& range, TFormatter&& formatter, size_t limit); diff --git a/library/cpp/yt/string/unittests/format_ut.cpp b/library/cpp/yt/string/unittests/format_ut.cpp index e2e23c737c2..a6c5ef6837f 100644 --- a/library/cpp/yt/string/unittests/format_ut.cpp +++ b/library/cpp/yt/string/unittests/format_ut.cpp @@ -267,6 +267,19 @@ TEST(TFormatTest, LazyMultiValueFormatter) EXPECT_EQ("int: 1, string: hello, range: [1, 2, 3]", Format("%v", lazyFormatter)); } +TEST(TFormatTest, ReusableLambdaFormatter) +{ + auto formatter = [&] (auto* builder, int value) { + builder->AppendFormat("%v", value); + }; + + std::vector<int> range1{1, 2, 3}; + EXPECT_EQ("[1, 2, 3]", Format("%v", MakeFormattableView(range1, formatter))); + + std::vector<int> range2{4, 5, 6}; + EXPECT_EQ("[4, 5, 6]", Format("%v", MakeFormattableView(range2, formatter))); +} + TEST(TFormatTest, VectorArg) { std::vector<TString> params = {"a", "b", "c"}; |