| 442 | } |
| 443 | |
| 444 | func 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 | |
| 468 | func compact(src string) string { |
| 469 | // s/[ \n]+/ /g; s/ $//; |