mirror of https://github.com/v2ray/v2ray-core
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.2 KiB
49 lines
1.2 KiB
9 years ago
|
package assert
|
||
9 years ago
|
|
||
|
import (
|
||
|
v2net "github.com/v2ray/v2ray-core/common/net"
|
||
9 years ago
|
"github.com/v2ray/v2ray-core/common/serial"
|
||
9 years ago
|
)
|
||
|
|
||
|
func Port(value v2net.Port) *PortSubject {
|
||
|
return &PortSubject{value: value}
|
||
|
}
|
||
|
|
||
|
type PortSubject struct {
|
||
9 years ago
|
Subject
|
||
9 years ago
|
value v2net.Port
|
||
|
}
|
||
|
|
||
|
func (subject *PortSubject) Named(name string) *PortSubject {
|
||
|
subject.Subject.Named(name)
|
||
|
return subject
|
||
|
}
|
||
|
|
||
|
func (subject *PortSubject) DisplayString() string {
|
||
|
return subject.Subject.DisplayString(subject.value.String())
|
||
|
}
|
||
|
|
||
|
func (subject *PortSubject) Equals(expectation v2net.Port) {
|
||
|
if subject.value.Value() != expectation.Value() {
|
||
9 years ago
|
subject.Fail(subject.DisplayString(), "is equal to", expectation)
|
||
9 years ago
|
}
|
||
|
}
|
||
|
|
||
|
func (subject *PortSubject) GreaterThan(expectation v2net.Port) {
|
||
|
if subject.value.Value() <= expectation.Value() {
|
||
9 years ago
|
subject.Fail(subject.DisplayString(), "is greater than", expectation)
|
||
9 years ago
|
}
|
||
|
}
|
||
|
|
||
|
func (subject *PortSubject) LessThan(expectation v2net.Port) {
|
||
|
if subject.value.Value() >= expectation.Value() {
|
||
9 years ago
|
subject.Fail(subject.DisplayString(), "is less than", expectation)
|
||
9 years ago
|
}
|
||
|
}
|
||
9 years ago
|
|
||
|
func (subject *PortSubject) IsValid() {
|
||
9 years ago
|
if subject.value == 0 {
|
||
9 years ago
|
subject.Fail(subject.DisplayString(), "is", serial.StringT("a valid port"))
|
||
9 years ago
|
}
|
||
9 years ago
|
}
|