2015-12-02 11:27:55 -05:00
|
|
|
package assert
|
2015-12-02 09:27:18 -05:00
|
|
|
|
|
|
|
import (
|
2016-08-20 14:55:45 -04:00
|
|
|
v2net "v2ray.com/core/common/net"
|
2015-12-02 09:27:18 -05:00
|
|
|
)
|
|
|
|
|
2016-11-27 15:39:09 -05:00
|
|
|
func (v *Assert) Port(value v2net.Port) *PortSubject {
|
2016-05-24 15:55:46 -04:00
|
|
|
return &PortSubject{
|
|
|
|
Subject: Subject{
|
2016-11-27 15:39:09 -05:00
|
|
|
a: v,
|
2016-05-24 15:55:46 -04:00
|
|
|
disp: value.String(),
|
|
|
|
},
|
|
|
|
value: value,
|
|
|
|
}
|
2015-12-02 09:27:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
type PortSubject struct {
|
2016-05-24 09:29:08 -04:00
|
|
|
Subject
|
2015-12-02 09:27:18 -05:00
|
|
|
value v2net.Port
|
|
|
|
}
|
|
|
|
|
|
|
|
func (subject *PortSubject) Equals(expectation v2net.Port) {
|
|
|
|
if subject.value.Value() != expectation.Value() {
|
2016-05-24 15:55:46 -04:00
|
|
|
subject.Fail("is equal to", expectation.String())
|
2015-12-02 09:27:18 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (subject *PortSubject) GreaterThan(expectation v2net.Port) {
|
|
|
|
if subject.value.Value() <= expectation.Value() {
|
2016-05-24 15:55:46 -04:00
|
|
|
subject.Fail("is greater than", expectation.String())
|
2015-12-02 09:27:18 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (subject *PortSubject) LessThan(expectation v2net.Port) {
|
|
|
|
if subject.value.Value() >= expectation.Value() {
|
2016-05-24 15:55:46 -04:00
|
|
|
subject.Fail("is less than", expectation.String())
|
2015-12-02 09:27:18 -05:00
|
|
|
}
|
|
|
|
}
|
2015-12-02 15:44:01 -05:00
|
|
|
|
|
|
|
func (subject *PortSubject) IsValid() {
|
2015-12-02 15:58:46 -05:00
|
|
|
if subject.value == 0 {
|
2016-05-24 15:55:46 -04:00
|
|
|
subject.Fail("is", "a valid port")
|
2015-12-02 15:58:46 -05:00
|
|
|
}
|
2015-12-02 15:44:01 -05:00
|
|
|
}
|