diff options
author | art-snake <art-snake@yandex-team.ru> | 2022-02-10 16:50:34 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:34 +0300 |
commit | 1700010e2088971894d12a7a16d6004866f986fd (patch) | |
tree | ac3b38289119375037d595858db9751013220a3f /library/cpp/protobuf/json/ut | |
parent | 785bc0acdf3b0c63f971ee17e845945d7381dcb7 (diff) | |
download | ydb-1700010e2088971894d12a7a16d6004866f986fd.tar.gz |
Restoring authorship annotation for <art-snake@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/protobuf/json/ut')
-rw-r--r-- | library/cpp/protobuf/json/ut/json2proto_ut.cpp | 136 | ||||
-rw-r--r-- | library/cpp/protobuf/json/ut/proto2json_ut.cpp | 114 | ||||
-rw-r--r-- | library/cpp/protobuf/json/ut/test.proto | 32 |
3 files changed, 141 insertions, 141 deletions
diff --git a/library/cpp/protobuf/json/ut/json2proto_ut.cpp b/library/cpp/protobuf/json/ut/json2proto_ut.cpp index 0dfe57bc7a2..081072971c6 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"( { diff --git a/library/cpp/protobuf/json/ut/proto2json_ut.cpp b/library/cpp/protobuf/json/ut/proto2json_ut.cpp index 07e52d7f2f5..6ae7960bb13 100644 --- a/library/cpp/protobuf/json/ut/proto2json_ut.cpp +++ b/library/cpp/protobuf/json/ut/proto2json_ut.cpp @@ -465,52 +465,52 @@ Y_UNIT_TEST(TestMissingSingleKeyConfig) { UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, json, config)); UNIT_ASSERT_JSONS_EQUAL(json, modelJson); } - { - // Test MissingKeyExplicitDefaultThrowRequired for non explicit default values. - TFlatOptional proto; - NJson::TJsonValue modelJson(NJson::JSON_MAP); - NJson::TJsonValue json; - TProto2JsonConfig config; - config.MissingSingleKeyMode = TProto2JsonConfig::MissingKeyExplicitDefaultThrowRequired; - - UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, json, config)); - UNIT_ASSERT_JSONS_EQUAL(json, modelJson); - } - { - // Test MissingKeyExplicitDefaultThrowRequired for explicit default values. - NJson::TJsonValue modelJson; - modelJson["String"] = "value"; - - TSingleDefaultString proto; - NJson::TJsonValue json; - TProto2JsonConfig config; - config.MissingSingleKeyMode = TProto2JsonConfig::MissingKeyExplicitDefaultThrowRequired; - UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, json, config)); - UNIT_ASSERT_JSONS_EQUAL(json, modelJson); - } - { - // Test MissingKeyExplicitDefaultThrowRequired for empty required values. - TFlatRequired proto; - NJson::TJsonValue json; - TProto2JsonConfig config; - config.MissingSingleKeyMode = TProto2JsonConfig::MissingKeyExplicitDefaultThrowRequired; - UNIT_ASSERT_EXCEPTION_CONTAINS(Proto2Json(proto, json, config), yexception, "Empty required protobuf field"); - } - { - // Test MissingKeyExplicitDefaultThrowRequired for required value. - TSingleRequiredString proto; - NJson::TJsonValue json; - TProto2JsonConfig config; - config.MissingSingleKeyMode = TProto2JsonConfig::MissingKeyExplicitDefaultThrowRequired; - - UNIT_ASSERT_EXCEPTION_CONTAINS(Proto2Json(proto, json, config), yexception, "Empty required protobuf field"); - - NJson::TJsonValue modelJson; - modelJson["String"] = "value"; - proto.SetString("value"); - UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, json, config)); - UNIT_ASSERT_JSONS_EQUAL(json, modelJson); - } + { + // Test MissingKeyExplicitDefaultThrowRequired for non explicit default values. + TFlatOptional proto; + NJson::TJsonValue modelJson(NJson::JSON_MAP); + NJson::TJsonValue json; + TProto2JsonConfig config; + config.MissingSingleKeyMode = TProto2JsonConfig::MissingKeyExplicitDefaultThrowRequired; + + UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, json, config)); + UNIT_ASSERT_JSONS_EQUAL(json, modelJson); + } + { + // Test MissingKeyExplicitDefaultThrowRequired for explicit default values. + NJson::TJsonValue modelJson; + modelJson["String"] = "value"; + + TSingleDefaultString proto; + NJson::TJsonValue json; + TProto2JsonConfig config; + config.MissingSingleKeyMode = TProto2JsonConfig::MissingKeyExplicitDefaultThrowRequired; + UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, json, config)); + UNIT_ASSERT_JSONS_EQUAL(json, modelJson); + } + { + // Test MissingKeyExplicitDefaultThrowRequired for empty required values. + TFlatRequired proto; + NJson::TJsonValue json; + TProto2JsonConfig config; + config.MissingSingleKeyMode = TProto2JsonConfig::MissingKeyExplicitDefaultThrowRequired; + UNIT_ASSERT_EXCEPTION_CONTAINS(Proto2Json(proto, json, config), yexception, "Empty required protobuf field"); + } + { + // Test MissingKeyExplicitDefaultThrowRequired for required value. + TSingleRequiredString proto; + NJson::TJsonValue json; + TProto2JsonConfig config; + config.MissingSingleKeyMode = TProto2JsonConfig::MissingKeyExplicitDefaultThrowRequired; + + UNIT_ASSERT_EXCEPTION_CONTAINS(Proto2Json(proto, json, config), yexception, "Empty required protobuf field"); + + NJson::TJsonValue modelJson; + modelJson["String"] = "value"; + proto.SetString("value"); + UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, json, config)); + UNIT_ASSERT_JSONS_EQUAL(json, modelJson); + } } // TestMissingSingleKeyConfig Y_UNIT_TEST(TestMissingRepeatedKeyNoConfig) { @@ -551,17 +551,17 @@ Y_UNIT_TEST(TestMissingRepeatedKeyConfig) { UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, json, config)); UNIT_ASSERT_JSONS_EQUAL(json, modelJson); } - { - TFlatRepeated proto; - NJson::TJsonValue modelJson(NJson::JSON_MAP); - NJson::TJsonValue json; - TProto2JsonConfig config; - config.MissingRepeatedKeyMode = TProto2JsonConfig::MissingKeyExplicitDefaultThrowRequired; - - // SHould be same as MissingKeySkip - UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, json, config)); - UNIT_ASSERT_JSONS_EQUAL(json, modelJson); - } + { + TFlatRepeated proto; + NJson::TJsonValue modelJson(NJson::JSON_MAP); + NJson::TJsonValue json; + TProto2JsonConfig config; + config.MissingRepeatedKeyMode = TProto2JsonConfig::MissingKeyExplicitDefaultThrowRequired; + + // SHould be same as MissingKeySkip + UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, json, config)); + UNIT_ASSERT_JSONS_EQUAL(json, modelJson); + } } // TestMissingRepeatedKeyConfig Y_UNIT_TEST(TestEscaping) { diff --git a/library/cpp/protobuf/json/ut/test.proto b/library/cpp/protobuf/json/ut/test.proto index 0fa996fd413..8cf7bf8a5d8 100644 --- a/library/cpp/protobuf/json/ut/test.proto +++ b/library/cpp/protobuf/json/ut/test.proto @@ -177,22 +177,22 @@ message TWithJsonName { optional int32 Def_upper = 3; // json_name = "DefUpper" optional int32 def_lower = 4; // json_name = "defLower" } - -message TSingleRequiredString { - required string String = 1; -} - -message TSingleDefaultString { - optional string String = 1 [default = "value"]; -} - -message TSingleRepeatedString { - repeated string RepeatedString = 1; -} - -message TSingleRepeatedInt { - repeated int32 RepeatedInt = 1; -} + +message TSingleRequiredString { + required string String = 1; +} + +message TSingleDefaultString { + optional string String = 1 [default = "value"]; +} + +message TSingleRepeatedString { + repeated string RepeatedString = 1; +} + +message TSingleRepeatedInt { + repeated int32 RepeatedInt = 1; +} message TExtensionField { extensions 100 to 199; |