go: give enums their own scalar types

This commit is contained in:
rw
2018-07-26 16:40:56 -07:00
parent 2361dfb66a
commit f675f6433c
4 changed files with 48 additions and 34 deletions

View File

@@ -1356,31 +1356,28 @@ func CheckFinishedBytesError(fail func(string, ...interface{})) {
// 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
{
want := map[example.Any]string{
example.AnyNONE: "NONE",
example.AnyMonster: "Monster",
example.AnyTestSimpleTableWithEnum: "TestSimpleTableWithEnum",
example.AnyMyGame_Example2_Monster: "MyGame_Example2_Monster",
}
got := example.EnumNamesAny
if !reflect.DeepEqual(got, want) {
fail("enum name is not equal")
}
}
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")
}
{
want := map[example.Color]string{
example.ColorRed: "Red",
example.ColorGreen: "Green",
example.ColorBlue: "Blue",
}
got := example.EnumNamesColor
if !reflect.DeepEqual(got, want) {
fail("enum name is not equal")
}
}
}