4 This package implements the Gomega matchers and does not typically need to be imported.
5 See the docs for Gomega for documentation on the matchers
7 http://onsi.github.io/gomega/
16 type omegaMatcher interface {
17 Match(actual interface{}) (success bool, err error)
18 FailureMessage(actual interface{}) (message string)
19 NegatedFailureMessage(actual interface{}) (message string)
22 func isBool(a interface{}) bool {
23 return reflect.TypeOf(a).Kind() == reflect.Bool
26 func isNumber(a interface{}) bool {
30 kind := reflect.TypeOf(a).Kind()
31 return reflect.Int <= kind && kind <= reflect.Float64
34 func isInteger(a interface{}) bool {
35 kind := reflect.TypeOf(a).Kind()
36 return reflect.Int <= kind && kind <= reflect.Int64
39 func isUnsignedInteger(a interface{}) bool {
40 kind := reflect.TypeOf(a).Kind()
41 return reflect.Uint <= kind && kind <= reflect.Uint64
44 func isFloat(a interface{}) bool {
45 kind := reflect.TypeOf(a).Kind()
46 return reflect.Float32 <= kind && kind <= reflect.Float64
49 func toInteger(a interface{}) int64 {
51 return reflect.ValueOf(a).Int()
52 } else if isUnsignedInteger(a) {
53 return int64(reflect.ValueOf(a).Uint())
54 } else if isFloat(a) {
55 return int64(reflect.ValueOf(a).Float())
57 panic(fmt.Sprintf("Expected a number! Got <%T> %#v", a, a))
61 func toUnsignedInteger(a interface{}) uint64 {
63 return uint64(reflect.ValueOf(a).Int())
64 } else if isUnsignedInteger(a) {
65 return reflect.ValueOf(a).Uint()
66 } else if isFloat(a) {
67 return uint64(reflect.ValueOf(a).Float())
69 panic(fmt.Sprintf("Expected a number! Got <%T> %#v", a, a))
73 func toFloat(a interface{}) float64 {
75 return float64(reflect.ValueOf(a).Int())
76 } else if isUnsignedInteger(a) {
77 return float64(reflect.ValueOf(a).Uint())
78 } else if isFloat(a) {
79 return reflect.ValueOf(a).Float()
81 panic(fmt.Sprintf("Expected a number! Got <%T> %#v", a, a))
85 func isError(a interface{}) bool {
90 func isChan(a interface{}) bool {
94 return reflect.TypeOf(a).Kind() == reflect.Chan
97 func isMap(a interface{}) bool {
101 return reflect.TypeOf(a).Kind() == reflect.Map
104 func isArrayOrSlice(a interface{}) bool {
108 switch reflect.TypeOf(a).Kind() {
109 case reflect.Array, reflect.Slice:
116 func isString(a interface{}) bool {
120 return reflect.TypeOf(a).Kind() == reflect.String
123 func toString(a interface{}) (string, bool) {
124 aString, isString := a.(string)
129 aBytes, isBytes := a.([]byte)
131 return string(aBytes), true
134 aStringer, isStringer := a.(fmt.Stringer)
136 return aStringer.String(), true
142 func lengthOf(a interface{}) (int, bool) {
146 switch reflect.TypeOf(a).Kind() {
147 case reflect.Map, reflect.Array, reflect.String, reflect.Chan, reflect.Slice:
148 return reflect.ValueOf(a).Len(), true
153 func capOf(a interface{}) (int, bool) {
157 switch reflect.TypeOf(a).Kind() {
158 case reflect.Array, reflect.Chan, reflect.Slice:
159 return reflect.ValueOf(a).Cap(), true
165 func isNil(a interface{}) bool {
170 switch reflect.TypeOf(a).Kind() {
171 case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Ptr, reflect.Slice:
172 return reflect.ValueOf(a).IsNil()