diff options
author | art-snake <art-snake@yandex-team.ru> | 2022-02-10 16:50:35 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:35 +0300 |
commit | dc5517df41fe6319ff249956fe5650e4bbc3e660 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/protobuf/json/ut/json2proto_ut.cpp | |
parent | 1700010e2088971894d12a7a16d6004866f986fd (diff) | |
download | ydb-dc5517df41fe6319ff249956fe5650e4bbc3e660.tar.gz |
Restoring authorship annotation for <art-snake@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/protobuf/json/ut/json2proto_ut.cpp')
-rw-r--r-- | library/cpp/protobuf/json/ut/json2proto_ut.cpp | 136 |
1 files changed, 68 insertions, 68 deletions
diff --git a/library/cpp/protobuf/json/ut/json2proto_ut.cpp b/library/cpp/protobuf/json/ut/json2proto_ut.cpp index 081072971c..0dfe57bc7a 100644 --- a/library/cpp/protobuf/json/ut/json2proto_ut.cpp +++ b/library/cpp/protobuf/json/ut/json2proto_ut.cpp @@ -690,57 +690,57 @@ Y_UNIT_TEST(TestVectorizeScalars) { #undef DEFINE_FIELD } -Y_UNIT_TEST(TestValueVectorizer) { - { - // No ValueVectorizer - NJson::TJsonValue json; - json["RepeatedString"] = "123"; - TJson2ProtoConfig config; - TSingleRepeatedString expected; - UNIT_ASSERT_EXCEPTION(Json2Proto(json, expected, config), yexception); - } - { - // ValueVectorizer replace original value by array - NJson::TJsonValue json; - json["RepeatedString"] = "123"; - TJson2ProtoConfig config; - - TSingleRepeatedString expected; - expected.AddRepeatedString("4"); - expected.AddRepeatedString("5"); - expected.AddRepeatedString("6"); - - config.ValueVectorizer = [](const NJson::TJsonValue& val) -> NJson::TJsonValue::TArray { - Y_UNUSED(val); - return {NJson::TJsonValue("4"), NJson::TJsonValue("5"), NJson::TJsonValue("6")}; - }; - TSingleRepeatedString actual; - Json2Proto(json, actual, config); - UNIT_ASSERT_PROTOS_EQUAL(expected, actual); - } - { - // ValueVectorizer replace original value by array and cast - NJson::TJsonValue json; - json["RepeatedInt"] = 123; - TJson2ProtoConfig config; - - TSingleRepeatedInt expected; - expected.AddRepeatedInt(4); - expected.AddRepeatedInt(5); - expected.AddRepeatedInt(6); - - config.ValueVectorizer = [](const NJson::TJsonValue& val) -> NJson::TJsonValue::TArray { - Y_UNUSED(val); - return {NJson::TJsonValue("4"), NJson::TJsonValue(5), NJson::TJsonValue("6")}; - }; - config.CastFromString = true; - - TSingleRepeatedInt actual; - Json2Proto(json, actual, config); - UNIT_ASSERT_PROTOS_EQUAL(expected, actual); - } -} - +Y_UNIT_TEST(TestValueVectorizer) { + { + // No ValueVectorizer + NJson::TJsonValue json; + json["RepeatedString"] = "123"; + TJson2ProtoConfig config; + TSingleRepeatedString expected; + UNIT_ASSERT_EXCEPTION(Json2Proto(json, expected, config), yexception); + } + { + // ValueVectorizer replace original value by array + NJson::TJsonValue json; + json["RepeatedString"] = "123"; + TJson2ProtoConfig config; + + TSingleRepeatedString expected; + expected.AddRepeatedString("4"); + expected.AddRepeatedString("5"); + expected.AddRepeatedString("6"); + + config.ValueVectorizer = [](const NJson::TJsonValue& val) -> NJson::TJsonValue::TArray { + Y_UNUSED(val); + return {NJson::TJsonValue("4"), NJson::TJsonValue("5"), NJson::TJsonValue("6")}; + }; + TSingleRepeatedString actual; + Json2Proto(json, actual, config); + UNIT_ASSERT_PROTOS_EQUAL(expected, actual); + } + { + // ValueVectorizer replace original value by array and cast + NJson::TJsonValue json; + json["RepeatedInt"] = 123; + TJson2ProtoConfig config; + + TSingleRepeatedInt expected; + expected.AddRepeatedInt(4); + expected.AddRepeatedInt(5); + expected.AddRepeatedInt(6); + + config.ValueVectorizer = [](const NJson::TJsonValue& val) -> NJson::TJsonValue::TArray { + Y_UNUSED(val); + return {NJson::TJsonValue("4"), NJson::TJsonValue(5), NJson::TJsonValue("6")}; + }; + config.CastFromString = true; + + TSingleRepeatedInt actual; + Json2Proto(json, actual, config); + UNIT_ASSERT_PROTOS_EQUAL(expected, actual); + } +} + Y_UNIT_TEST(TestMapAsObject) { TMapType modelProto; @@ -1103,23 +1103,23 @@ Y_UNIT_TEST(TestMergeRepeatedAppend) { UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto); } // TestMergeRepeatedAppend -Y_UNIT_TEST(TestEmptyStringForCastFromString) { - NJson::TJsonValue json; - json["I32"] = ""; - json["Bool"] = ""; - json["OneString"] = ""; - - TJson2ProtoConfig config; - config.SetCastFromString(true); - config.SetDoNotCastEmptyStrings(true); - TFlatOptional proto; - UNIT_ASSERT_NO_EXCEPTION(Json2Proto(json, proto, config)); - UNIT_ASSERT(!proto.HasBool()); - UNIT_ASSERT(!proto.HasI32()); - UNIT_ASSERT(proto.HasOneString()); - UNIT_ASSERT_EQUAL("", proto.GetOneString()); -} // TestEmptyStringForCastFromString - +Y_UNIT_TEST(TestEmptyStringForCastFromString) { + NJson::TJsonValue json; + json["I32"] = ""; + json["Bool"] = ""; + json["OneString"] = ""; + + TJson2ProtoConfig config; + config.SetCastFromString(true); + config.SetDoNotCastEmptyStrings(true); + TFlatOptional proto; + UNIT_ASSERT_NO_EXCEPTION(Json2Proto(json, proto, config)); + UNIT_ASSERT(!proto.HasBool()); + UNIT_ASSERT(!proto.HasI32()); + UNIT_ASSERT(proto.HasOneString()); + UNIT_ASSERT_EQUAL("", proto.GetOneString()); +} // TestEmptyStringForCastFromString + Y_UNIT_TEST(TestAllowComments) { constexpr TStringBuf json = R"( { |