-
Notifications
You must be signed in to change notification settings - Fork 0
/
pointer.go
56 lines (45 loc) · 1.02 KB
/
pointer.go
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package assert
import (
"reflect"
"v2ray.com/core/common/serial"
)
func (v *Assert) Pointer(value interface{}) *PointerSubject {
return &PointerSubject{
Subject: Subject{
a: v,
disp: serial.ToString(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.ToString(expectation))
}
}
func (subject *PointerSubject) IsNil() {
if subject.value == nil {
return
}
valueType := reflect.TypeOf(subject.value)
nilType := reflect.Zero(valueType)
realValue := reflect.ValueOf(subject.value)
if nilType != realValue {
subject.Fail("is", "nil")
}
}
func (subject *PointerSubject) IsNotNil() {
if subject.value == nil {
subject.Fail("is not", "nil")
}
valueType := reflect.TypeOf(subject.value)
nilType := reflect.Zero(valueType)
realValue := reflect.ValueOf(subject.value)
if nilType == realValue {
subject.Fail("is not", "nil")
}
}