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

Function TestUnmarshalText

proto/text_test.go:1255–1279  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1253}
1254
1255func TestUnmarshalText(t *testing.T) {
1256 for _, test := range unmarshalTextTests {
1257 t.Run("", func(t *testing.T) {
1258 pb := new(pb2.MyMessage)
1259 err := proto.UnmarshalText(test.in, pb)
1260 if test.err == "" {
1261 // We don't expect failure.
1262 if err != nil {
1263 t.Errorf("proto.UnmarshalText error: %v", err)
1264 } else if !proto.Equal(pb, test.out) {
1265 t.Errorf("proto.Equal mismatch:\ngot: %v\nwant: %v", pb, test.out)
1266 }
1267 } else {
1268 // We do expect failure.
1269 if err == nil {
1270 t.Errorf("proto.UnmarshalText: got nil error, want %v", test.err)
1271 } else if !strings.Contains(err.Error(), test.err) {
1272 t.Errorf("proto.UnmarshalText error mismatch:\ngot: %v\nwant: %v", err.Error(), test.err)
1273 } else if _, ok := err.(*proto.RequiredNotSetError); ok && test.out != nil && !proto.Equal(pb, test.out) {
1274 t.Errorf("proto.Equal mismatch:\ngot %v\nwant: %v", pb, test.out)
1275 }
1276 }
1277 })
1278 }
1279}
1280
1281func TestUnmarshalTextCustomMessage(t *testing.T) {
1282 msg := &textMessage{}

Callers

nothing calls this directly

Calls 3

UnmarshalTextFunction · 0.92
EqualFunction · 0.92
ErrorMethod · 0.45

Tested by

no test coverage detected