mirror of
https://github.com/v2fly/v2ray-core
synced 2024-02-27 03:18:06 +00:00
typed segments
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package assert
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
|
||||
"github.com/v2ray/v2ray-core/common/serial"
|
||||
)
|
||||
|
||||
@@ -26,7 +28,15 @@ func (subject *PointerSubject) Equals(expectation interface{}) {
|
||||
}
|
||||
|
||||
func (subject *PointerSubject) IsNil() {
|
||||
if subject.value != nil {
|
||||
if subject.value == nil {
|
||||
return
|
||||
}
|
||||
|
||||
valueType := reflect.TypeOf(subject.value)
|
||||
nilType := reflect.Zero(valueType)
|
||||
realValue := reflect.ValueOf(subject.value)
|
||||
|
||||
if nilType != realValue {
|
||||
subject.Fail("is", "nil")
|
||||
}
|
||||
}
|
||||
@@ -35,4 +45,12 @@ func (subject *PointerSubject) IsNotNil() {
|
||||
if subject.value == nil {
|
||||
subject.Fail("is not", "nil")
|
||||
}
|
||||
|
||||
valueType := reflect.TypeOf(subject.value)
|
||||
nilType := reflect.Zero(valueType)
|
||||
realValue := reflect.ValueOf(subject.value)
|
||||
|
||||
if nilType == realValue {
|
||||
subject.Fail("is not", "nil")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package assert
|
||||
|
||||
import (
|
||||
"github.com/v2ray/v2ray-core/common/serial"
|
||||
)
|
||||
|
||||
func (this *Assert) Uint32(value uint32) *Uint32Subject {
|
||||
return &Uint32Subject{
|
||||
Subject: Subject{
|
||||
a: this,
|
||||
disp: serial.Uint32ToString(value),
|
||||
},
|
||||
value: value,
|
||||
}
|
||||
}
|
||||
|
||||
type Uint32Subject struct {
|
||||
Subject
|
||||
value uint32
|
||||
}
|
||||
|
||||
func (subject *Uint32Subject) Equals(expectation uint32) {
|
||||
if subject.value != expectation {
|
||||
subject.Fail("is equal to", serial.Uint32ToString(expectation))
|
||||
}
|
||||
}
|
||||
|
||||
func (subject *Uint32Subject) GreaterThan(expectation uint32) {
|
||||
if subject.value <= expectation {
|
||||
subject.Fail("is greater than", serial.Uint32ToString(expectation))
|
||||
}
|
||||
}
|
||||
|
||||
func (subject *Uint32Subject) LessThan(expectation uint32) {
|
||||
if subject.value >= expectation {
|
||||
subject.Fail("is less than", serial.Uint32ToString(expectation))
|
||||
}
|
||||
}
|
||||
|
||||
func (subject *Uint32Subject) IsPositive() {
|
||||
if subject.value <= 0 {
|
||||
subject.Fail("is", "positive")
|
||||
}
|
||||
}
|
||||
|
||||
func (subject *Uint32Subject) IsNegative() {
|
||||
if subject.value >= 0 {
|
||||
subject.Fail("is not", "negative")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user