mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-13 00:04:29 +00:00
Add EnumNames to Go code
Tested: on Darwin
This commit is contained in:
@@ -8,3 +8,11 @@ const (
|
||||
AnyTestSimpleTableWithEnum = 2
|
||||
AnyMyGame_Example2_Monster = 3
|
||||
)
|
||||
|
||||
var EnumNamesAny = map[int]string{
|
||||
AnyNONE:"NONE",
|
||||
AnyMonster:"Monster",
|
||||
AnyTestSimpleTableWithEnum:"TestSimpleTableWithEnum",
|
||||
AnyMyGame_Example2_Monster:"MyGame_Example2_Monster",
|
||||
}
|
||||
|
||||
|
||||
@@ -7,3 +7,10 @@ const (
|
||||
ColorGreen = 2
|
||||
ColorBlue = 8
|
||||
)
|
||||
|
||||
var EnumNamesColor = map[int]string{
|
||||
ColorRed:"Red",
|
||||
ColorGreen:"Green",
|
||||
ColorBlue:"Blue",
|
||||
}
|
||||
|
||||
|
||||
@@ -100,6 +100,9 @@ func TestAll(t *testing.T) {
|
||||
// Verify that vtables are deduplicated when written:
|
||||
CheckVtableDeduplication(t.Fatalf)
|
||||
|
||||
// Verify the enum names
|
||||
CheckEnumNames(t.Fatalf)
|
||||
|
||||
// Verify that the Go code used in FlatBuffers documentation passes
|
||||
// some sanity checks:
|
||||
CheckDocExample(generated, off, t.Fatalf)
|
||||
@@ -1314,6 +1317,37 @@ func CheckFinishedBytesError(fail func(string, ...interface{})) {
|
||||
b.FinishedBytes()
|
||||
}
|
||||
|
||||
// CheckEnumNames checks that the generated enum names are correct.
|
||||
func CheckEnumNames(fail func(string, ...interface{})) {
|
||||
type testEnumNames struct {
|
||||
EnumNames map[int]string
|
||||
Expected map[int]string
|
||||
}
|
||||
data := [...]testEnumNames{
|
||||
{example.EnumNamesAny,
|
||||
map[int]string{
|
||||
example.AnyNONE: "NONE",
|
||||
example.AnyMonster: "Monster",
|
||||
example.AnyTestSimpleTableWithEnum: "TestSimpleTableWithEnum",
|
||||
},
|
||||
},
|
||||
{example.EnumNamesColor,
|
||||
map[int]string{
|
||||
example.ColorRed: "Red",
|
||||
example.ColorGreen: "Green",
|
||||
example.ColorBlue: "Blue",
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, t := range data {
|
||||
for val, name := range t.Expected {
|
||||
if name != t.EnumNames[val] {
|
||||
fail("enum name is not equal")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// CheckDocExample checks that the code given in FlatBuffers documentation
|
||||
// is syntactically correct.
|
||||
func CheckDocExample(buf []byte, off flatbuffers.UOffsetT, fail func(string, ...interface{})) {
|
||||
|
||||
Reference in New Issue
Block a user