mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-10-17 06:24:11 -04:00
massive refactoring against unit test lib
This commit is contained in:
45
testing/assert/pointersubject.go
Normal file
45
testing/assert/pointersubject.go
Normal file
@@ -0,0 +1,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.")
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user