errorsubject.go 930 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package unit
  2. type ErrorSubject struct {
  3. *Subject
  4. value error
  5. }
  6. func NewErrorSubject(base *Subject, value error) *ErrorSubject {
  7. subject := new(ErrorSubject)
  8. subject.Subject = base
  9. subject.value = value
  10. return subject
  11. }
  12. func (subject *ErrorSubject) Named(name string) *ErrorSubject {
  13. subject.Subject.Named(name)
  14. return subject
  15. }
  16. func (subject *ErrorSubject) Fail(verb string, other error) {
  17. subject.FailWithMessage("Not true that " + subject.DisplayString() + " " + verb + " <" + other.Error() + ">.")
  18. }
  19. func (subject *ErrorSubject) DisplayString() string {
  20. return subject.Subject.DisplayString(subject.value.Error())
  21. }
  22. func (subject *ErrorSubject) Equals(expectation error) {
  23. if subject.value != expectation {
  24. subject.Fail("is equal to", expectation)
  25. }
  26. }
  27. func (subject *ErrorSubject) IsNil() {
  28. if subject.value != nil {
  29. subject.FailWithMessage("Not true that " + subject.DisplayString() + " is nil.")
  30. }
  31. }