2015-09-09 09:18:29 -04:00
|
|
|
package unit
|
|
|
|
|
2015-09-24 16:24:00 -04:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2015-09-09 09:18:29 -04:00
|
|
|
type ErrorSubject struct {
|
|
|
|
*Subject
|
|
|
|
value error
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewErrorSubject(base *Subject, value error) *ErrorSubject {
|
2015-09-20 07:08:05 -04:00
|
|
|
return &ErrorSubject{
|
|
|
|
Subject: base,
|
|
|
|
value: value,
|
|
|
|
}
|
2015-09-09 09:18:29 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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() {
|
2015-09-09 09:26:11 -04:00
|
|
|
if subject.value != nil {
|
|
|
|
subject.FailWithMessage("Not true that " + subject.DisplayString() + " is nil.")
|
|
|
|
}
|
|
|
|
}
|
2015-09-24 16:24:00 -04:00
|
|
|
|
|
|
|
func (subject *ErrorSubject) HasCode(code int) {
|
|
|
|
errorPrefix := fmt.Sprintf("[Error 0x%04X]", code)
|
|
|
|
if !strings.Contains(subject.value.Error(), errorPrefix) {
|
|
|
|
subject.FailWithMessage(fmt.Sprintf("Not ture that %s has error code 0x%04X.", subject.DisplayString(), code))
|
|
|
|
}
|
|
|
|
}
|