bytessubject.go 837 B

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