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

Function TestTextOneof

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

Source from the content-addressed store, hash-verified

442}
443
444func TestTextOneof(t *testing.T) {
445 tests := []struct {
446 m proto.Message
447 want string
448 }{
449 // zero message
450 {&pb2.Communique{}, ``},
451 // scalar field
452 {&pb2.Communique{Union: &pb2.Communique_Number{4}}, `number:4`},
453 // message field
454 {&pb2.Communique{Union: &pb2.Communique_Msg{
455 &pb2.Strings{StringField: proto.String("why hello!")},
456 }}, `msg:<string_field:"why hello!" >`},
457 // bad oneof (should not panic)
458 {&pb2.Communique{Union: &pb2.Communique_Msg{nil}}, `msg:<>`},
459 }
460 for _, test := range tests {
461 got := strings.TrimSpace(test.m.String())
462 if got != test.want {
463 t.Errorf("got:\n%s\n\nwant:\n%s", got, test.want)
464 }
465 }
466}
467
468func compact(src string) string {
469 // s/[ \n]+/ /g; s/ $//;

Callers

nothing calls this directly

Calls 2

StringFunction · 0.92
StringMethod · 0.45

Tested by

no test coverage detected