-
Notifications
You must be signed in to change notification settings - Fork 0
/
address.go
67 lines (55 loc) · 1.71 KB
/
address.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package assert
import (
v2net "github.com/v2ray/v2ray-core/common/net"
"github.com/v2ray/v2ray-core/common/serial"
"github.com/v2ray/v2ray-core/testing/assert"
)
func Address(value v2net.Address) *AddressSubject {
return &AddressSubject{value: value}
}
type AddressSubject struct {
assert.Subject
value v2net.Address
}
func (subject *AddressSubject) Named(name string) *AddressSubject {
subject.Subject.Named(name)
return subject
}
func (subject *AddressSubject) DisplayString() string {
return subject.Subject.DisplayString(subject.value.String())
}
func (subject *AddressSubject) Equals(another v2net.Address) {
if !subject.value.Equals(another) {
subject.Fail(subject.DisplayString(), "equals to", another)
}
}
func (subject *AddressSubject) IsIPv4() {
if !subject.value.IsIPv4() {
subject.Fail(subject.DisplayString(), "is", serial.StringLiteral("an IPv4 address"))
}
}
func (subject *AddressSubject) IsNotIPv4() {
if subject.value.IsIPv4() {
subject.Fail(subject.DisplayString(), "is not", serial.StringLiteral("an IPv4 address"))
}
}
func (subject *AddressSubject) IsIPv6() {
if !subject.value.IsIPv6() {
subject.Fail(subject.DisplayString(), "is", serial.StringLiteral("an IPv6 address"))
}
}
func (subject *AddressSubject) IsNotIPv6() {
if subject.value.IsIPv6() {
subject.Fail(subject.DisplayString(), "is not", serial.StringLiteral("an IPv6 address"))
}
}
func (subject *AddressSubject) IsDomain() {
if !subject.value.IsDomain() {
subject.Fail(subject.DisplayString(), "is", serial.StringLiteral("a domain address"))
}
}
func (subject *AddressSubject) IsNotDomain() {
if subject.value.IsDomain() {
subject.Fail(subject.DisplayString(), "is not", serial.StringLiteral("a domain address"))
}
}