1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-21 17:46:58 -05:00

update assertion api

This commit is contained in:
Darien Raymond 2017-10-24 10:03:00 +02:00
parent 6ddafdbd73
commit 4a0ca30d08

View File

@ -7,40 +7,40 @@ import (
"v2ray.com/ext/assert"
)
var IsIPv4 = assert.CreateOperator(reflect.TypeOf(net.Address(nil)), reflect.ValueOf(func(a net.Address) bool {
var IsIPv4 = assert.CreateMatcher(reflect.TypeOf(net.Address(nil)), reflect.ValueOf(func(a net.Address) bool {
return a.Family().IsIPv4()
}), 1, "is IPv4")
var IsIPv6 = assert.CreateOperator(reflect.TypeOf(net.Address(nil)), reflect.ValueOf(func(a net.Address) bool {
var IsIPv6 = assert.CreateMatcher(reflect.TypeOf(net.Address(nil)), reflect.ValueOf(func(a net.Address) bool {
return a.Family().IsIPv6()
}), 1, "is IPv6")
var IsIP = assert.CreateOperator(reflect.TypeOf(net.Address(nil)), reflect.ValueOf(func(a net.Address) bool {
var IsIP = assert.CreateMatcher(reflect.TypeOf(net.Address(nil)), reflect.ValueOf(func(a net.Address) bool {
return a.Family().IsIPv4() || a.Family().IsIPv6()
}), 1, "is IP")
var IsTCP = assert.CreateOperator(reflect.TypeOf(net.Destination{}), reflect.ValueOf(func(a net.Destination) bool {
var IsTCP = assert.CreateMatcher(reflect.TypeOf(net.Destination{}), reflect.ValueOf(func(a net.Destination) bool {
return a.Network == net.Network_TCP
}), 1, "is TCP")
var IsUDP = assert.CreateOperator(reflect.TypeOf(net.Destination{}), reflect.ValueOf(func(a net.Destination) bool {
var IsUDP = assert.CreateMatcher(reflect.TypeOf(net.Destination{}), reflect.ValueOf(func(a net.Destination) bool {
return a.Network == net.Network_UDP
}), 1, "is UDP")
var IsDomain = assert.CreateOperator(reflect.TypeOf(net.Address(nil)), reflect.ValueOf(func(a net.Address) bool {
var IsDomain = assert.CreateMatcher(reflect.TypeOf(net.Address(nil)), reflect.ValueOf(func(a net.Address) bool {
return a.Family().IsDomain()
}), 1, "is Domain")
func init() {
assert.RegisterEqualsOperator(reflect.TypeOf((*net.Address)(nil)).Elem(), reflect.ValueOf(func(a, b net.Address) bool {
assert.RegisterEqualsMatcher(reflect.TypeOf((*net.Address)(nil)).Elem(), reflect.ValueOf(func(a, b net.Address) bool {
return a == b
}))
assert.RegisterEqualsOperator(reflect.TypeOf(net.Destination{}), reflect.ValueOf(func(a, b net.Destination) bool {
assert.RegisterEqualsMatcher(reflect.TypeOf(net.Destination{}), reflect.ValueOf(func(a, b net.Destination) bool {
return a == b
}))
assert.RegisterEqualsOperator(reflect.TypeOf(net.Port(0)), reflect.ValueOf(func(a, b net.Port) bool {
assert.RegisterEqualsMatcher(reflect.TypeOf(net.Port(0)), reflect.ValueOf(func(a, b net.Port) bool {
return a == b
}))
}