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

Function TestMapFieldWithNilBytes

proto/proto_test.go:1926–1955  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1924}
1925
1926func TestMapFieldWithNilBytes(t *testing.T) {
1927 m1 := &pb2.MessageWithMap{
1928 ByteMapping: map[bool][]byte{
1929 false: {},
1930 true: nil,
1931 },
1932 }
1933 n := proto.Size(m1)
1934 b, err := proto.Marshal(m1)
1935 if err != nil {
1936 t.Fatalf("Marshal: %v", err)
1937 }
1938 if n != len(b) {
1939 t.Errorf("Size(m1) = %d; want len(Marshal(m1)) = %d", n, len(b))
1940 }
1941 m2 := new(pb2.MessageWithMap)
1942 if err := proto.Unmarshal(b, m2); err != nil {
1943 t.Fatalf("Unmarshal: %v, got these bytes: %v", err, b)
1944 }
1945 if v, ok := m2.ByteMapping[false]; !ok {
1946 t.Error("byte_mapping[false] not present")
1947 } else if len(v) != 0 {
1948 t.Errorf("byte_mapping[false] not empty: %#v", v)
1949 }
1950 if v, ok := m2.ByteMapping[true]; !ok {
1951 t.Error("byte_mapping[true] not present")
1952 } else if len(v) != 0 {
1953 t.Errorf("byte_mapping[true] not empty: %#v", v)
1954 }
1955}
1956
1957func TestDecodeMapFieldMissingKey(t *testing.T) {
1958 b := []byte{

Callers

nothing calls this directly

Calls 4

SizeFunction · 0.92
MarshalFunction · 0.92
UnmarshalFunction · 0.92
ErrorMethod · 0.45

Tested by

no test coverage detected