mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
encoding/json: add tests for InvalidUnmarshalError
R=golang-codereviews, shawn.p.smith CC=golang-codereviews https://golang.org/cl/41960047
This commit is contained in:
parent
4d239bcea2
commit
66730120fa
1 changed files with 23 additions and 0 deletions
|
|
@ -1316,3 +1316,26 @@ func TestPrefilled(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
var invalidUnmarshalTests = []struct {
|
||||
v interface{}
|
||||
want string
|
||||
}{
|
||||
{nil, "json: Unmarshal(nil)"},
|
||||
{struct{}{}, "json: Unmarshal(non-pointer struct {})"},
|
||||
{(*int)(nil), "json: Unmarshal(nil *int)"},
|
||||
}
|
||||
|
||||
func TestInvalidUnmarshal(t *testing.T) {
|
||||
buf := []byte(`{"a":"1"}`)
|
||||
for _, tt := range invalidUnmarshalTests {
|
||||
err := Unmarshal(buf, tt.v)
|
||||
if err == nil {
|
||||
t.Errorf("Unmarshal expecting error, got nil")
|
||||
continue
|
||||
}
|
||||
if got := err.Error(); got != tt.want {
|
||||
t.Errorf("Unmarshal = %q; want %q", got, tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue