bytes.go 922 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. return
  24. }
  25. for idx, b := range expectation {
  26. if subject.value[idx] != b {
  27. subject.FailWithMessage(fmt.Sprint("Bytes are different: ", b, " vs ", subject.value[idx]))
  28. return
  29. }
  30. }
  31. }
  32. func (subject *BytesSubject) NotEquals(expectation []byte) {
  33. if bytes.Equal(subject.value, expectation) {
  34. subject.Fail("is not equal to", serial.BytesToHexString(expectation))
  35. }
  36. }