2015-12-02 16:27:55 +00:00
|
|
|
package assert
|
2015-12-02 15:19:39 +00:00
|
|
|
|
|
|
|
import (
|
2017-01-14 00:27:45 +01:00
|
|
|
"v2ray.com/core/common/net"
|
2015-12-02 15:19:39 +00:00
|
|
|
)
|
|
|
|
|
2017-01-14 00:27:45 +01:00
|
|
|
func (v *Assert) Address(value net.Address) *AddressSubject {
|
2016-05-24 21:55:46 +02:00
|
|
|
return &AddressSubject{
|
|
|
|
Subject: Subject{
|
|
|
|
disp: value.String(),
|
2016-11-27 21:39:09 +01:00
|
|
|
a: v,
|
2016-05-24 21:55:46 +02:00
|
|
|
},
|
|
|
|
value: value,
|
|
|
|
}
|
2015-12-02 15:19:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type AddressSubject struct {
|
2016-05-24 15:29:08 +02:00
|
|
|
Subject
|
2017-01-14 00:27:45 +01:00
|
|
|
value net.Address
|
2015-12-02 15:19:39 +00:00
|
|
|
}
|
|
|
|
|
2017-01-14 00:27:45 +01:00
|
|
|
func (subject *AddressSubject) NotEquals(another net.Address) {
|
2016-11-27 09:19:52 +01:00
|
|
|
if subject.value == another {
|
2016-05-24 21:55:46 +02:00
|
|
|
subject.Fail("not equals to", another.String())
|
|
|
|
}
|
2015-12-02 15:19:39 +00:00
|
|
|
}
|
|
|
|
|
2017-01-14 00:27:45 +01:00
|
|
|
func (subject *AddressSubject) Equals(another net.Address) {
|
2016-11-27 09:19:52 +01:00
|
|
|
if subject.value != another {
|
2016-05-24 21:55:46 +02:00
|
|
|
subject.Fail("equals to", another.String())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (subject *AddressSubject) NotEqualsString(another string) {
|
|
|
|
if subject.value.String() == another {
|
|
|
|
subject.Fail("not equals to string", another)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (subject *AddressSubject) EqualsString(another string) {
|
|
|
|
if subject.value.String() != another {
|
|
|
|
subject.Fail("equals to string", another)
|
2015-12-25 01:07:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-02 15:19:39 +00:00
|
|
|
func (subject *AddressSubject) IsIPv4() {
|
2016-08-14 18:14:12 +02:00
|
|
|
if !subject.value.Family().IsIPv4() {
|
2016-05-24 21:55:46 +02:00
|
|
|
subject.Fail("is", "an IPv4 address")
|
2015-12-02 15:19:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (subject *AddressSubject) IsNotIPv4() {
|
2016-08-14 18:14:12 +02:00
|
|
|
if subject.value.Family().IsIPv4() {
|
2016-05-24 21:55:46 +02:00
|
|
|
subject.Fail("is not", "an IPv4 address")
|
2015-12-02 15:19:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (subject *AddressSubject) IsIPv6() {
|
2016-08-14 18:14:12 +02:00
|
|
|
if !subject.value.Family().IsIPv6() {
|
2016-05-24 21:55:46 +02:00
|
|
|
subject.Fail("is", "an IPv6 address")
|
2015-12-02 15:19:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (subject *AddressSubject) IsNotIPv6() {
|
2016-08-14 18:14:12 +02:00
|
|
|
if subject.value.Family().IsIPv6() {
|
2016-05-24 21:55:46 +02:00
|
|
|
subject.Fail("is not", "an IPv6 address")
|
2015-12-02 15:19:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (subject *AddressSubject) IsDomain() {
|
2016-08-14 18:14:12 +02:00
|
|
|
if !subject.value.Family().IsDomain() {
|
2016-05-24 21:55:46 +02:00
|
|
|
subject.Fail("is", "a domain address")
|
2015-12-02 15:19:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (subject *AddressSubject) IsNotDomain() {
|
2016-08-14 18:14:12 +02:00
|
|
|
if subject.value.Family().IsDomain() {
|
2016-05-24 21:55:46 +02:00
|
|
|
subject.Fail("is not", "a domain address")
|
2015-12-02 15:19:39 +00:00
|
|
|
}
|
|
|
|
}
|