| 1875 | } |
| 1876 | |
| 1877 | func TestMapFieldRoundTrips(t *testing.T) { |
| 1878 | m := &pb2.MessageWithMap{ |
| 1879 | NameMapping: map[int32]string{ |
| 1880 | 1: "Rob", |
| 1881 | 4: "Ian", |
| 1882 | 8: "Dave", |
| 1883 | }, |
| 1884 | MsgMapping: map[int64]*pb2.FloatingPoint{ |
| 1885 | 0x7001: {F: proto.Float64(2.0)}, |
| 1886 | }, |
| 1887 | ByteMapping: map[bool][]byte{ |
| 1888 | false: []byte("that's not right!"), |
| 1889 | true: []byte("aye, 'tis true!"), |
| 1890 | }, |
| 1891 | } |
| 1892 | b, err := proto.Marshal(m) |
| 1893 | if err != nil { |
| 1894 | t.Fatalf("Marshal: %v", err) |
| 1895 | } |
| 1896 | t.Logf("FYI b: %q", b) |
| 1897 | m2 := new(pb2.MessageWithMap) |
| 1898 | if err := proto.Unmarshal(b, m2); err != nil { |
| 1899 | t.Fatalf("Unmarshal: %v", err) |
| 1900 | } |
| 1901 | if !proto.Equal(m, m2) { |
| 1902 | t.Errorf("Map did not survive a round trip.\ninitial: %v\n final: %v", m, m2) |
| 1903 | } |
| 1904 | } |
| 1905 | |
| 1906 | func TestMapFieldWithNil(t *testing.T) { |
| 1907 | m1 := &pb2.MessageWithMap{ |