1 package emperror
2
3 import (
4 "io"
5 "testing"
6
7 "github.com/pkg/errors"
8 )
9
10 func TestWrapf_Format(t *testing.T) {
11 testError := errors.New("error")
12
13 tests := []struct {
14 error
15 format string
16 want string
17 }{{
18 Wrapf(io.EOF, "error%d", 2),
19 "%s",
20 "error2: EOF",
21 }, {
22 Wrapf(io.EOF, "error%d", 2),
23 "%v",
24 "error2: EOF",
25 }, {
26 Wrapf(io.EOF, "error%d", 2),
27 "%+v",
28 "EOF\n" +
29 "error2\n" +
30 "github.com/goph/emperror.TestWrapf_Format\n" +
31 "\t.+/wrapf_test.go:26",
32 }, {
33 Wrapf(errors.New("error"), "error%d", 2),
34 "%s",
35 "error2: error",
36 }, {
37 Wrapf(errors.New("error"), "error%d", 2),
38 "%v",
39 "error2: error",
40 }, {
41 Wrapf(errors.New("error"), "error%d", 2),
42 "%+v",
43 "error\n" +
44 "github.com/goph/emperror.TestWrapf_Format\n" +
45 "\t.+/wrapf_test.go:41",
46 }, {
47 Wrapf(testError, "error%d", 2),
48 "%+v",
49 "error\n" +
50 "github.com/goph/emperror.TestWrapf_Format\n" +
51 "\t.+/wrapf_test.go:11",
52 }}
53
54 for i, tt := range tests {
55 testFormatRegexp(t, i, tt.error, tt.format, tt.want)
56 }
57 }
58
View as plain text