MCPcopy
hub / github.com/protocolbuffers/protobuf-go / testMethods

Function testMethods

internal/testprotos/nullable/nullable_test.go:43–67  ·  view source on GitHub ↗
(t *testing.T, mt protoreflect.MessageType)

Source from the content-addressed store, hash-verified

41}
42
43func testMethods(t *testing.T, mt protoreflect.MessageType) {
44 m1 := mt.New()
45 populated := testPopulateMessage(t, m1, 2)
46 b, err := proto.Marshal(m1.Interface())
47 if err != nil {
48 t.Errorf("proto.Marshal error: %v", err)
49 }
50 if populated && len(b) == 0 {
51 t.Errorf("len(proto.Marshal) = 0, want >0")
52 }
53 m2 := mt.New()
54 if err := proto.Unmarshal(b, m2.Interface()); err != nil {
55 t.Errorf("proto.Unmarshal error: %v", err)
56 }
57 if diff := cmp.Diff(m1.Interface(), m2.Interface(), protocmp.Transform()); diff != "" {
58 t.Errorf("message mismatch:\n%v", diff)
59 }
60 proto.Reset(m2.Interface())
61 testEmptyMessage(t, m2, true)
62 proto.Merge(m2.Interface(), m1.Interface())
63 if diff := cmp.Diff(m1.Interface(), m2.Interface(), protocmp.Transform()); diff != "" {
64 t.Errorf("message mismatch:\n%v", diff)
65 }
66 proto.Merge(mt.New().Interface(), mt.Zero().Interface())
67}
68
69func testEmptyMessage(t *testing.T, m protoreflect.Message, wantValid bool) {
70 numFields := func(m protoreflect.Message) (n int) {

Callers 1

TestMethodsFunction · 0.85

Calls 10

MarshalFunction · 0.92
UnmarshalFunction · 0.92
TransformFunction · 0.92
ResetFunction · 0.92
MergeFunction · 0.92
testPopulateMessageFunction · 0.85
testEmptyMessageFunction · 0.85
NewMethod · 0.65
InterfaceMethod · 0.65
ZeroMethod · 0.65

Tested by

no test coverage detected