(t *testing.T)
| 19 | }.Marshal() |
| 20 | |
| 21 | func TestDiscardUnknown(t *testing.T) { |
| 22 | tests := []struct { |
| 23 | desc string |
| 24 | in, want proto.Message |
| 25 | }{{ |
| 26 | desc: "Nil", |
| 27 | in: nil, want: nil, // Should not panic |
| 28 | }, { |
| 29 | desc: "NilPtr", |
| 30 | in: (*pb3.Message)(nil), want: (*pb3.Message)(nil), // Should not panic |
| 31 | }, { |
| 32 | desc: "Nested", |
| 33 | in: &pb3.Message{ |
| 34 | Name: "Aaron", |
| 35 | Nested: &pb3.Nested{Cute: true, XXX_unrecognized: []byte(rawFields)}, |
| 36 | XXX_unrecognized: []byte(rawFields), |
| 37 | }, |
| 38 | want: &pb3.Message{ |
| 39 | Name: "Aaron", |
| 40 | Nested: &pb3.Nested{Cute: true}, |
| 41 | }, |
| 42 | }, { |
| 43 | desc: "Slice", |
| 44 | in: &pb3.Message{ |
| 45 | Name: "Aaron", |
| 46 | Children: []*pb3.Message{ |
| 47 | {Name: "Sarah", XXX_unrecognized: []byte(rawFields)}, |
| 48 | {Name: "Abraham", XXX_unrecognized: []byte(rawFields)}, |
| 49 | }, |
| 50 | XXX_unrecognized: []byte(rawFields), |
| 51 | }, |
| 52 | want: &pb3.Message{ |
| 53 | Name: "Aaron", |
| 54 | Children: []*pb3.Message{ |
| 55 | {Name: "Sarah"}, |
| 56 | {Name: "Abraham"}, |
| 57 | }, |
| 58 | }, |
| 59 | }, { |
| 60 | desc: "OneOf", |
| 61 | in: &pb2.Communique{ |
| 62 | Union: &pb2.Communique_Msg{&pb2.Strings{ |
| 63 | StringField: proto.String("123"), |
| 64 | XXX_unrecognized: []byte(rawFields), |
| 65 | }}, |
| 66 | XXX_unrecognized: []byte(rawFields), |
| 67 | }, |
| 68 | want: &pb2.Communique{ |
| 69 | Union: &pb2.Communique_Msg{&pb2.Strings{StringField: proto.String("123")}}, |
| 70 | }, |
| 71 | }, { |
| 72 | desc: "Map", |
| 73 | in: &pb2.MessageWithMap{MsgMapping: map[int64]*pb2.FloatingPoint{ |
| 74 | 0x4002: &pb2.FloatingPoint{ |
| 75 | Exact: proto.Bool(true), |
| 76 | XXX_unrecognized: []byte(rawFields), |
| 77 | }, |
| 78 | }}, |
nothing calls this directly
no test coverage detected