aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/protobuf/json/ut/proto2json_ut.cpp
diff options
context:
space:
mode:
authorAlexSm <alex@ydb.tech>2023-12-22 20:30:08 +0100
committerGitHub <noreply@github.com>2023-12-22 20:30:08 +0100
commit6b4f46a6883f21c16eef367106167ea59932515e (patch)
tree5833709b16bba3948f15e88b9038229c5065605b /library/cpp/protobuf/json/ut/proto2json_ut.cpp
parenta8b737f2a6df02f6e45ed703246c75f0f4cf7a34 (diff)
downloadydb-6b4f46a6883f21c16eef367106167ea59932515e.tar.gz
Import libs 3 (#679)
Diffstat (limited to 'library/cpp/protobuf/json/ut/proto2json_ut.cpp')
-rw-r--r--library/cpp/protobuf/json/ut/proto2json_ut.cpp44
1 files changed, 42 insertions, 2 deletions
diff --git a/library/cpp/protobuf/json/ut/proto2json_ut.cpp b/library/cpp/protobuf/json/ut/proto2json_ut.cpp
index f19558e60a..80dae6f01d 100644
--- a/library/cpp/protobuf/json/ut/proto2json_ut.cpp
+++ b/library/cpp/protobuf/json/ut/proto2json_ut.cpp
@@ -981,7 +981,7 @@ Y_UNIT_TEST(TestMapAsObject) {
UNIT_ASSERT_JSON_STRINGS_EQUAL(jsonStr.Str(), modelStr);
} // TestMapAsObject
-Y_UNIT_TEST(TestMapWTF) {
+Y_UNIT_TEST(TestMapUsingGeneratedAsJSON) {
TMapType proto;
auto& items = *proto.MutableItems();
@@ -995,7 +995,47 @@ Y_UNIT_TEST(TestMapWTF) {
UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, jsonStr));
UNIT_ASSERT_JSON_STRINGS_EQUAL(jsonStr.Str(), modelStr);
-} // TestMapWTF
+} // TestMapUsingGeneratedAsJSON
+
+Y_UNIT_TEST(TestMapDefaultValue) {
+ TMapType proto;
+
+ auto& items = *proto.MutableItems();
+ items["key1"] = "";
+
+ TString modelStr(R"_({"Items":{"key1":""}})_");
+
+ TStringStream jsonStr;
+
+ TProto2JsonConfig config;
+ config.MapAsObject = true;
+ UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, jsonStr, config));
+ UNIT_ASSERT_JSON_STRINGS_EQUAL(jsonStr.Str(), modelStr);
+
+ jsonStr.Clear();
+ UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, jsonStr));
+ UNIT_ASSERT_JSON_STRINGS_EQUAL(jsonStr.Str(), modelStr);
+} // TestMapDefaultValue
+
+Y_UNIT_TEST(TestMapDefaultMessageValue) {
+ TComplexMapType proto;
+
+ auto& map = *proto.MutableNested();
+ map["key1"]; // Creates an empty nested message
+
+ TString modelStr(R"_({"Nested":{"key1":{}}})_");
+
+ TStringStream jsonStr;
+
+ TProto2JsonConfig config;
+ config.MapAsObject = true;
+ UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, jsonStr, config));
+ UNIT_ASSERT_JSON_STRINGS_EQUAL(jsonStr.Str(), modelStr);
+
+ jsonStr.Clear();
+ UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, jsonStr));
+ UNIT_ASSERT_JSON_STRINGS_EQUAL(jsonStr.Str(), modelStr);
+} // TestMapDefaultMessageValue
Y_UNIT_TEST(TestStringifyNumbers) {
#define TEST_SINGLE(flag, field, value, expectString) \