diff options
author | alexcrush <alexcrush@yandex-team.ru> | 2022-02-10 16:50:33 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:33 +0300 |
commit | 34f0683c2d7731f2f9f59966c12e602f405fa0d6 (patch) | |
tree | 9af7dd74efcfa3d8aa7b40bd757ad8f2d89f6902 /library/cpp/protobuf/json/ut | |
parent | a1d67d6a31f789aa011250c3edce5751c0cadad2 (diff) | |
download | ydb-34f0683c2d7731f2f9f59966c12e602f405fa0d6.tar.gz |
Restoring authorship annotation for <alexcrush@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 | 64 | ||||
-rw-r--r-- | library/cpp/protobuf/json/ut/proto2json_ut.cpp | 16 |
2 files changed, 40 insertions, 40 deletions
diff --git a/library/cpp/protobuf/json/ut/json2proto_ut.cpp b/library/cpp/protobuf/json/ut/json2proto_ut.cpp index 0dfe57bc7a..c659cfcc50 100644 --- a/library/cpp/protobuf/json/ut/json2proto_ut.cpp +++ b/library/cpp/protobuf/json/ut/json2proto_ut.cpp @@ -317,55 +317,55 @@ Y_UNIT_TEST(TestInvalidEnum) { UNIT_ASSERT_EXCEPTION(Json2Proto(json, proto), yexception); } } - + Y_UNIT_TEST(TestFieldNameMode) { // Original case 1 { TString modelStr(R"_({"String":"value"})_"); - + TFlatOptional proto; TJson2ProtoConfig config; - + UNIT_ASSERT_NO_EXCEPTION(proto = Json2Proto<TFlatOptional>(modelStr, config)); UNIT_ASSERT(proto.GetString() == "value"); } - + // Original case 2 { TString modelStr(R"_({"String":"value"})_"); - + TFlatOptional proto; TJson2ProtoConfig config; config.FieldNameMode = TJson2ProtoConfig::FieldNameOriginalCase; - + UNIT_ASSERT_NO_EXCEPTION(proto = Json2Proto<TFlatOptional>(modelStr, config)); UNIT_ASSERT(proto.GetString() == "value"); } - + // Lowercase { TString modelStr(R"_({"string":"value"})_"); - + TFlatOptional proto; TJson2ProtoConfig config; config.FieldNameMode = TJson2ProtoConfig::FieldNameLowerCase; - + UNIT_ASSERT_NO_EXCEPTION(proto = Json2Proto<TFlatOptional>(modelStr, config)); UNIT_ASSERT(proto.GetString() == "value"); } - + // Uppercase { TString modelStr(R"_({"STRING":"value"})_"); - + TFlatOptional proto; TJson2ProtoConfig config; config.FieldNameMode = TJson2ProtoConfig::FieldNameUpperCase; - + UNIT_ASSERT_NO_EXCEPTION(proto = Json2Proto<TFlatOptional>(modelStr, config)); UNIT_ASSERT(proto.GetString() == "value"); } - + // Camelcase { TString modelStr(R"_({"string":"value"})_"); @@ -433,25 +433,25 @@ Y_UNIT_TEST(TestFieldNameMode) { // Original case, repeated { TString modelStr(R"_({"I32":[1,2]})_"); - + TFlatRepeated proto; TJson2ProtoConfig config; config.FieldNameMode = TJson2ProtoConfig::FieldNameOriginalCase; - + UNIT_ASSERT_NO_EXCEPTION(proto = Json2Proto<TFlatRepeated>(modelStr, config)); UNIT_ASSERT(proto.I32Size() == 2); UNIT_ASSERT(proto.GetI32(0) == 1); UNIT_ASSERT(proto.GetI32(1) == 2); } - + // Lower case, repeated { TString modelStr(R"_({"i32":[1,2]})_"); - + TFlatRepeated proto; TJson2ProtoConfig config; config.FieldNameMode = TJson2ProtoConfig::FieldNameLowerCase; - + UNIT_ASSERT_NO_EXCEPTION(proto = Json2Proto<TFlatRepeated>(modelStr, config)); UNIT_ASSERT(proto.I32Size() == 2); UNIT_ASSERT(proto.GetI32(0) == 1); @@ -491,7 +491,7 @@ Y_UNIT_TEST(TestFieldNameMode) { config.SetFieldNameMode(TJson2ProtoConfig::FieldNameLowerCase), yexception, "mutually exclusive"); } } // TestFieldNameMode - + class TStringTransform: public IStringTransform { public: int GetType() const override { @@ -501,7 +501,7 @@ public: str = "transformed_any"; } }; - + class TBytesTransform: public IStringTransform { public: int GetType() const override { @@ -519,7 +519,7 @@ Y_UNIT_TEST(TestInvalidJson) { TFlatOptional proto; UNIT_ASSERT_EXCEPTION(Json2Proto(val, proto), yexception); } - + Y_UNIT_TEST(TestInvalidRepeatedFieldWithMapAsObject) { TCompositeRepeated proto; TJson2ProtoConfig config; @@ -531,37 +531,37 @@ Y_UNIT_TEST(TestStringTransforms) { // Check that strings and bytes are transformed { TString modelStr(R"_({"String":"value_str", "Bytes": "value_bytes"})_"); - + TFlatOptional proto; TJson2ProtoConfig config; config.AddStringTransform(new TStringTransform); - + UNIT_ASSERT_NO_EXCEPTION(proto = Json2Proto<TFlatOptional>(modelStr, config)); UNIT_ASSERT(proto.GetString() == "transformed_any"); UNIT_ASSERT(proto.GetBytes() == "transformed_any"); } - + // Check that bytes are transformed, strings are left intact { TString modelStr(R"_({"String":"value_str", "Bytes": "value_bytes"})_"); - + TFlatOptional proto; TJson2ProtoConfig config; config.AddStringTransform(new TBytesTransform); - + UNIT_ASSERT_NO_EXCEPTION(proto = Json2Proto<TFlatOptional>(modelStr, config)); UNIT_ASSERT(proto.GetString() == "value_str"); UNIT_ASSERT(proto.GetBytes() == "transformed_bytes"); } - + // Check that repeated bytes are transformed, repeated strings are left intact { TString modelStr(R"_({"String":["value_str", "str2"], "Bytes": ["value_bytes", "bytes2"]})_"); - + TFlatRepeated proto; TJson2ProtoConfig config; config.AddStringTransform(new TBytesTransform); - + UNIT_ASSERT_NO_EXCEPTION(proto = Json2Proto<TFlatRepeated>(modelStr, config)); UNIT_ASSERT(proto.StringSize() == 2); UNIT_ASSERT(proto.GetString(0) == "value_str"); @@ -570,15 +570,15 @@ Y_UNIT_TEST(TestStringTransforms) { UNIT_ASSERT(proto.GetBytes(0) == "transformed_bytes"); UNIT_ASSERT(proto.GetBytes(1) == "transformed_bytes"); } - + // Check that bytes are transformed, strings are left intact in composed messages { TString modelStr(R"_({"Part": {"String":"value_str", "Bytes": "value_bytes"}})_"); - + TCompositeOptional proto; TJson2ProtoConfig config; config.AddStringTransform(new TBytesTransform); - + UNIT_ASSERT_NO_EXCEPTION(proto = Json2Proto<TCompositeOptional>(modelStr, config)); UNIT_ASSERT(proto.GetPart().GetString() == "value_str"); UNIT_ASSERT(proto.GetPart().GetBytes() == "transformed_bytes"); diff --git a/library/cpp/protobuf/json/ut/proto2json_ut.cpp b/library/cpp/protobuf/json/ut/proto2json_ut.cpp index 07e52d7f2f..31264e4a74 100644 --- a/library/cpp/protobuf/json/ut/proto2json_ut.cpp +++ b/library/cpp/protobuf/json/ut/proto2json_ut.cpp @@ -631,37 +631,37 @@ public: str = "bytes"; } }; - + Y_UNIT_TEST(TestBytesTransform) { // Test that string field is not changed { TString modelStr(R"_({"String":"value"})_"); - + TFlatOptional proto; proto.SetString(R"_(value)_"); TProto2JsonConfig config; config.StringTransforms.push_back(new TBytesTransform()); TStringStream jsonStr; - + UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, jsonStr, config)); UNIT_ASSERT_JSON_STRINGS_EQUAL(jsonStr.Str(), modelStr); } - + // Test that bytes field is changed { TString modelStr(R"_({"Bytes":"bytes"})_"); - + TFlatOptional proto; proto.SetBytes(R"_(value)_"); TProto2JsonConfig config; config.StringTransforms.push_back(new TBytesTransform()); TStringStream jsonStr; - + UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, jsonStr, config)); UNIT_ASSERT_JSON_STRINGS_EQUAL(jsonStr.Str(), modelStr); - } + } } - + Y_UNIT_TEST(TestFieldNameMode) { // Original case 1 { |