2015-12-02 09:27:18 -05:00
|
|
|
package assert
|
2015-09-20 05:45:40 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2015-12-02 09:27:18 -05:00
|
|
|
func Pointer(value interface{}) *PointerSubject {
|
|
|
|
return &PointerSubject{value: value}
|
2015-09-20 05:45:40 -04:00
|
|
|
}
|
|
|
|
|
2015-12-02 09:27:18 -05:00
|
|
|
type PointerSubject struct {
|
|
|
|
Subject
|
|
|
|
value interface{}
|
2015-09-20 05:45:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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.")
|
|
|
|
}
|
|
|
|
}
|