-
-
Notifications
You must be signed in to change notification settings - Fork 66
/
format_exception_test.go
74 lines (62 loc) · 1.7 KB
/
format_exception_test.go
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
package gozxing
import (
"fmt"
"testing"
errors "golang.org/x/xerrors"
)
func testFormatExceptionType(t testing.TB, e error) {
t.Helper()
var fe FormatException
if !errors.As(e, &fe) {
t.Fatalf("Type must be FormatException")
}
var re ReaderException
if !errors.As(e, &re) {
t.Fatalf("Type must be ReaderException")
}
var ne NotFoundException
if errors.As(e, &ne) {
t.Fatalf("Type must not be NotFoundException")
}
if _, ok := e.(FormatException); !ok {
t.Fatalf("Type must be FormatException")
}
if _, ok := e.(ReaderException); !ok {
t.Fatalf("Type must be ReaderException")
}
if _, ok := e.(ChecksumException); ok {
t.Fatalf("Type must not be ChecksumException")
}
fe.formatException()
fe.readerException()
}
func TestFormatException(t *testing.T) {
var e error = NewFormatException()
testFormatExceptionType(t, e)
}
func TestNewFormatException(t *testing.T) {
var e error = NewFormatException("testmsg %d, %d", 10, 20)
testFormatExceptionType(t, e)
msg := e.Error()
wants := "FormatException: testmsg 10, 20"
if msg != wants {
t.Fatalf("Error() = \"%s\", wants \"%s\"", msg, wants)
}
}
func TestWrapFormatException(t *testing.T) {
base := errors.New("newformatexception")
var e error = WrapFormatException(base)
testFormatExceptionType(t, e)
if !errors.Is(e, base) {
t.Fatalf("err(%v) is not base(%v)", e, base)
}
wants := "FormatException: newformatexception"
if msg := fmt.Sprintf("%v", e); msg != wants {
t.Fatalf("e.Error() = \"%s\", wants \"%s\"", msg, wants)
}
e = WrapFormatException(e)
wants = "FormatException: FormatException: newformatexception"
if msg := fmt.Sprintf("%v", e); msg != wants {
t.Fatalf("e.Error() = \"%s\", wants \"%s\"", msg, wants)
}
}