-
Notifications
You must be signed in to change notification settings - Fork 1
/
hamcrest_util.go
63 lines (58 loc) · 1.32 KB
/
hamcrest_util.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
package assert
import (
"fmt"
"reflect"
)
func buildError(format string, message string, args ...interface{}) error {
if len(message) == 0 {
return fmt.Errorf(format, args...)
}
var a []interface{}
b := append(a, message)
c := append(b, args...)
return fmt.Errorf("%s, "+format, c...)
}
func sameType(a interface{}, b interface{}) bool {
aType := reflect.TypeOf(a)
bType := reflect.TypeOf(b)
return aType == bType
}
func less(a interface{}, b interface{}) bool {
if sameType(a, b) {
switch a.(type) {
case int:
return a.(int) < b.(int)
case int8:
return a.(int8) < b.(int8)
case int16:
return a.(int16) < b.(int16)
case int32:
return a.(int32) < b.(int32)
case int64:
return a.(int64) < b.(int64)
case uint:
return a.(uint) < b.(uint)
case uint8:
return a.(uint8) < b.(uint8)
case uint16:
return a.(uint16) < b.(uint16)
case uint32:
return a.(uint32) < b.(uint32)
case uint64:
return a.(uint64) < b.(uint64)
case float32:
return a.(float32) < b.(float32)
case float64:
return a.(float64) < b.(float64)
}
panic(fmt.Sprintf("unsupport typ: %v", reflect.TypeOf(a)))
}
return false
}
func isByteArray(value interface{}) bool {
if value == nil {
return false
}
typ := reflect.TypeOf(value)
return typ.Kind() == reflect.Slice && typ.Elem().Kind() == reflect.Uint8
}