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

Function TestEncodeDecodeBytes2

proto/proto_test.go:867–886  ·  view source on GitHub ↗

Test that we encode nil-valued fields of a repeated bytes field correctly. Since entries in a repeated field cannot be nil, nil must mean empty value.

(t *testing.T)

Source from the content-addressed store, hash-verified

865// Test that we encode nil-valued fields of a repeated bytes field correctly.
866// Since entries in a repeated field cannot be nil, nil must mean empty value.
867func TestEncodeDecodeBytes2(t *testing.T) {
868 pb := initGoTest(false)
869
870 // Create our bytes
871 pb.F_BytesRepeated = [][]byte{nil}
872
873 d, err := proto.Marshal(pb)
874 if err != nil {
875 t.Error(err)
876 }
877
878 pbd := new(pb2.GoTest)
879 if err := proto.Unmarshal(d, pbd); err != nil {
880 t.Error(err)
881 }
882
883 if len(pbd.F_BytesRepeated) != 1 || pbd.F_BytesRepeated[0] == nil {
884 t.Error("Unexpected value for repeated bytes field")
885 }
886}
887
888// All required fields set, defaults provided, all repeated fields given two values.
889func TestSkippingUnrecognizedFields(t *testing.T) {

Callers

nothing calls this directly

Calls 4

MarshalFunction · 0.92
UnmarshalFunction · 0.92
initGoTestFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected