(t *testing.T)
| 23 | ) |
| 24 | |
| 25 | func TestUnmarshal(t *testing.T) { |
| 26 | type test struct { |
| 27 | desc string |
| 28 | umo prototext.UnmarshalOptions |
| 29 | inputMessage proto.Message |
| 30 | inputText string |
| 31 | wantMessage proto.Message |
| 32 | wantErr string // Expected error substring. |
| 33 | skip bool |
| 34 | } |
| 35 | tests := []test{{ |
| 36 | desc: "case sensitive", |
| 37 | inputMessage: &pb3.Scalars{}, |
| 38 | inputText: `S_BOOL: true`, |
| 39 | wantErr: "unknown field: S_BOOL", |
| 40 | }, { |
| 41 | desc: "proto2 string with invalid UTF-8", |
| 42 | inputMessage: &pb2.Scalars{}, |
| 43 | inputText: `opt_string: "abc\xff"`, |
| 44 | wantMessage: &pb2.Scalars{ |
| 45 | OptString: proto.String("abc\xff"), |
| 46 | }, |
| 47 | }, { |
| 48 | desc: "protoeditions unvalidated string with invalid UTF-8", |
| 49 | inputMessage: &pbeditions.Scalars{}, |
| 50 | inputText: `opt_string: "abc\xff"`, |
| 51 | wantMessage: &pbeditions.Scalars{ |
| 52 | OptString: proto.String("abc\xff"), |
| 53 | }, |
| 54 | }, { |
| 55 | desc: "proto3 string with invalid UTF-8", |
| 56 | inputMessage: &pb3.Scalars{}, |
| 57 | inputText: `s_string: "abc\xff"`, |
| 58 | wantErr: "(line 1:11): contains invalid UTF-8", |
| 59 | }, { |
| 60 | desc: "proto2 message contains unknown field", |
| 61 | inputMessage: &pb2.Scalars{}, |
| 62 | inputText: "unknown_field: 123", |
| 63 | wantErr: "unknown field", |
| 64 | }, { |
| 65 | desc: "proto3 message contains unknown field", |
| 66 | inputMessage: &pb3.Scalars{}, |
| 67 | inputText: "unknown_field: 456", |
| 68 | wantErr: "unknown field", |
| 69 | }, { |
| 70 | desc: "proto2 message contains reserved field name", |
| 71 | inputMessage: &pb2.ReservedFieldNames{}, |
| 72 | inputText: "reserved_field: 123 reserved_field { nested: 123 } opt_int32: 456", |
| 73 | wantMessage: &pb2.ReservedFieldNames{OptInt32: proto.Int32(456)}, |
| 74 | }, { |
| 75 | desc: "proto3 message contains reserved field name", |
| 76 | inputMessage: &pb3.ReservedFieldNames{}, |
| 77 | inputText: "reserved_field: 123 reserved_field { nested: 123 } opt_int32: 456", |
| 78 | wantMessage: &pb3.ReservedFieldNames{OptInt32: 456}, |
| 79 | }, { |
| 80 | desc: "proto2 message contains discarded unknown field", |
| 81 | umo: prototext.UnmarshalOptions{DiscardUnknown: true}, |
| 82 | inputMessage: &pb2.Scalars{}, |
nothing calls this directly
no test coverage detected