push
github
0 of 14 new or added lines in 2 files covered. (0.0%)
1325 of 1534 relevant lines covered (86.38%)
15.28 hits per line
1 |
package internals
|
|
2 |
|
|
3 |
import (
|
|
4 |
"fmt"
|
|
5 |
"reflect"
|
|
6 |
) |
|
7 |
|
|
8 |
// checks that the value is the zero value for its type
|
|
9 |
func IsZeroValue(x any) bool { |
248✔ |
10 |
if x == nil { |
265✔ |
11 |
return true |
17✔ |
12 |
} |
17✔ |
13 |
|
|
14 |
v := reflect.ValueOf(x) |
231✔ |
15 |
if !v.IsValid() {
|
231✔ |
16 |
return true |
× |
17 |
} |
× |
18 |
|
|
19 |
// Check if the value is the zero value for its type
|
|
20 |
zeroValue := reflect.Zero(v.Type()) |
231✔ |
21 |
return reflect.DeepEqual(v.Interface(), zeroValue.Interface())
|
231✔ |
22 |
} |
|
23 |
|
|
NEW
|
func SafeString(x any) string { |
× |
NEW
|
if x == nil { |
× |
NEW
|
return "<nil>" |
× |
NEW
|
} |
× |
NEW
|
return fmt.Sprintf("%v", x) |
× |
29 |
} |
|
30 |
|
|
NEW
|
func SafeError(x error) string { |
× |
NEW
|
if x == nil { |
× |
NEW
|
return "<nil>" |
× |
NEW
|
} |
× |
NEW
|
return x.Error()
|
× |
36 |
} |