aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Van Lenten <thomasvl@google.com>2016-08-22 15:37:25 -0400
committerGitHub <noreply@github.com>2016-08-22 15:37:25 -0400
commitb5794ed02420770bf58398581c1ca11e1c9a29d9 (patch)
tree00106165ca04438ddc60d5caad610629a9e1999a
parentff2a6600e5df21683b86aca7e30bbb80c0aed848 (diff)
parent7437774a27dfedc7ecbd3eaa7b8dd79794bbc5d6 (diff)
downloadprotobuf-b5794ed02420770bf58398581c1ca11e1c9a29d9.tar.gz
protobuf-b5794ed02420770bf58398581c1ca11e1c9a29d9.tar.bz2
protobuf-b5794ed02420770bf58398581c1ca11e1c9a29d9.zip
Merge pull request #1984 from thomasvl/more_json_tests
More tests to shake out some cases in the json parsing
-rw-r--r--conformance/conformance_test.cc72
-rw-r--r--conformance/failure_list_cpp.txt9
-rw-r--r--conformance/failure_list_java.txt3
-rw-r--r--conformance/failure_list_ruby.txt1
4 files changed, 85 insertions, 0 deletions
diff --git a/conformance/conformance_test.cc b/conformance/conformance_test.cc
index 8c247b55..05ca2719 100644
--- a/conformance/conformance_test.cc
+++ b/conformance/conformance_test.cc
@@ -763,6 +763,10 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner,
"FieldNameEscaped",
R"({"fieldn\u0061me1": 1})",
"fieldname1: 1");
+ // String ends with escape character.
+ ExpectParseFailureForJson(
+ "StringEndsWithEscapeChar",
+ "{\"optionalString\": \"abc\\");
// Field names must be quoted (or it's not valid JSON).
ExpectParseFailureForJson(
"FieldNameNotQuoted",
@@ -771,6 +775,17 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner,
ExpectParseFailureForJson(
"TrailingCommaInAnObject",
R"({"fieldname1":1,})");
+ ExpectParseFailureForJson(
+ "TrailingCommaInAnObjectWithSpace",
+ R"({"fieldname1":1 ,})");
+ ExpectParseFailureForJson(
+ "TrailingCommaInAnObjectWithSpaceCommaSpace",
+ R"({"fieldname1":1 , })");
+ ExpectParseFailureForJson(
+ "TrailingCommaInAnObjectWithNewlines",
+ R"({
+ "fieldname1":1,
+ })");
// JSON doesn't support comments.
ExpectParseFailureForJson(
"JsonWithComments",
@@ -778,6 +793,42 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner,
// This is a comment.
"fieldname1": 1
})");
+ // JSON spec says whitespace doesn't matter, so try a few spacings to be sure.
+ RunValidJsonTest(
+ "OneLineNoSpaces",
+ "{\"optionalInt32\":1,\"optionalInt64\":2}",
+ R"(
+ optional_int32: 1
+ optional_int64: 2
+ )");
+ RunValidJsonTest(
+ "OneLineWithSpaces",
+ "{ \"optionalInt32\" : 1 , \"optionalInt64\" : 2 }",
+ R"(
+ optional_int32: 1
+ optional_int64: 2
+ )");
+ RunValidJsonTest(
+ "MultilineNoSpaces",
+ "{\n\"optionalInt32\"\n:\n1\n,\n\"optionalInt64\"\n:\n2\n}",
+ R"(
+ optional_int32: 1
+ optional_int64: 2
+ )");
+ RunValidJsonTest(
+ "MultilineWithSpaces",
+ "{\n \"optionalInt32\" : 1\n ,\n \"optionalInt64\" : 2\n}\n",
+ R"(
+ optional_int32: 1
+ optional_int64: 2
+ )");
+ // Missing comma between key/value pairs.
+ ExpectParseFailureForJson(
+ "MissingCommaOneLine",
+ "{ \"optionalInt32\": 1 \"optionalInt64\": 2 }");
+ ExpectParseFailureForJson(
+ "MissingCommaMultiline",
+ "{\n \"optionalInt32\": 1\n \"optionalInt64\": 2\n}");
// Duplicated field names are not allowed.
ExpectParseFailureForJson(
"FieldNameDuplicate",
@@ -1389,6 +1440,15 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner,
ExpectParseFailureForJson(
"RepeatedFieldTrailingComma",
R"({"repeatedInt32": [1, 2, 3, 4,]})");
+ ExpectParseFailureForJson(
+ "RepeatedFieldTrailingCommaWithSpace",
+ "{\"repeatedInt32\": [1, 2, 3, 4 ,]}");
+ ExpectParseFailureForJson(
+ "RepeatedFieldTrailingCommaWithSpaceCommaSpace",
+ "{\"repeatedInt32\": [1, 2, 3, 4 , ]}");
+ ExpectParseFailureForJson(
+ "RepeatedFieldTrailingCommaWithNewlines",
+ "{\"repeatedInt32\": [\n 1,\n 2,\n 3,\n 4,\n]}");
// Map fields.
RunValidJsonTest(
@@ -1507,6 +1567,18 @@ bool ConformanceTestSuite::RunSuite(ConformanceTestRunner* runner,
"MapFieldValueIsNull",
R"({"mapInt32Int32": {"0": null}})");
+ // http://www.rfc-editor.org/rfc/rfc7159.txt says strings have to use double
+ // quotes.
+ ExpectParseFailureForJson(
+ "StringFieldSingleQuoteKey",
+ R"({'optionalString': "Hello world!"})");
+ ExpectParseFailureForJson(
+ "StringFieldSingleQuoteValue",
+ R"({"optionalString": 'Hello world!'})");
+ ExpectParseFailureForJson(
+ "StringFieldSingleQuoteBoth",
+ R"({'optionalString': 'Hello world!'})");
+
// Wrapper types.
RunValidJsonTest(
"OptionalBoolWrapper",
diff --git a/conformance/failure_list_cpp.txt b/conformance/failure_list_cpp.txt
index 839e5210..0f1c9414 100644
--- a/conformance/failure_list_cpp.txt
+++ b/conformance/failure_list_cpp.txt
@@ -30,8 +30,17 @@ JsonInput.MapFieldValueIsNull
JsonInput.RepeatedFieldMessageElementIsNull
JsonInput.RepeatedFieldPrimitiveElementIsNull
JsonInput.RepeatedFieldTrailingComma
+JsonInput.RepeatedFieldTrailingCommaWithNewlines
+JsonInput.RepeatedFieldTrailingCommaWithSpace
+JsonInput.RepeatedFieldTrailingCommaWithSpaceCommaSpace
+JsonInput.StringFieldSingleQuoteBoth
+JsonInput.StringFieldSingleQuoteKey
+JsonInput.StringFieldSingleQuoteValue
JsonInput.StringFieldUppercaseEscapeLetter
JsonInput.TrailingCommaInAnObject
+JsonInput.TrailingCommaInAnObjectWithNewlines
+JsonInput.TrailingCommaInAnObjectWithSpace
+JsonInput.TrailingCommaInAnObjectWithSpaceCommaSpace
JsonInput.WrapperTypesWithNullValue.JsonOutput
JsonInput.WrapperTypesWithNullValue.ProtobufOutput
ProtobufInput.PrematureEofBeforeKnownRepeatedValue.MESSAGE
diff --git a/conformance/failure_list_java.txt b/conformance/failure_list_java.txt
index a8636878..6bf91940 100644
--- a/conformance/failure_list_java.txt
+++ b/conformance/failure_list_java.txt
@@ -38,6 +38,9 @@ JsonInput.OriginalProtoFieldName.JsonOutput
JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotBool
JsonInput.RepeatedFieldWrongElementTypeExpectingStringsGotInt
JsonInput.StringFieldNotAString
+JsonInput.StringFieldSingleQuoteBoth
+JsonInput.StringFieldSingleQuoteKey
+JsonInput.StringFieldSingleQuoteValue
JsonInput.StringFieldSurrogateInWrongOrder
JsonInput.StringFieldUnpairedHighSurrogate
JsonInput.StringFieldUnpairedLowSurrogate
diff --git a/conformance/failure_list_ruby.txt b/conformance/failure_list_ruby.txt
index 2960f03b..11428f48 100644
--- a/conformance/failure_list_ruby.txt
+++ b/conformance/failure_list_ruby.txt
@@ -156,6 +156,7 @@ JsonInput.RepeatedUint32Wrapper.JsonOutput
JsonInput.RepeatedUint32Wrapper.ProtobufOutput
JsonInput.RepeatedUint64Wrapper.JsonOutput
JsonInput.RepeatedUint64Wrapper.ProtobufOutput
+JsonInput.StringEndsWithEscapeChar
JsonInput.StringFieldNotAString
JsonInput.StringFieldSurrogateInWrongOrder
JsonInput.StringFieldSurrogatePair.JsonOutput