diff options
author | Feng Xiao <xfxyjwf@gmail.com> | 2017-03-17 15:05:58 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-17 15:05:58 -0700 |
commit | 15b60bccf8992f7ff0897705e43aa8ab8889cd02 (patch) | |
tree | 811272aec7bfe0b81f6f2daaedfdc87eeb5b98c2 /src/google/protobuf/util/json_util_test.cc | |
parent | c12cc3490bb5dc4bb686a597e10e8025b1617dac (diff) | |
parent | 89eb4e51b24f7417224b47faf32503d11b6b1bc0 (diff) | |
download | protobuf-15b60bccf8992f7ff0897705e43aa8ab8889cd02.tar.gz protobuf-15b60bccf8992f7ff0897705e43aa8ab8889cd02.tar.bz2 protobuf-15b60bccf8992f7ff0897705e43aa8ab8889cd02.zip |
Merge pull request #2867 from mojoBrendan/master
Add preserve_proto_field_names option to JsonPrintOptions
Diffstat (limited to 'src/google/protobuf/util/json_util_test.cc')
-rw-r--r-- | src/google/protobuf/util/json_util_test.cc | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/google/protobuf/util/json_util_test.cc b/src/google/protobuf/util/json_util_test.cc index 53c8a0f8..7c03d674 100644 --- a/src/google/protobuf/util/json_util_test.cc +++ b/src/google/protobuf/util/json_util_test.cc @@ -159,6 +159,43 @@ TEST_F(JsonUtilTest, TestDefaultValues) { "\"repeatedMessageValue\":[]" "}", ToJson(m, options)); + + options.preserve_proto_field_names = true; + m.set_string_value("i am a test string value"); + m.set_bytes_value("i am a test bytes value"); + EXPECT_EQ( + "{\"bool_value\":false," + "\"int32_value\":0," + "\"int64_value\":\"0\"," + "\"uint32_value\":0," + "\"uint64_value\":\"0\"," + "\"float_value\":0," + "\"double_value\":0," + "\"string_value\":\"i am a test string value\"," + "\"bytes_value\":\"aSBhbSBhIHRlc3QgYnl0ZXMgdmFsdWU=\"," + "\"enum_value\":\"FOO\"," + "\"repeated_bool_value\":[]," + "\"repeated_int32_value\":[]," + "\"repeated_int64_value\":[]," + "\"repeated_uint32_value\":[]," + "\"repeated_uint64_value\":[]," + "\"repeated_float_value\":[]," + "\"repeated_double_value\":[]," + "\"repeated_string_value\":[]," + "\"repeated_bytes_value\":[]," + "\"repeated_enum_value\":[]," + "\"repeated_message_value\":[]" + "}", + ToJson(m, options)); +} + +TEST_F(JsonUtilTest, TestPreserveProtoFieldNames) { + TestMessage m; + m.mutable_message_value(); + + JsonPrintOptions options; + options.preserve_proto_field_names = true; + EXPECT_EQ("{\"message_value\":{}}", ToJson(m, options)); } TEST_F(JsonUtilTest, TestAlwaysPrintEnumsAsInts) { |