-
-
Notifications
You must be signed in to change notification settings - Fork 66
/
reader_exception_test.go
55 lines (46 loc) · 1.05 KB
/
reader_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
package gozxing
import (
"fmt"
"strings"
"testing"
errors "golang.org/x/xerrors"
)
func newTestException(args ...interface{}) ReaderException {
return readerException{
newException("TestException", args...),
}
}
func TestException_Format(t *testing.T) {
re := newTestException("%d %x", 10, 10)
s := fmt.Sprintf("%+v", re)
cases := []string{
"TestException: 10 a:",
"gozxing.TestException_Format",
"reader_exception_test.go:18",
}
for _, c := range cases {
if strings.Index(s, c) < 0 {
t.Fatalf("error message must contains \"%s\"\n%s", c, s)
}
}
}
func TestWrapReaderException(t *testing.T) {
base := errors.New("base error")
e := WrapReaderException(base)
if !errors.Is(e, base) {
t.Fatalf("err is not base")
}
s := fmt.Sprintf("%+v", e)
cases := []string{
"base error",
"gozxing.TestWrapReaderException",
"reader_exception_test.go:35",
"reader_exception_test.go:34",
}
for _, c := range cases {
if strings.Index(s, c) < 0 {
t.Fatalf("error message must contains \"%s\"\n%s", c, s)
}
}
e.readerException()
}