bytessubject.go 948 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package assert
  2. import (
  3. "bytes"
  4. "fmt"
  5. )
  6. func Bytes(value []byte) *BytesSubject {
  7. return &BytesSubject{value: value}
  8. }
  9. type BytesSubject struct {
  10. Subject
  11. value []byte
  12. }
  13. func (subject *BytesSubject) Named(name string) *BytesSubject {
  14. subject.Subject.Named(name)
  15. return subject
  16. }
  17. func (subject *BytesSubject) Fail(verb string, other []byte) {
  18. otherString := fmt.Sprintf("%v", other)
  19. subject.FailWithMessage("Not true that " + subject.DisplayString() + " " + verb + " <" + otherString + ">.")
  20. }
  21. func (subject *BytesSubject) DisplayString() string {
  22. return subject.Subject.DisplayString(fmt.Sprintf("%v", subject.value))
  23. }
  24. func (subject *BytesSubject) Equals(expectation []byte) {
  25. if !bytes.Equal(subject.value, expectation) {
  26. subject.Fail("is equal to", expectation)
  27. }
  28. }
  29. func (subject *BytesSubject) NotEquals(expectation []byte) {
  30. if bytes.Equal(subject.value, expectation) {
  31. subject.Fail("is not equal to", expectation)
  32. }
  33. }