Test that enums work. Checks for a bug introduced by making enums named types instead of int32: newInt32FromUint64 would crash with a type mismatch in reflect.PointTo.
(t *testing.T)
| 1206 | // named types instead of int32: newInt32FromUint64 would crash with |
| 1207 | // a type mismatch in reflect.PointTo. |
| 1208 | func TestEnum(t *testing.T) { |
| 1209 | pb := new(pb2.GoEnum) |
| 1210 | pb.Foo = pb2.FOO_FOO1.Enum() |
| 1211 | o := new(proto.Buffer) |
| 1212 | if err := o.Marshal(pb); err != nil { |
| 1213 | t.Fatal("error encoding enum:", err) |
| 1214 | } |
| 1215 | pb1 := new(pb2.GoEnum) |
| 1216 | if err := o.Unmarshal(pb1); err != nil { |
| 1217 | t.Fatal("error decoding enum:", err) |
| 1218 | } |
| 1219 | if *pb1.Foo != pb2.FOO_FOO1 { |
| 1220 | t.Error("expected 7 but got ", *pb1.Foo) |
| 1221 | } |
| 1222 | } |
| 1223 | |
| 1224 | // Enum types have String methods. Check that enum fields can be printed. |
| 1225 | // We don't care what the value actually is, just as long as it doesn't crash. |