-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalue_extractor_numeric.go
68 lines (64 loc) · 1.91 KB
/
value_extractor_numeric.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
56
57
58
59
60
61
62
63
64
65
66
67
68
package justest
import (
"cmp"
"reflect"
)
var (
NumericValueExtractor = NewNumericValueExtractor()
)
//go:noinline
func NewNumericValueExtractor() ValueExtractor {
sve := NewValueExtractor(ExtractorUnsupported)
sve[reflect.Chan] = NewChannelExtractor(sve, true)
sve[reflect.Float32] = ExtractSameValue
sve[reflect.Float64] = ExtractSameValue
sve[reflect.Func] = NewFuncExtractor(sve, true)
sve[reflect.Int] = ExtractSameValue
sve[reflect.Int8] = ExtractSameValue
sve[reflect.Int16] = ExtractSameValue
sve[reflect.Int32] = ExtractSameValue
sve[reflect.Int64] = ExtractSameValue
sve[reflect.Pointer] = NewPointerExtractor(sve, true)
sve[reflect.Uint] = ExtractSameValue
sve[reflect.Uint8] = ExtractSameValue
sve[reflect.Uint16] = ExtractSameValue
sve[reflect.Uint32] = ExtractSameValue
sve[reflect.Uint64] = ExtractSameValue
return sve
}
// getNumericCompareFuncFor returns a reflection wrapper for the [cmp.Compare] function with the correct generic type
// for the numeric type provided.
//
//go:noinline
func getNumericCompareFuncFor(t T, v any) reflect.Value {
GetHelper(t).Helper()
switch v.(type) {
case int:
return reflect.ValueOf(cmp.Compare[int])
case int8:
return reflect.ValueOf(cmp.Compare[int8])
case int16:
return reflect.ValueOf(cmp.Compare[int16])
case int32:
return reflect.ValueOf(cmp.Compare[int32])
case int64:
return reflect.ValueOf(cmp.Compare[int64])
case uint:
return reflect.ValueOf(cmp.Compare[uint])
case uint8:
return reflect.ValueOf(cmp.Compare[uint8])
case uint16:
return reflect.ValueOf(cmp.Compare[uint16])
case uint32:
return reflect.ValueOf(cmp.Compare[uint32])
case uint64:
return reflect.ValueOf(cmp.Compare[uint64])
case float32:
return reflect.ValueOf(cmp.Compare[float32])
case float64:
return reflect.ValueOf(cmp.Compare[float64])
default:
t.Fatalf("Type '%T' of actual '%+v' does not have a defined comparison function", v, v)
panic("unreachable")
}
}