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

Function TestLegacyMarshalMethod

proto/methods_test.go:45–73  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

43}
44
45func TestLegacyMarshalMethod(t *testing.T) {
46 for _, test := range []selfMarshaler{
47 {bytes: []byte("marshal")},
48 {bytes: []byte("marshal"), err: errors.New("some error")},
49 } {
50 m := impl.Export{}.MessageOf(test).Interface()
51 b, err := proto.Marshal(m)
52 if err != test.err || !bytes.Equal(b, test.bytes) {
53 t.Errorf("proto.Marshal(%v) = %v, %v; want %v, %v", test, b, err, test.bytes, test.err)
54 }
55 if gotSize, wantSize := proto.Size(m), len(test.bytes); gotSize != wantSize {
56 t.Fatalf("proto.Size(%v) = %v, want %v", test, gotSize, wantSize)
57 }
58
59 prefix := []byte("prefix")
60 want := append(prefix, test.bytes...)
61 b, err = proto.MarshalOptions{}.MarshalAppend(prefix, m)
62 if err != test.err || !bytes.Equal(b, want) {
63 t.Errorf("MarshalAppend(%v, %v) = %v, %v; want %v, %v", prefix, test, b, err, test.bytes, test.err)
64 }
65
66 b, err = proto.MarshalOptions{
67 Deterministic: true,
68 }.MarshalAppend(nil, m)
69 if err != test.err || !bytes.Equal(b, test.bytes) {
70 t.Errorf("MarshalOptions{Deterministic:true}.MarshalAppend(nil, %v) = %v, %v; want %v, %v", test, b, err, test.bytes, test.err)
71 }
72 }
73}
74
75func TestLegacyUnmarshalMethod(t *testing.T) {
76 sm := &selfMarshaler{}

Callers

nothing calls this directly

Calls 7

MarshalFunction · 0.92
SizeFunction · 0.92
NewMethod · 0.65
InterfaceMethod · 0.65
MessageOfMethod · 0.45
EqualMethod · 0.45
MarshalAppendMethod · 0.45

Tested by

no test coverage detected