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

Function TestMapFieldRoundTrips

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

Source from the content-addressed store, hash-verified

1875}
1876
1877func 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
1906func TestMapFieldWithNil(t *testing.T) {
1907 m1 := &pb2.MessageWithMap{

Callers

nothing calls this directly

Calls 4

Float64Function · 0.92
MarshalFunction · 0.92
UnmarshalFunction · 0.92
EqualFunction · 0.92

Tested by

no test coverage detected