mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 04:04:19 +00:00
Fixed GenerateText not handling vectors of unions.
Change-Id: Ie82abaf178495c4692e7d10be6b4a13f2fa1bee6
This commit is contained in:
@@ -2410,6 +2410,7 @@ void UnionVectorTest() {
|
||||
|
||||
TestMovie(repacked_movie);
|
||||
|
||||
// Generate text using mini-reflection.
|
||||
auto s =
|
||||
flatbuffers::FlatBufferToString(fbb.GetBufferPointer(), MovieTypeTable());
|
||||
TEST_EQ_STR(
|
||||
@@ -2451,6 +2452,39 @@ void UnionVectorTest() {
|
||||
" ]\n"
|
||||
"}");
|
||||
|
||||
// Generate text using parsed schema.
|
||||
std::string jsongen;
|
||||
auto result = GenerateText(parser, fbb.GetBufferPointer(), &jsongen);
|
||||
TEST_EQ(result, true);
|
||||
TEST_EQ_STR(
|
||||
jsongen.c_str(),
|
||||
"{\n"
|
||||
" main_character_type: \"Rapunzel\",\n"
|
||||
" main_character: {\n"
|
||||
" hair_length: 6\n"
|
||||
" },\n"
|
||||
" characters_type: [\n"
|
||||
" \"Belle\",\n"
|
||||
" \"MuLan\",\n"
|
||||
" \"BookFan\",\n"
|
||||
" \"Other\",\n"
|
||||
" \"Unused\"\n"
|
||||
" ],\n"
|
||||
" characters: [\n"
|
||||
" {\n"
|
||||
" books_read: 7\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" sword_attack_damage: 5\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" books_read: 2\n"
|
||||
" },\n"
|
||||
" \"Other\",\n"
|
||||
" \"Unused\"\n"
|
||||
" ]\n"
|
||||
"}\n");
|
||||
|
||||
flatbuffers::Parser parser2(idl_opts);
|
||||
TEST_EQ(parser2.Parse("struct Bool { b:bool; }"
|
||||
"union Any { Bool }"
|
||||
|
||||
Reference in New Issue
Block a user