aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/json/decode_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/encoding/json/decode_test.go')
-rw-r--r--src/encoding/json/decode_test.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/encoding/json/decode_test.go b/src/encoding/json/decode_test.go
index 219e845c7b..b707dcfa99 100644
--- a/src/encoding/json/decode_test.go
+++ b/src/encoding/json/decode_test.go
@@ -2572,3 +2572,34 @@ func TestUnmarshalMaxDepth(t *testing.T) {
}
}
}
+
+func TestInvalidUnmarshalErrorIs(t *testing.T) {
+ err := fmt.Errorf("apackage: %w: failed to parse struct", &InvalidUnmarshalError{reflect.TypeOf("a")})
+ if !errors.Is(err, &InvalidUnmarshalError{}) {
+ t.Fatalf("%v should be unwrapped to a InvalidUnmarshalError", err)
+ }
+}
+
+func TestUnmarshalFieldErrorIs(t *testing.T) {
+ err := fmt.Errorf("apackage: %w: failed to parse struct", &UnmarshalFieldError{
+ Key: "foo",
+ Type: reflect.TypeOf("a"),
+ Field: reflect.StructField{Name: "b"},
+ })
+ if !errors.Is(err, &UnmarshalFieldError{}) {
+ t.Fatalf("%v should be unwrapped to a UnmarshalFieldError", err)
+ }
+}
+
+func TestUnmarshalTypeErrorIs(t *testing.T) {
+ err := fmt.Errorf("apackage: %w: failed to parse struct", &UnmarshalTypeError{
+ Value: "foo",
+ Type: reflect.TypeOf("a"),
+ Offset: 1,
+ Struct: "Foo",
+ Field: "Bar",
+ })
+ if !errors.Is(err, &UnmarshalTypeError{}) {
+ t.Fatalf("%v should be unwrapped to a UnmarshalTypeError", err)
+ }
+}