2016-05-24 15:55:46 -04:00
|
|
|
package assert
|
|
|
|
|
|
|
|
import (
|
2016-06-27 16:22:01 -04:00
|
|
|
"reflect"
|
|
|
|
|
2016-08-20 14:55:45 -04:00
|
|
|
"v2ray.com/core/common/serial"
|
2016-05-24 15:55:46 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func (this *Assert) Pointer(value interface{}) *PointerSubject {
|
|
|
|
return &PointerSubject{
|
|
|
|
Subject: Subject{
|
|
|
|
a: this,
|
|
|
|
disp: serial.PointerToString(value),
|
|
|
|
},
|
|
|
|
value: value,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type PointerSubject struct {
|
|
|
|
Subject
|
|
|
|
value interface{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (subject *PointerSubject) Equals(expectation interface{}) {
|
|
|
|
if subject.value != expectation {
|
|
|
|
subject.Fail("is equal to", serial.PointerToString(expectation))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (subject *PointerSubject) IsNil() {
|
2016-06-27 16:22:01 -04: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 15:55:46 -04:00
|
|
|
subject.Fail("is", "nil")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (subject *PointerSubject) IsNotNil() {
|
|
|
|
if subject.value == nil {
|
|
|
|
subject.Fail("is not", "nil")
|
|
|
|
}
|
2016-06-27 16:22:01 -04: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 15:55:46 -04:00
|
|
|
}
|