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

Function TestMergeMessages

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

Source from the content-addressed store, hash-verified

1534}
1535
1536func TestMergeMessages(t *testing.T) {
1537 pb := &pb2.MessageList{Message: []*pb2.MessageList_Message{{Name: proto.String("x"), Count: proto.Int32(1)}}}
1538 data, err := proto.Marshal(pb)
1539 if err != nil {
1540 t.Fatalf("Marshal: %v", err)
1541 }
1542
1543 pb1 := new(pb2.MessageList)
1544 if err := proto.Unmarshal(data, pb1); err != nil {
1545 t.Fatalf("first Unmarshal: %v", err)
1546 }
1547 if err := proto.Unmarshal(data, pb1); err != nil {
1548 t.Fatalf("second Unmarshal: %v", err)
1549 }
1550 if len(pb1.Message) != 1 {
1551 t.Errorf("two Unmarshals produced %d Messages, want 1", len(pb1.Message))
1552 }
1553
1554 pb2 := new(pb2.MessageList)
1555 if err := proto.UnmarshalMerge(data, pb2); err != nil {
1556 t.Fatalf("first UnmarshalMerge: %v", err)
1557 }
1558 if err := proto.UnmarshalMerge(data, pb2); err != nil {
1559 t.Fatalf("second UnmarshalMerge: %v", err)
1560 }
1561 if len(pb2.Message) != 2 {
1562 t.Errorf("two UnmarshalMerges produced %d Messages, want 2", len(pb2.Message))
1563 }
1564}
1565
1566func TestExtensionMarshalOrder(t *testing.T) {
1567 m := &pb2.MyMessage{Count: proto.Int(123)}

Callers

nothing calls this directly

Calls 5

StringFunction · 0.92
Int32Function · 0.92
MarshalFunction · 0.92
UnmarshalFunction · 0.92
UnmarshalMergeFunction · 0.92

Tested by

no test coverage detected