diff options
Diffstat (limited to 'src/encoding/json/encode_test.go')
| -rw-r--r-- | src/encoding/json/encode_test.go | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/encoding/json/encode_test.go b/src/encoding/json/encode_test.go index 7290eca06f..90826a7f47 100644 --- a/src/encoding/json/encode_test.go +++ b/src/encoding/json/encode_test.go @@ -7,6 +7,7 @@ package json import ( "bytes" "encoding" + "errors" "fmt" "log" "math" @@ -211,7 +212,7 @@ var unsupportedValues = []interface{}{ func TestUnsupportedValues(t *testing.T) { for _, v := range unsupportedValues { if _, err := Marshal(v); err != nil { - if _, ok := err.(*UnsupportedValueError); !ok { + if !errors.Is(err, &UnsupportedValueError{}) { t.Errorf("for %v, got %T want UnsupportedValueError", v, err) } } else { @@ -1155,3 +1156,24 @@ func TestMarshalerError(t *testing.T) { } } } + +func TestMarshalerErrorIs(t *testing.T) { + err := fmt.Errorf("apackage: %w: failed to parse struct", &MarshalerError{ + reflect.TypeOf("a"), + fmt.Errorf("something"), + "TestMarshalerErrorIs", + }) + if !errors.Is(err, &MarshalerError{}) { + t.Fatalf("%v should be unwrapped to a MarshalerError", err) + } +} + +func TestUnsupportedValueErrorIs(t *testing.T) { + err := fmt.Errorf("apackage: %w: failed to parse struct", &UnsupportedValueError{ + Value: reflect.Value{}, + Str: "Foo", + }) + if !errors.Is(err, &UnsupportedValueError{}) { + t.Fatalf("%v should be unwrapped to a UnsupportedValueError", err) + } +} |
