stringsubject.go 740 B

1234567891011121314151617181920212223242526272829303132
  1. package unit
  2. type StringSubject struct {
  3. *Subject
  4. value string
  5. }
  6. func NewStringSubject(base *Subject, value string) *StringSubject {
  7. return &StringSubject{
  8. Subject: base,
  9. value: value,
  10. }
  11. }
  12. func (subject *StringSubject) Named(name string) *StringSubject {
  13. subject.Subject.Named(name)
  14. return subject
  15. }
  16. func (subject *StringSubject) Fail(verb string, other string) {
  17. subject.FailWithMessage("Not true that " + subject.DisplayString() + " " + verb + " <" + other + ">.")
  18. }
  19. func (subject *StringSubject) DisplayString() string {
  20. return subject.Subject.DisplayString(subject.value)
  21. }
  22. func (subject *StringSubject) Equals(expectation string) {
  23. if subject.value != expectation {
  24. subject.Fail("is equal to", expectation)
  25. }
  26. }