mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-09 22:56:27 +00:00
JSON Parser allows union type fields to come after unions.
This is useful because many JSON generators will sort the fields, cause X_type to follow X. Change-Id: I00ef3ac05418224fc05aee93e6b3b3597e73ffe3 Tested: on Linux. Bug: 29221752
This commit is contained in:
@@ -783,7 +783,7 @@ void ErrorTest() {
|
||||
TestError("table X { Y:int; Y:int; }", "field already");
|
||||
TestError("struct X { Y:string; }", "only scalar");
|
||||
TestError("struct X { Y:int (deprecated); }", "deprecate");
|
||||
TestError("union Z { X } table X { Y:Z; } root_type X; { Y: {",
|
||||
TestError("union Z { X } table X { Y:Z; } root_type X; { Y: {}, A:1 }",
|
||||
"missing type field");
|
||||
TestError("union Z { X } table X { Y:Z; } root_type X; { Y_type: 99, Y: {",
|
||||
"type id");
|
||||
@@ -951,6 +951,16 @@ void UnknownFieldsTest() {
|
||||
TEST_EQ(jsongen == "{str: \"test\",i: 10}", true);
|
||||
}
|
||||
|
||||
void ParseUnionTest() {
|
||||
// Unions must be parseable with the type field following the object.
|
||||
flatbuffers::Parser parser;
|
||||
TEST_EQ(parser.Parse("table T { A:int; }"
|
||||
"union U { T }"
|
||||
"table V { X:U; }"
|
||||
"root_type V;"
|
||||
"{ X:{ A:1 }, X_type: T }"), true);
|
||||
}
|
||||
|
||||
int main(int /*argc*/, const char * /*argv*/[]) {
|
||||
// Run our various test suites:
|
||||
|
||||
@@ -979,6 +989,7 @@ int main(int /*argc*/, const char * /*argv*/[]) {
|
||||
UnicodeSurrogatesTest();
|
||||
UnicodeInvalidSurrogatesTest();
|
||||
UnknownFieldsTest();
|
||||
ParseUnionTest();
|
||||
|
||||
if (!testing_fails) {
|
||||
TEST_OUTPUT_LINE("ALL TESTS PASSED");
|
||||
|
||||
Reference in New Issue
Block a user