boolsubject.go 980 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package unit
  2. import (
  3. "strconv"
  4. )
  5. type BoolSubject struct {
  6. *Subject
  7. value bool
  8. }
  9. func NewBoolSubject(base *Subject, value bool) *BoolSubject {
  10. return &BoolSubject{
  11. Subject: base,
  12. value: value,
  13. }
  14. }
  15. func (subject *BoolSubject) Named(name string) *BoolSubject {
  16. subject.Subject.Named(name)
  17. return subject
  18. }
  19. func (subject *BoolSubject) Fail(verb string, other bool) {
  20. subject.FailWithMessage("Not true that " + subject.DisplayString() + " " + verb + " <" + strconv.FormatBool(other) + ">.")
  21. }
  22. func (subject *BoolSubject) DisplayString() string {
  23. return subject.Subject.DisplayString(strconv.FormatBool(subject.value))
  24. }
  25. func (subject *BoolSubject) Equals(expectation bool) {
  26. if subject.value != expectation {
  27. subject.Fail("is equal to", expectation)
  28. }
  29. }
  30. func (subject *BoolSubject) IsTrue() {
  31. if subject.value != true {
  32. subject.Fail("is", true)
  33. }
  34. }
  35. func (subject *BoolSubject) IsFalse() {
  36. if subject.value != false {
  37. subject.Fail("is", false)
  38. }
  39. }