-
Notifications
You must be signed in to change notification settings - Fork 0
/
errorsubject.go
41 lines (33 loc) · 989 Bytes
/
errorsubject.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
package assert
func Error(value error) *ErrorSubject {
return &ErrorSubject{value: value}
}
type ErrorSubject struct {
Subject
value error
}
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() {
if subject.value != nil {
subject.FailWithMessage("Not true that " + subject.DisplayString() + " is nil.")
}
}
func (subject *ErrorSubject) IsNotNil() {
if subject.value == nil {
subject.FailWithMessage("Not true that the error is not nil.")
}
}