-
Notifications
You must be signed in to change notification settings - Fork 0
/
pointersubject.go
45 lines (36 loc) · 1.05 KB
/
pointersubject.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
package assert
import (
"fmt"
)
func Pointer(value interface{}) *PointerSubject {
return &PointerSubject{value: value}
}
type PointerSubject struct {
Subject
value interface{}
}
func (subject *PointerSubject) Named(name string) *PointerSubject {
subject.Subject.Named(name)
return subject
}
func (subject *PointerSubject) Fail(verb string, other interface{}) {
subject.FailWithMessage(fmt.Sprintf("Not true that %s %s <%v>.", subject.DisplayString(), verb, other))
}
func (subject *PointerSubject) DisplayString() string {
return subject.Subject.DisplayString(fmt.Sprintf("%v", subject.value))
}
func (subject *PointerSubject) Equals(expectation interface{}) {
if subject.value != expectation {
subject.Fail("is equal to", expectation)
}
}
func (subject *PointerSubject) IsNil() {
if subject.value != nil {
subject.FailWithMessage("Not true that " + subject.DisplayString() + " is nil.")
}
}
func (subject *PointerSubject) IsNotNil() {
if subject.value == nil {
subject.FailWithMessage("Not true that " + subject.DisplayString() + " is not nil.")
}
}