-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhamcrest_implements.go
More file actions
34 lines (28 loc) · 878 Bytes
/
hamcrest_implements.go
File metadata and controls
34 lines (28 loc) · 878 Bytes
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
package assert
import (
"reflect"
)
type implementsMatcher struct {
expectedValue interface{}
message string
}
// Implements checks if the value implements the expected value
func Implements(expectedValue interface{}) *implementsMatcher {
m := new(implementsMatcher)
m.expectedValue = expectedValue
return m
}
func (m *implementsMatcher) Message(message string) Matcher {
m.message = message
return m
}
func (m *implementsMatcher) Matches(value interface{}) bool {
expectedType := reflect.TypeOf(m.expectedValue).Elem()
valueType := reflect.TypeOf(value)
return valueType.Implements(expectedType)
}
func (m *implementsMatcher) DescribeMismatch(value interface{}) error {
expectedType := reflect.TypeOf(m.expectedValue).Elem()
valueType := reflect.TypeOf(value)
return buildError("expected type '%v' but got '%v'", m.message, expectedType, valueType)
}