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

Function TestNegativeInt32

proto/proto_test.go:986–1012  ·  view source on GitHub ↗

Check that an int32 field can be upgraded to an int64 field.

(t *testing.T)

Source from the content-addressed store, hash-verified

984
985// Check that an int32 field can be upgraded to an int64 field.
986func TestNegativeInt32(t *testing.T) {
987 om := &pb2.OldMessage{
988 Num: proto.Int32(-1),
989 }
990 b, err := proto.Marshal(om)
991 if err != nil {
992 t.Fatalf("Marshal of OldMessage: %v", err)
993 }
994
995 // Check the size. It should be 11 bytes;
996 // 1 for the field/wire type, and 10 for the negative number.
997 if len(b) != 11 {
998 t.Errorf("%v marshaled as %q, wanted 11 bytes", om, b)
999 }
1000
1001 // Unmarshal into a NewMessage.
1002 nm := new(pb2.NewMessage)
1003 if err := proto.Unmarshal(b, nm); err != nil {
1004 t.Fatalf("Unmarshal to NewMessage: %v", err)
1005 }
1006 want := &pb2.NewMessage{
1007 Num: proto.Int64(-1),
1008 }
1009 if !proto.Equal(nm, want) {
1010 t.Errorf("nm = %v, want %v", nm, want)
1011 }
1012}
1013
1014// Check that we can grow an array (repeated field) to have many elements.
1015// This test doesn't depend only on our encoding; for variety, it makes sure

Callers

nothing calls this directly

Calls 5

Int32Function · 0.92
MarshalFunction · 0.92
UnmarshalFunction · 0.92
Int64Function · 0.92
EqualFunction · 0.92

Tested by

no test coverage detected