bool.go 734 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package assert
  2. import (
  3. "strconv"
  4. )
  5. // Assert on a boolean variable.
  6. func (this *Assert) Bool(value bool) *BoolSubject {
  7. return &BoolSubject{
  8. Subject: Subject{
  9. disp: strconv.FormatBool(value),
  10. a: this,
  11. },
  12. value: value,
  13. }
  14. }
  15. type BoolSubject struct {
  16. Subject
  17. value bool
  18. }
  19. // to be equal to another boolean variable.
  20. func (subject *BoolSubject) Equals(expectation bool) {
  21. if subject.value != expectation {
  22. subject.Fail("is equal to", strconv.FormatBool(expectation))
  23. }
  24. }
  25. // to be true.
  26. func (subject *BoolSubject) IsTrue() {
  27. if subject.value != true {
  28. subject.Fail("is", "True")
  29. }
  30. }
  31. // to be false.
  32. func (subject *BoolSubject) IsFalse() {
  33. if subject.value != false {
  34. subject.Fail("is", "False")
  35. }
  36. }