-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfmt.go
54 lines (46 loc) · 1.02 KB
/
fmt.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
package testing
import (
"fmt"
"strconv"
)
// Sprintf convenience function.
//
// See: https://pkg.go.dev/fmt#Sprintf
func Sprintf(format string, a ...interface{}) string { return fmt.Sprintf(format, a...) }
// Errorf convenience function.
//
// See: https://pkg.go.dev/fmt#Errorf
func Errorf(format string, a ...interface{}) error { return fmt.Errorf(format, a...) }
// Str converts an int to a string.
func Str(i int) string {
return strconv.Itoa(i)
}
func fmtError(err error, not bool) (rstr string) {
defer func() {
if not {
if err == ErrAny {
rstr = "<nil>"
} else {
rstr = "NOT " + rstr
}
}
}()
if err == nil {
return "<nil>"
} else if err == PanicExpected {
return "<panic>"
} else if err == ErrAny {
return "<any error>"
}
switch err := err.(type) {
case ErrContains:
return "<contains: \"" + err.Substr + "\">"
}
return fmt.Sprintf("%+#v", err)
}
func fmtVal(val interface{}, not bool) string {
if not {
return fmt.Sprintf("NOT %+#v", val)
}
return fmt.Sprintf("%+#v", val)
}