ip.go 733 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. package assert
  2. import (
  3. "bytes"
  4. "net"
  5. "github.com/v2ray/v2ray-core/common/serial"
  6. )
  7. func IP(value net.IP) *IPSubject {
  8. return &IPSubject{value: value}
  9. }
  10. type IPSubject struct {
  11. Subject
  12. value net.IP
  13. }
  14. func (subject *IPSubject) Named(name string) *IPSubject {
  15. subject.Subject.Named(name)
  16. return subject
  17. }
  18. func (subject *IPSubject) DisplayString() string {
  19. return subject.Subject.DisplayString(subject.value.String())
  20. }
  21. func (subject *IPSubject) IsNil() {
  22. if subject.value != nil {
  23. subject.Fail(subject.DisplayString(), "is", serial.StringT("nil"))
  24. }
  25. }
  26. func (subject *IPSubject) Equals(ip net.IP) {
  27. if !bytes.Equal([]byte(subject.value), []byte(ip)) {
  28. subject.Fail(subject.DisplayString(), "equals to", ip)
  29. }
  30. }