Skip to content

Commit

Permalink
unit test: document mainline behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
antongrbin committed Apr 19, 2024
1 parent 7f8b7d6 commit 5b6a533
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions src/google/protobuf/json/json_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,76 @@ TEST_P(JsonTest, ParseMap) {
EXPECT_EQ(other->DebugString(), message.DebugString());
}

TEST_P(JsonTest, ParseMapWithEnumValuesProto2) {
ParseOptions options;
options.ignore_unknown_fields = false;
protobuf_unittest::TestMapOfEnums message;
EXPECT_THAT(ToProto(message, R"json({
"enum_map": {
"key1": "PROTOCOL",
"key2": "UNKNOWN_ENUM_STRING_VALUE",
"key3": "BUFFER",
"key4": "UNKNOWN_ENUM_STRING_VALUE",
"key5": "PROTOCOL",
}
})json", options),
StatusIs(absl::StatusCode::kInvalidArgument)
);
}

TEST_P(JsonTest, ParseMapWithEnumValuesProto3) {
ParseOptions options;
options.ignore_unknown_fields = false;
proto3::MapOfEnums message;
EXPECT_THAT(ToProto(message, R"json({
"map": {
"key1": "FOO",
"key2": "UNKNOWN_ENUM_STRING_VALUE",
"key3": "BAR",
"key4": "UNKNOWN_ENUM_STRING_VALUE",
"key5": "FOO",
}
})json", options),
StatusIs(absl::StatusCode::kInvalidArgument)
);
}

TEST_P(JsonTest, ParseMapWithEnumValuesProto2WithUnknownFields) {
ParseOptions options;
options.ignore_unknown_fields = true;
protobuf_unittest::TestMapOfEnums message;
ASSERT_OK(ToProto(message, R"json({
"enum_map": {
"key1": "PROTOCOL",
"key2": "UNKNOWN_ENUM_STRING_VALUE",
"key3": "BUFFER",
"key4": "UNKNOWN_ENUM_STRING_VALUE",
"key5": "PROTOCOL",
}
})json", options));
EXPECT_EQ(message.enum_map().size(), 5);
EXPECT_EQ(message.enum_map().contains("key2"), true);
EXPECT_EQ(message.enum_map().contains("key4"), true);
}

TEST_P(JsonTest, ParseMapWithEnumValuesProto3WithUnknownFields) {
ParseOptions options;
options.ignore_unknown_fields = true;
proto3::MapOfEnums message;
ASSERT_OK(ToProto(message, R"json({
"map": {
"key1": "FOO",
"key2": "UNKNOWN_ENUM_STRING_VALUE",
"key3": "BAR",
"key4": "UNKNOWN_ENUM_STRING_VALUE",
"key5": "FOO",
}
})json", options));
EXPECT_EQ(message.map().size(), 5);
EXPECT_EQ(message.map().contains("key2"), true);
EXPECT_EQ(message.map().contains("key4"), true);
}

TEST_P(JsonTest, RepeatedMapKey) {
EXPECT_THAT(ToProto<TestMap>(R"json({
"string_map": {
Expand Down

0 comments on commit 5b6a533

Please sign in to comment.