-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuiltin_test.go
More file actions
85 lines (82 loc) · 2.01 KB
/
builtin_test.go
File metadata and controls
85 lines (82 loc) · 2.01 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
80
81
82
83
84
85
package errors
import (
"fmt"
"testing"
)
func TestReplaceFormatError(t *testing.T) {
testCases := []struct {
desc string
format string
arg []any
expected string
}{
{
"Error with single %+v",
"there is an %s error, err: %+v",
[]any{"hello", New("root error")},
"there is an %s error, err: %s",
},
{
"Error with single %v",
"there is an %s error, err: %v",
[]any{"hello", New("root error")},
"there is an %s error, err: %s",
},
{
"Error with single %#v",
"there is an %s error, err: %#v",
[]any{"hello", New("root error")},
"there is an %s error, err: %s",
},
{
"Error with multiple %+v",
"there is an %+v error, err: %+v",
[]any{"hello", New("root error")},
"there is an %+v error, err: %s",
},
{
"Error with multiple %v",
"there is an %v error, err: %v",
[]any{"hello", New("root error")},
"there is an %v error, err: %s",
},
{
"Error with multiple %#v",
"there is an %#v error, err: %#v",
[]any{"hello", New("root error")},
"there is an %#v error, err: %s",
},
{
"fmt.Error with single %+v",
"there is an %s error, err: %+v",
[]any{"hello", fmt.Errorf("root error")},
"there is an %s error, err: %+v",
},
{
"fmt.Error with multiple %+v",
"there is an %+v error, err: %+v",
[]any{"hello", fmt.Errorf("root error")},
"there is an %+v error, err: %+v",
},
{
"complex error",
"this is %%%% error1: %v, this is error2: %+v, %%%% this is float: %f%% this is error3: %#v, this is error4: %v",
[]any{
New("error1"),
fmt.Errorf("error2"),
0.323,
Wrap(New("error3 root"), "error3"),
fmt.Errorf("error4, err: %+v", "no!!"),
},
"this is %%%% error1: %s, this is error2: %+v, %%%% this is float: %f%% this is error3: %s, this is error4: %v",
},
}
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
got := replaceFormatError(tc.format, tc.arg...)
if tc.expected != got {
t.Errorf("expected: '%s', but got '%s'", tc.expected, got)
}
})
}
}