(t *testing.T)
| 872 | } |
| 873 | |
| 874 | func TestUnmarshalNext(t *testing.T) { |
| 875 | // We only need to check against a few, not all of them. |
| 876 | tests := unmarshalingTests[:5] |
| 877 | |
| 878 | // Create a buffer with many concatenated JSON objects. |
| 879 | var b bytes.Buffer |
| 880 | for _, tt := range tests { |
| 881 | b.WriteString(tt.json) |
| 882 | } |
| 883 | |
| 884 | dec := json.NewDecoder(&b) |
| 885 | for _, tt := range tests { |
| 886 | // Make a new instance of the type of our wanted object. |
| 887 | p := reflect.New(reflect.TypeOf(tt.pb).Elem()).Interface().(proto.Message) |
| 888 | |
| 889 | err := tt.unmarshaler.UnmarshalNext(dec, p) |
| 890 | if err != nil { |
| 891 | t.Errorf("%s: %v", tt.desc, err) |
| 892 | continue |
| 893 | } |
| 894 | |
| 895 | // For easier diffs, compare text strings of the protos. |
| 896 | exp := proto.MarshalTextString(tt.pb) |
| 897 | act := proto.MarshalTextString(p) |
| 898 | if string(exp) != string(act) { |
| 899 | t.Errorf("%s: got [%s] want [%s]", tt.desc, act, exp) |
| 900 | } |
| 901 | } |
| 902 | |
| 903 | p := &pb2.Simple{} |
| 904 | err := new(Unmarshaler).UnmarshalNext(dec, p) |
| 905 | if err != io.EOF { |
| 906 | t.Errorf("eof: got %v, want io.EOF", err) |
| 907 | } |
| 908 | } |
| 909 | |
| 910 | var unmarshalingShouldError = []struct { |
| 911 | desc string |
nothing calls this directly
no test coverage detected