2016-05-24 19:55:46 +00:00
|
|
|
package assert
|
|
|
|
|
|
|
|
import (
|
2016-06-27 20:22:01 +00:00
|
|
|
"reflect"
|
|
|
|
|
2016-08-20 18:55:45 +00:00
|
|
|
"v2ray.com/core/common/serial"
|
2016-05-24 19:55:46 +00:00
|
|
|
)
|
|
|
|
|
2016-11-27 20:39:09 +00:00
|
|
|
func (v *Assert) Pointer(value interface{}) *PointerSubject {
|
2016-05-24 19:55:46 +00:00
|
|
|
return &PointerSubject{
|
|
|
|
Subject: Subject{
|
2016-11-27 20:39:09 +00:00
|
|
|
a: v,
|
2016-12-06 12:42:21 +00:00
|
|
|
disp: serial.ToString(value),
|
2016-05-24 19:55:46 +00:00
|
|
|
},
|
|
|
|
value: value,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type PointerSubject struct {
|
|
|
|
Subject
|
|
|
|
value interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (subject *PointerSubject) Equals(expectation interface{}) {
|
|
|
|
if subject.value != expectation {
|
2016-12-06 23:31:08 +00:00
|
|
|
subject.Fail("is equal to", serial.ToString(expectation))
|
2016-05-24 19:55:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (subject *PointerSubject) IsNil() {
|
2016-06-27 20:22:01 +00:00
|
|
|
if subject.value == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
valueType := reflect.TypeOf(subject.value)
|
|
|
|
nilType := reflect.Zero(valueType)
|
|
|
|
realValue := reflect.ValueOf(subject.value)
|
|
|
|
|
|
|
|
if nilType != realValue {
|
2016-05-24 19:55:46 +00:00
|
|
|
subject.Fail("is", "nil")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (subject *PointerSubject) IsNotNil() {
|
|
|
|
if subject.value == nil {
|
|
|
|
subject.Fail("is not", "nil")
|
|
|
|
}
|
2016-06-27 20:22:01 +00:00
|
|
|
|
|
|
|
valueType := reflect.TypeOf(subject.value)
|
|
|
|
nilType := reflect.Zero(valueType)
|
|
|
|
realValue := reflect.ValueOf(subject.value)
|
|
|
|
|
|
|
|
if nilType == realValue {
|
|
|
|
subject.Fail("is not", "nil")
|
|
|
|
}
|
2016-05-24 19:55:46 +00:00
|
|
|
}
|