diff options
author | stakanviski <stakanviski@yandex-team.ru> | 2022-02-10 16:50:01 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:01 +0300 |
commit | 95ab23a39b5482a434361566cabdd5b0a433cb43 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/protobuf/json/ut | |
parent | da8356a5535e6177965cba3bbae73c5fb28f6ccc (diff) | |
download | ydb-95ab23a39b5482a434361566cabdd5b0a433cb43.tar.gz |
Restoring authorship annotation for <stakanviski@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/protobuf/json/ut')
-rw-r--r-- | library/cpp/protobuf/json/ut/fields.incl | 4 | ||||
-rw-r--r-- | library/cpp/protobuf/json/ut/json2proto_ut.cpp | 70 | ||||
-rw-r--r-- | library/cpp/protobuf/json/ut/proto2json_ut.cpp | 22 | ||||
-rw-r--r-- | library/cpp/protobuf/json/ut/test.proto | 30 | ||||
-rw-r--r-- | library/cpp/protobuf/json/ut/ya.make | 4 |
5 files changed, 65 insertions, 65 deletions
diff --git a/library/cpp/protobuf/json/ut/fields.incl b/library/cpp/protobuf/json/ut/fields.incl index d848f614cd..4b22985836 100644 --- a/library/cpp/protobuf/json/ut/fields.incl +++ b/library/cpp/protobuf/json/ut/fields.incl @@ -17,7 +17,7 @@ DEFINE_FIELD(Bytes, "מחשב") DEFINE_FIELD(Enum, E_1) DEFINE_FIELD(Float, 1.123f) DEFINE_FIELD(Double, 1.123456789012) -DEFINE_FIELD(OneString, "Lorem ipsum dolor") -DEFINE_FIELD(OneTwoString, "Lorem ipsum dolor sit") +DEFINE_FIELD(OneString, "Lorem ipsum dolor") +DEFINE_FIELD(OneTwoString, "Lorem ipsum dolor sit") DEFINE_FIELD(ABC, "abc") DEFINE_FIELD(UserID, "some_id")
\ No newline at end of file diff --git a/library/cpp/protobuf/json/ut/json2proto_ut.cpp b/library/cpp/protobuf/json/ut/json2proto_ut.cpp index 55dd9f18cb..0dfe57bc7a 100644 --- a/library/cpp/protobuf/json/ut/json2proto_ut.cpp +++ b/library/cpp/protobuf/json/ut/json2proto_ut.cpp @@ -16,7 +16,7 @@ #include <util/generic/string.h> #include <util/generic/ylimits.h> #include <util/stream/str.h> -#include <util/string/cast.h> +#include <util/string/cast.h> #include <util/system/defaults.h> #include <util/system/yassert.h> @@ -33,7 +33,7 @@ namespace google { } // namespace protobuf } -namespace { +namespace { class TInit { public: TInit() { @@ -41,15 +41,15 @@ namespace { } } Init; - template <typename T> - TString ConvertToString(T value) { - return ToString(value); - } - - // default ToString<double>() implementation loses precision - TString ConvertToString(double value) { - return FloatToString(value); - } + template <typename T> + TString ConvertToString(T value) { + return ToString(value); + } + + // default ToString<double>() implementation loses precision + TString ConvertToString(double value) { + return FloatToString(value); + } TString JsonValueToString(const NJson::TJsonValue& json) { NJsonWriter::TBuf buf(NJsonWriter::HEM_UNSAFE); @@ -68,8 +68,8 @@ namespace { UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto); } -} - +} + Y_UNIT_TEST_SUITE(TJson2ProtoTest) { Y_UNIT_TEST(TestFlatOptional){ {const NJson::TJsonValue& json = CreateFlatJson(); @@ -369,35 +369,35 @@ Y_UNIT_TEST(TestFieldNameMode) { // Camelcase { TString modelStr(R"_({"string":"value"})_"); - + TFlatOptional proto; TJson2ProtoConfig config; config.FieldNameMode = TJson2ProtoConfig::FieldNameCamelCase; - + UNIT_ASSERT_NO_EXCEPTION(proto = Json2Proto<TFlatOptional>(modelStr, config)); UNIT_ASSERT(proto.GetString() == "value"); } { TString modelStr(R"_({"oneString":"value"})_"); - + TFlatOptional proto; TJson2ProtoConfig config; config.FieldNameMode = TJson2ProtoConfig::FieldNameCamelCase; - + UNIT_ASSERT_NO_EXCEPTION(proto = Json2Proto<TFlatOptional>(modelStr, config)); UNIT_ASSERT(proto.GetOneString() == "value"); } { TString modelStr(R"_({"oneTwoString":"value"})_"); - + TFlatOptional proto; TJson2ProtoConfig config; config.FieldNameMode = TJson2ProtoConfig::FieldNameCamelCase; - + UNIT_ASSERT_NO_EXCEPTION(proto = Json2Proto<TFlatOptional>(modelStr, config)); UNIT_ASSERT(proto.GetOneTwoString() == "value"); } - + // snake_case { TString modelStr(R"_({"string":"value"})_"); @@ -457,7 +457,7 @@ Y_UNIT_TEST(TestFieldNameMode) { UNIT_ASSERT(proto.GetI32(0) == 1); UNIT_ASSERT(proto.GetI32(1) == 2); } - + // UseJsonName { // FIXME(CONTRIB-139): since protobuf 3.1, Def_upper json name is @@ -465,18 +465,18 @@ Y_UNIT_TEST(TestFieldNameMode) { // updated, library/cpp/protobuf/json preserves compatibility with // protobuf 3.0 by lowercasing default names, making it "defUpper". TString modelStr(R"_({"My-Upper":1,"my-lower":2,"defUpper":3,"defLower":4})_"); - + TWithJsonName proto; TJson2ProtoConfig config; config.SetUseJsonName(true); - + UNIT_ASSERT_NO_EXCEPTION(proto = Json2Proto<TWithJsonName>(modelStr, config)); UNIT_ASSERT_EQUAL(proto.Getmy_upper(), 1); UNIT_ASSERT_EQUAL(proto.GetMy_lower(), 2); UNIT_ASSERT_EQUAL(proto.GetDef_upper(), 3); UNIT_ASSERT_EQUAL(proto.Getdef_lower(), 4); } - + // FieldNameMode with UseJsonName { TJson2ProtoConfig config; @@ -589,23 +589,23 @@ Y_UNIT_TEST(TestCastFromString) { // single fields { NJson::TJsonValue json; -#define DEFINE_FIELD(name, value) \ +#define DEFINE_FIELD(name, value) \ json.InsertValue(#name, ConvertToString(value)); #include <library/cpp/protobuf/json/ut/fields.incl> -#undef DEFINE_FIELD - +#undef DEFINE_FIELD + TFlatOptional proto; UNIT_ASSERT_EXCEPTION_CONTAINS(Json2Proto(json, proto), yexception, "Invalid type"); - + TJson2ProtoConfig config; config.SetCastFromString(true); Json2Proto(json, proto, config); - + TFlatOptional modelProto; FillFlatProto(&modelProto); UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto); } - + // repeated fields { NJson::TJsonValue json; @@ -619,21 +619,21 @@ Y_UNIT_TEST(TestCastFromString) { json.InsertValue(#name, array); \ } #include <library/cpp/protobuf/json/ut/repeated_fields.incl> -#undef DEFINE_REPEATED_FIELD - +#undef DEFINE_REPEATED_FIELD + TFlatRepeated proto; UNIT_ASSERT_EXCEPTION_CONTAINS(Json2Proto(json, proto), yexception, "Invalid type"); - + TJson2ProtoConfig config; config.SetCastFromString(true); Json2Proto(json, proto, config); - + TFlatRepeated modelProto; FillRepeatedProto(&modelProto); UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto); } } // TestCastFromString - + Y_UNIT_TEST(TestMap) { TMapType modelProto; diff --git a/library/cpp/protobuf/json/ut/proto2json_ut.cpp b/library/cpp/protobuf/json/ut/proto2json_ut.cpp index 7fc3a1e403..07e52d7f2f 100644 --- a/library/cpp/protobuf/json/ut/proto2json_ut.cpp +++ b/library/cpp/protobuf/json/ut/proto2json_ut.cpp @@ -721,41 +721,41 @@ Y_UNIT_TEST(TestFieldNameMode) { // Camelcase { TString modelStr(R"_({"string":"value"})_"); - + TFlatOptional proto; proto.SetString("value"); TStringStream jsonStr; TProto2JsonConfig config; config.FieldNameMode = TProto2JsonConfig::FieldNameCamelCase; - + UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, jsonStr, config)); UNIT_ASSERT_JSON_STRINGS_EQUAL(jsonStr.Str(), modelStr); } { TString modelStr(R"_({"oneString":"value"})_"); - + TFlatOptional proto; proto.SetOneString("value"); TStringStream jsonStr; TProto2JsonConfig config; config.FieldNameMode = TProto2JsonConfig::FieldNameCamelCase; - + UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, jsonStr, config)); UNIT_ASSERT_JSON_STRINGS_EQUAL(jsonStr.Str(), modelStr); } { TString modelStr(R"_({"oneTwoString":"value"})_"); - + TFlatOptional proto; proto.SetOneTwoString("value"); TStringStream jsonStr; TProto2JsonConfig config; config.FieldNameMode = TProto2JsonConfig::FieldNameCamelCase; - + UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, jsonStr, config)); UNIT_ASSERT_JSON_STRINGS_EQUAL(jsonStr.Str(), modelStr); } - + // snake_case { TString modelStr(R"_({"string":"value"})_"); @@ -857,7 +857,7 @@ Y_UNIT_TEST(TestFieldNameMode) { // FIXME(CONTRIB-139): see the comment about UseJsonName in json2proto_ut.cpp: // Def_upper json name should be "DefUpper". TString modelStr(R"_({"My-Upper":1,"my-lower":2,"defUpper":3,"defLower":4})_"); - + TWithJsonName proto; proto.Setmy_upper(1); proto.SetMy_lower(2); @@ -866,11 +866,11 @@ Y_UNIT_TEST(TestFieldNameMode) { TStringStream jsonStr; TProto2JsonConfig config; config.SetUseJsonName(true); - + UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, jsonStr, config)); UNIT_ASSERT_STRINGS_EQUAL(jsonStr.Str(), modelStr); } - + // FieldNameMode with UseJsonName { TProto2JsonConfig config; @@ -884,7 +884,7 @@ Y_UNIT_TEST(TestFieldNameMode) { UNIT_ASSERT_EXCEPTION_CONTAINS( config.SetFieldNameMode(TProto2JsonConfig::FieldNameLowerCase), yexception, "mutually exclusive"); } - + /// TODO: test missing keys } // TestFieldNameMode diff --git a/library/cpp/protobuf/json/ut/test.proto b/library/cpp/protobuf/json/ut/test.proto index 1285cb430d..0fa996fd41 100644 --- a/library/cpp/protobuf/json/ut/test.proto +++ b/library/cpp/protobuf/json/ut/test.proto @@ -28,9 +28,9 @@ message TFlatOptional { optional float Float = 15; optional double Double = 16; - - optional string OneString = 17; - optional string OneTwoString = 18; + + optional string OneString = 17; + optional string OneTwoString = 18; optional string ABC = 19; optional string UserID = 20; }; @@ -56,9 +56,9 @@ message TFlatRequired { required float Float = 15; required double Double = 16; - - required string OneString = 17; - required string OneTwoString = 18; + + required string OneString = 17; + required string OneTwoString = 18; required string ABC = 19; required string UserID = 20; }; @@ -84,9 +84,9 @@ message TFlatRepeated { repeated float Float = 15; repeated double Double = 16; - - repeated string OneString = 17; - repeated string OneTwoString = 18; + + repeated string OneString = 17; + repeated string OneTwoString = 18; repeated string ABC = 19; repeated string UserID = 20; }; @@ -112,9 +112,9 @@ message TFlatDefault { optional float Float = 15 [default = 0.123]; optional double Double = 16 [default = 0.456]; - - optional string OneString = 17 [default = "string"]; - optional string OneTwoString = 18 [default = "string"]; + + optional string OneString = 17 [default = "string"]; + optional string OneTwoString = 18 [default = "string"]; optional string ABC = 19 [default = "abc"]; optional string UserID = 20 [default = "some_id"]; }; @@ -134,7 +134,7 @@ message TCompositeRepeated { message TMapType { map<string, string> Items = 1; }; - + message TNameGeneratorType { optional int32 Field = 1; }; @@ -171,12 +171,12 @@ message TComplexMapType { map<string, TComplexMapType> Nested = 16; }; -message TWithJsonName { +message TWithJsonName { optional int32 my_upper = 1 [json_name = "My-Upper"]; optional int32 My_lower = 2 [json_name = "my-lower"]; optional int32 Def_upper = 3; // json_name = "DefUpper" optional int32 def_lower = 4; // json_name = "defLower" -} +} message TSingleRequiredString { required string String = 1; diff --git a/library/cpp/protobuf/json/ut/ya.make b/library/cpp/protobuf/json/ut/ya.make index 68a087d224..b60a6d3c17 100644 --- a/library/cpp/protobuf/json/ut/ya.make +++ b/library/cpp/protobuf/json/ut/ya.make @@ -14,8 +14,8 @@ SRCS( util_ut.cpp ) -GENERATE_ENUM_SERIALIZATION(test.pb.h) - +GENERATE_ENUM_SERIALIZATION(test.pb.h) + PEERDIR( library/cpp/protobuf/json ) |