address.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package assert
  2. import (
  3. "v2ray.com/core/common/net"
  4. )
  5. func (v *Assert) Address(value net.Address) *AddressSubject {
  6. return &AddressSubject{
  7. Subject: Subject{
  8. disp: value.String(),
  9. a: v,
  10. },
  11. value: value,
  12. }
  13. }
  14. type AddressSubject struct {
  15. Subject
  16. value net.Address
  17. }
  18. func (subject *AddressSubject) NotEquals(another net.Address) {
  19. if subject.value == another {
  20. subject.Fail("not equals to", another.String())
  21. }
  22. }
  23. func (subject *AddressSubject) Equals(another net.Address) {
  24. if subject.value != another {
  25. subject.Fail("equals to", another.String())
  26. }
  27. }
  28. func (subject *AddressSubject) NotEqualsString(another string) {
  29. if subject.value.String() == another {
  30. subject.Fail("not equals to string", another)
  31. }
  32. }
  33. func (subject *AddressSubject) EqualsString(another string) {
  34. if subject.value.String() != another {
  35. subject.Fail("equals to string", another)
  36. }
  37. }
  38. func (subject *AddressSubject) IsIPv4() {
  39. if !subject.value.Family().IsIPv4() {
  40. subject.Fail("is", "an IPv4 address")
  41. }
  42. }
  43. func (subject *AddressSubject) IsNotIPv4() {
  44. if subject.value.Family().IsIPv4() {
  45. subject.Fail("is not", "an IPv4 address")
  46. }
  47. }
  48. func (subject *AddressSubject) IsIPv6() {
  49. if !subject.value.Family().IsIPv6() {
  50. subject.Fail("is", "an IPv6 address")
  51. }
  52. }
  53. func (subject *AddressSubject) IsNotIPv6() {
  54. if subject.value.Family().IsIPv6() {
  55. subject.Fail("is not", "an IPv6 address")
  56. }
  57. }
  58. func (subject *AddressSubject) IsDomain() {
  59. if !subject.value.Family().IsDomain() {
  60. subject.Fail("is", "a domain address")
  61. }
  62. }
  63. func (subject *AddressSubject) IsNotDomain() {
  64. if subject.value.Family().IsDomain() {
  65. subject.Fail("is not", "a domain address")
  66. }
  67. }