You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
v2ray-core/testing/assert/pointer.go

57 lines
1.0 KiB

9 years ago
package assert
import (
9 years ago
"reflect"
"v2ray.com/core/common/serial"
9 years ago
)
8 years ago
func (v *Assert) Pointer(value interface{}) *PointerSubject {
9 years ago
return &PointerSubject{
Subject: Subject{
8 years ago
a: v,
disp: serial.ToString(value),
9 years ago
},
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() {
9 years ago
if subject.value == nil {
return
}
valueType := reflect.TypeOf(subject.value)
nilType := reflect.Zero(valueType)
realValue := reflect.ValueOf(subject.value)
if nilType != realValue {
9 years ago
subject.Fail("is", "nil")
}
}
func (subject *PointerSubject) IsNotNil() {
if subject.value == nil {
subject.Fail("is not", "nil")
}
9 years ago
valueType := reflect.TypeOf(subject.value)
nilType := reflect.Zero(valueType)
realValue := reflect.ValueOf(subject.value)
if nilType == realValue {
subject.Fail("is not", "nil")
}
9 years ago
}