diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:17 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:17 +0300 |
commit | d3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch) | |
tree | dd4bd3ca0f36b817e96812825ffaf10d645803f2 /library/cpp/protobuf/json/ut/inline_ut.cpp | |
parent | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff) | |
download | ydb-d3a398281c6fd1d3672036cb2d63f842d2cb28c5.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/protobuf/json/ut/inline_ut.cpp')
-rw-r--r-- | library/cpp/protobuf/json/ut/inline_ut.cpp | 158 |
1 files changed, 79 insertions, 79 deletions
diff --git a/library/cpp/protobuf/json/ut/inline_ut.cpp b/library/cpp/protobuf/json/ut/inline_ut.cpp index 0960de3220..c29ad32e7d 100644 --- a/library/cpp/protobuf/json/ut/inline_ut.cpp +++ b/library/cpp/protobuf/json/ut/inline_ut.cpp @@ -24,99 +24,99 @@ static NProtobufJsonUt::TInlineTest GetTestMsg() { Y_UNIT_TEST_SUITE(TProto2JsonInlineTest){ Y_UNIT_TEST(TestNormalPrint){ NProtobufJsonUt::TInlineTest msg = GetTestMsg(); -// normal print should output these fields as just string values -TString expRaw = R"({"OptJson":"{\"a\":1,\"b\":\"000\"}","NotJson":"12{}34","RepJson":["{}","[1,2]"],)" - R"("Inner":{"Number":[100,200],"InnerJson":"{\"xxx\":[]}"}})"; -TString myRaw; -Proto2Json(msg, myRaw); -UNIT_ASSERT_STRINGS_EQUAL(myRaw, expRaw); - -myRaw = PrintInlined(msg, [](const NProtoBuf::Message&, const NProtoBuf::FieldDescriptor*) { return false; }); -UNIT_ASSERT_STRINGS_EQUAL(myRaw, expRaw); // result is the same -} +// normal print should output these fields as just string values +TString expRaw = R"({"OptJson":"{\"a\":1,\"b\":\"000\"}","NotJson":"12{}34","RepJson":["{}","[1,2]"],)" + R"("Inner":{"Number":[100,200],"InnerJson":"{\"xxx\":[]}"}})"; +TString myRaw; +Proto2Json(msg, myRaw); +UNIT_ASSERT_STRINGS_EQUAL(myRaw, expRaw); + +myRaw = PrintInlined(msg, [](const NProtoBuf::Message&, const NProtoBuf::FieldDescriptor*) { return false; }); +UNIT_ASSERT_STRINGS_EQUAL(myRaw, expRaw); // result is the same +} Y_UNIT_TEST(TestInliningPrinter) { - NProtobufJsonUt::TInlineTest msg = GetTestMsg(); - // inlined print should output these fields as inlined json sub-objects - TString expInlined = R"({"OptJson":{"a":1,"b":"000"},"NotJson":"12{}34","RepJson":[{},[1,2]],)" - R"("Inner":{"Number":[100,200],"InnerJson":{"xxx":[]}}})"; - - { - TString myInlined = PrintInlined(msg, MakeFieldOptionFunctor(NProtobufJsonUt::inline_test)); - UNIT_ASSERT_STRINGS_EQUAL(myInlined, expInlined); + NProtobufJsonUt::TInlineTest msg = GetTestMsg(); + // inlined print should output these fields as inlined json sub-objects + TString expInlined = R"({"OptJson":{"a":1,"b":"000"},"NotJson":"12{}34","RepJson":[{},[1,2]],)" + R"("Inner":{"Number":[100,200],"InnerJson":{"xxx":[]}}})"; + + { + TString myInlined = PrintInlined(msg, MakeFieldOptionFunctor(NProtobufJsonUt::inline_test)); + UNIT_ASSERT_STRINGS_EQUAL(myInlined, expInlined); } - { - auto functor = [](const NProtoBuf::Message&, const NProtoBuf::FieldDescriptor* field) { - return field->name() == "OptJson" || field->name() == "RepJson" || field->name() == "InnerJson"; - }; - TString myInlined = PrintInlined(msg, functor); - UNIT_ASSERT_STRINGS_EQUAL(myInlined, expInlined); - } -} + { + auto functor = [](const NProtoBuf::Message&, const NProtoBuf::FieldDescriptor* field) { + return field->name() == "OptJson" || field->name() == "RepJson" || field->name() == "InnerJson"; + }; + TString myInlined = PrintInlined(msg, functor); + UNIT_ASSERT_STRINGS_EQUAL(myInlined, expInlined); + } +} Y_UNIT_TEST(TestNoValues) { - // no values - no printing - NProtobufJsonUt::TInlineTest msg; - msg.MutableInner()->AddNumber(100); - msg.MutableInner()->AddNumber(200); + // no values - no printing + NProtobufJsonUt::TInlineTest msg; + msg.MutableInner()->AddNumber(100); + msg.MutableInner()->AddNumber(200); - TString expInlined = R"({"Inner":{"Number":[100,200]}})"; + TString expInlined = R"({"Inner":{"Number":[100,200]}})"; - TString myInlined = PrintInlined(msg, MakeFieldOptionFunctor(NProtobufJsonUt::inline_test)); - UNIT_ASSERT_STRINGS_EQUAL(myInlined, expInlined); -} + TString myInlined = PrintInlined(msg, MakeFieldOptionFunctor(NProtobufJsonUt::inline_test)); + UNIT_ASSERT_STRINGS_EQUAL(myInlined, expInlined); +} Y_UNIT_TEST(TestMissingKeyModeNull) { - NProtobufJsonUt::TInlineTest msg; - msg.MutableInner()->AddNumber(100); - msg.MutableInner()->AddNumber(200); + NProtobufJsonUt::TInlineTest msg; + msg.MutableInner()->AddNumber(100); + msg.MutableInner()->AddNumber(200); - TString expInlined = R"({"OptJson":null,"NotJson":null,"RepJson":null,"Inner":{"Number":[100,200],"InnerJson":null}})"; + TString expInlined = R"({"OptJson":null,"NotJson":null,"RepJson":null,"Inner":{"Number":[100,200],"InnerJson":null}})"; - TProto2JsonConfig cfg; - cfg.SetMissingSingleKeyMode(TProto2JsonConfig::MissingKeyNull).SetMissingRepeatedKeyMode(TProto2JsonConfig::MissingKeyNull); - TString myInlined = PrintInlined(msg, MakeFieldOptionFunctor(NProtobufJsonUt::inline_test), cfg); - UNIT_ASSERT_STRINGS_EQUAL(myInlined, expInlined); -} + TProto2JsonConfig cfg; + cfg.SetMissingSingleKeyMode(TProto2JsonConfig::MissingKeyNull).SetMissingRepeatedKeyMode(TProto2JsonConfig::MissingKeyNull); + TString myInlined = PrintInlined(msg, MakeFieldOptionFunctor(NProtobufJsonUt::inline_test), cfg); + UNIT_ASSERT_STRINGS_EQUAL(myInlined, expInlined); +} Y_UNIT_TEST(TestMissingKeyModeDefault) { - NProtobufJsonUt::TInlineTestDefaultValues msg; + NProtobufJsonUt::TInlineTestDefaultValues msg; - TString expInlined = R"({"OptJson":{"default":1},"Number":0,"RepJson":[],"Inner":{"OptJson":{"default":2}}})"; + TString expInlined = R"({"OptJson":{"default":1},"Number":0,"RepJson":[],"Inner":{"OptJson":{"default":2}}})"; - TProto2JsonConfig cfg; - cfg.SetMissingSingleKeyMode(TProto2JsonConfig::MissingKeyDefault).SetMissingRepeatedKeyMode(TProto2JsonConfig::MissingKeyDefault); - TString myInlined = PrintInlined(msg, MakeFieldOptionFunctor(NProtobufJsonUt::inline_test), cfg); - UNIT_ASSERT_STRINGS_EQUAL(myInlined, expInlined); -} + TProto2JsonConfig cfg; + cfg.SetMissingSingleKeyMode(TProto2JsonConfig::MissingKeyDefault).SetMissingRepeatedKeyMode(TProto2JsonConfig::MissingKeyDefault); + TString myInlined = PrintInlined(msg, MakeFieldOptionFunctor(NProtobufJsonUt::inline_test), cfg); + UNIT_ASSERT_STRINGS_EQUAL(myInlined, expInlined); +} Y_UNIT_TEST(NoUnnecessaryCopyFunctor) { - size_t CopyCount = 0; - struct TFunctorMock { - TFunctorMock(size_t* copyCount) - : CopyCount(copyCount) - { - UNIT_ASSERT(*CopyCount <= 1); - } - - TFunctorMock(const TFunctorMock& f) - : CopyCount(f.CopyCount) - { - ++*CopyCount; - } - - TFunctorMock(TFunctorMock&& f) = default; - - bool operator()(const NProtoBuf::Message&, const NProtoBuf::FieldDescriptor*) const { - return false; - } - - size_t* CopyCount; - }; - - TProto2JsonConfig cfg; - TInliningPrinter<> printer(TFunctorMock(&CopyCount), cfg); - UNIT_ASSERT(CopyCount <= 1); -} -} -; + size_t CopyCount = 0; + struct TFunctorMock { + TFunctorMock(size_t* copyCount) + : CopyCount(copyCount) + { + UNIT_ASSERT(*CopyCount <= 1); + } + + TFunctorMock(const TFunctorMock& f) + : CopyCount(f.CopyCount) + { + ++*CopyCount; + } + + TFunctorMock(TFunctorMock&& f) = default; + + bool operator()(const NProtoBuf::Message&, const NProtoBuf::FieldDescriptor*) const { + return false; + } + + size_t* CopyCount; + }; + + TProto2JsonConfig cfg; + TInliningPrinter<> printer(TFunctorMock(&CopyCount), cfg); + UNIT_ASSERT(CopyCount <= 1); +} +} +; |