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

Function TestOneofParsing

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

Source from the content-addressed store, hash-verified

1349}
1350
1351func TestOneofParsing(t *testing.T) {
1352 const in = `name:"Shrek"`
1353 m := new(pb2.Communique)
1354 want := &pb2.Communique{Union: &pb2.Communique_Name{"Shrek"}}
1355 if err := proto.UnmarshalText(in, m); err != nil {
1356 t.Fatal(err)
1357 }
1358 if !proto.Equal(m, want) {
1359 t.Errorf("\n got %v\nwant %v", m, want)
1360 }
1361
1362 const inOverwrite = `name:"Shrek" number:42`
1363 m = new(pb2.Communique)
1364 testErr := "line 1.13: field 'number' would overwrite already parsed oneof 'union'"
1365 if err := proto.UnmarshalText(inOverwrite, m); err == nil {
1366 t.Errorf("proto.UnmarshalText: got nil error, want %v", testErr)
1367 } else if err.Error() != testErr {
1368 t.Errorf("error mismatch:\ngot: %v\nwant: %v", err.Error(), testErr)
1369 }
1370}

Callers

nothing calls this directly

Calls 3

UnmarshalTextFunction · 0.92
EqualFunction · 0.92
ErrorMethod · 0.45

Tested by

no test coverage detected