mirror of https://github.com/v2ray/v2ray-core
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.
42 lines
989 B
42 lines
989 B
9 years ago
|
package assert
|
||
9 years ago
|
|
||
9 years ago
|
func Error(value error) *ErrorSubject {
|
||
|
return &ErrorSubject{value: value}
|
||
9 years ago
|
}
|
||
|
|
||
9 years ago
|
type ErrorSubject struct {
|
||
|
Subject
|
||
|
value error
|
||
9 years ago
|
}
|
||
|
|
||
|
func (subject *ErrorSubject) Named(name string) *ErrorSubject {
|
||
|
subject.Subject.Named(name)
|
||
|
return subject
|
||
|
}
|
||
|
|
||
|
func (subject *ErrorSubject) Fail(verb string, other error) {
|
||
|
subject.FailWithMessage("Not true that " + subject.DisplayString() + " " + verb + " <" + other.Error() + ">.")
|
||
|
}
|
||
|
|
||
|
func (subject *ErrorSubject) DisplayString() string {
|
||
|
return subject.Subject.DisplayString(subject.value.Error())
|
||
|
}
|
||
|
|
||
|
func (subject *ErrorSubject) Equals(expectation error) {
|
||
|
if subject.value != expectation {
|
||
|
subject.Fail("is equal to", expectation)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func (subject *ErrorSubject) IsNil() {
|
||
9 years ago
|
if subject.value != nil {
|
||
|
subject.FailWithMessage("Not true that " + subject.DisplayString() + " is nil.")
|
||
|
}
|
||
|
}
|
||
9 years ago
|
|
||
|
func (subject *ErrorSubject) IsNotNil() {
|
||
|
if subject.value == nil {
|
||
|
subject.FailWithMessage("Not true that the error is not nil.")
|
||
|
}
|
||
|
}
|