| 1924 | } |
| 1925 | |
| 1926 | func 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 | |
| 1957 | func TestDecodeMapFieldMissingKey(t *testing.T) { |
| 1958 | b := []byte{ |