-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patherrors_test.go
More file actions
79 lines (73 loc) · 2.12 KB
/
Copy patherrors_test.go
File metadata and controls
79 lines (73 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package webp
import (
"errors"
"testing"
)
func TestDecoderErrorUnwrap(t *testing.T) {
cases := []struct {
kind DecoderErrorKind
sentinel []error
}{
{DecErrInvalidParam, []error{ErrInvalidParam}},
{DecErrNotEnoughData, []error{ErrNotEnoughData}},
{DecErrBitstream, []error{ErrBitstream}},
{DecErrUnsupported, []error{ErrUnsupported}},
{DecErrAnimated, []error{ErrUnsupported, ErrAnimated}},
}
all := []error{ErrInvalidParam, ErrNotEnoughData, ErrBitstream, ErrUnsupported, ErrAnimated, ErrLossyAlpha}
for _, tc := range cases {
err := error(&DecoderError{tc.kind, "boom"})
want := map[error]bool{}
for _, s := range tc.sentinel {
want[s] = true
if !errors.Is(err, s) {
t.Errorf("kind %d: errors.Is(%v) = false, want true", tc.kind, s)
}
}
for _, s := range all {
if !want[s] && errors.Is(err, s) {
t.Errorf("kind %d: errors.Is(%v) = true, want false", tc.kind, s)
}
}
if err.Error() == "" {
t.Errorf("kind %d: empty Error() string", tc.kind)
}
}
}
func TestEncoderErrorUnwrap(t *testing.T) {
cases := []struct {
kind EncoderErrorKind
sentinel []error
}{
{EncErrInvalidParam, []error{ErrInvalidParam}},
{EncErrBitstream, []error{ErrBitstream}},
{EncErrAlphaUnsupported, []error{ErrInvalidParam, ErrLossyAlpha}},
}
all := []error{ErrInvalidParam, ErrNotEnoughData, ErrBitstream, ErrUnsupported, ErrAnimated, ErrLossyAlpha}
for _, tc := range cases {
err := error(&EncoderError{tc.kind, "boom"})
want := map[error]bool{}
for _, s := range tc.sentinel {
want[s] = true
if !errors.Is(err, s) {
t.Errorf("kind %d: errors.Is(%v) = false, want true", tc.kind, s)
}
}
for _, s := range all {
if !want[s] && errors.Is(err, s) {
t.Errorf("kind %d: errors.Is(%v) = true, want false", tc.kind, s)
}
}
if err.Error() == "" {
t.Errorf("kind %d: empty Error() string", tc.kind)
}
}
}
func TestErrorConstructors(t *testing.T) {
if !errors.Is(animatedErr("x"), ErrAnimated) {
t.Error("animatedErr does not match ErrAnimated")
}
if !errors.Is(encAlphaUnsupported("x"), ErrLossyAlpha) {
t.Error("encAlphaUnsupported does not match ErrLossyAlpha")
}
}