MCPcopy
hub / github.com/golang/protobuf / TestEnum

Function TestEnum

proto/proto_test.go:1208–1222  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

1206// named types instead of int32: newInt32FromUint64 would crash with
1207// a type mismatch in reflect.PointTo.
1208func 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.

Callers

nothing calls this directly

Calls 4

MarshalMethod · 0.65
UnmarshalMethod · 0.65
EnumMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected