mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-02 04:04:19 +00:00
[C++] Fix for printing of enum in case output_enum_identifiers=1. (#5706)
* Add test-case for testing of the future Color in json (output_enum_identifiers = true) * Refactoring of idl_gen_text.cpp. Fix for printing of bit-enum with active output_enum_identifiers=1. * Move GenerateText implementation into class * Remove unnecessary code from flatbuffers.h
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
c4b2b0a25d
commit
01189d7edd
@@ -650,6 +650,19 @@ void JsonEnumsTest() {
|
||||
auto result = GenerateText(parser, builder.GetBufferPointer(), &jsongen);
|
||||
TEST_EQ(result, true);
|
||||
TEST_EQ(std::string::npos != jsongen.find("color: \"Red Blue\""), true);
|
||||
// Test forward compatibility with 'output_enum_identifiers = true'.
|
||||
// Current Color doesn't have '(1u << 2)' field, let's add it.
|
||||
builder.Clear();
|
||||
std::string future_json;
|
||||
auto future_name = builder.CreateString("future bitflag_enum");
|
||||
MonsterBuilder future_color(builder);
|
||||
future_color.add_name(future_name);
|
||||
future_color.add_color(
|
||||
static_cast<Color>((1u << 2) | Color_Blue | Color_Red));
|
||||
FinishMonsterBuffer(builder, future_color.Finish());
|
||||
result = GenerateText(parser, builder.GetBufferPointer(), &future_json);
|
||||
TEST_EQ(result, true);
|
||||
TEST_EQ(std::string::npos != future_json.find("color: 13"), true);
|
||||
}
|
||||
|
||||
#if defined(FLATBUFFERS_HAS_NEW_STRTOD) && (FLATBUFFERS_HAS_NEW_STRTOD > 0)
|
||||
|
||||
Reference in New Issue
Block a user