bytes.go 908 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package assert
  2. import (
  3. "bytes"
  4. "fmt"
  5. "v2ray.com/core/common/serial"
  6. )
  7. func (v *Assert) Bytes(value []byte) *BytesSubject {
  8. return &BytesSubject{
  9. Subject: Subject{
  10. disp: serial.BytesToHexString(value),
  11. a: v,
  12. },
  13. value: value,
  14. }
  15. }
  16. type BytesSubject struct {
  17. Subject
  18. value []byte
  19. }
  20. func (subject *BytesSubject) Equals(expectation []byte) {
  21. if len(subject.value) != len(expectation) {
  22. subject.FailWithMessage(fmt.Sprint("Bytes arrays have differen size: expected", len(expectation), ", actual", len(subject.value)))
  23. }
  24. for idx, b := range expectation {
  25. if subject.value[idx] != b {
  26. subject.FailWithMessage(fmt.Sprint("Bytes are different:", b, "vs", subject.value[idx]))
  27. return
  28. }
  29. }
  30. }
  31. func (subject *BytesSubject) NotEquals(expectation []byte) {
  32. if bytes.Equal(subject.value, expectation) {
  33. subject.Fail("is not equal to", serial.BytesToHexString(expectation))
  34. }
  35. }