1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-27 06:16:09 -04:00

remove unnecessary equals()

This commit is contained in:
Darien Raymond 2016-11-27 09:19:52 +01:00
parent b1f78a1ffc
commit 77e1427845
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
5 changed files with 2 additions and 129 deletions

View File

@ -49,7 +49,6 @@ type Address interface {
Family() AddressFamily
String() string // String representation of this Address
Equals(Address) bool
}
// ParseAddress parses a string into an Address. The return value will be an IPAddress when
@ -109,17 +108,6 @@ func (this ipv4Address) String() string {
return this.IP().String()
}
func (this ipv4Address) Equals(another Address) bool {
anotherIPv4, ok := another.(ipv4Address)
if !ok {
return false
}
return this[0] == anotherIPv4[0] &&
this[1] == anotherIPv4[1] &&
this[2] == anotherIPv4[2] &&
this[3] == anotherIPv4[3]
}
type ipv6Address [16]byte
func (addr ipv6Address) IP() net.IP {
@ -138,29 +126,6 @@ func (this ipv6Address) String() string {
return "[" + this.IP().String() + "]"
}
func (this ipv6Address) Equals(another Address) bool {
anotherIPv6, ok := another.(ipv6Address)
if !ok {
return false
}
return this[0] == anotherIPv6[0] &&
this[1] == anotherIPv6[1] &&
this[2] == anotherIPv6[2] &&
this[3] == anotherIPv6[3] &&
this[4] == anotherIPv6[4] &&
this[5] == anotherIPv6[5] &&
this[6] == anotherIPv6[6] &&
this[7] == anotherIPv6[7] &&
this[8] == anotherIPv6[8] &&
this[9] == anotherIPv6[9] &&
this[10] == anotherIPv6[10] &&
this[11] == anotherIPv6[11] &&
this[12] == anotherIPv6[12] &&
this[13] == anotherIPv6[13] &&
this[14] == anotherIPv6[14] &&
this[15] == anotherIPv6[15]
}
type domainAddress string
func (addr domainAddress) IP() net.IP {
@ -179,14 +144,6 @@ func (this domainAddress) String() string {
return this.Domain()
}
func (this domainAddress) Equals(another Address) bool {
anotherDomain, ok := another.(domainAddress)
if !ok {
return false
}
return this.Domain() == anotherDomain.Domain()
}
func (this *IPOrDomain) AsAddress() Address {
if this == nil {
return nil

View File

@ -72,51 +72,3 @@ func TestNetIPv4Address(t *testing.T) {
assert.Address(addr).IsIPv4()
assert.Address(addr).EqualsString("1.2.3.4")
}
func TestIPv4AddressEquals(t *testing.T) {
assert := assert.On(t)
addr := v2net.IPAddress([]byte{1, 2, 3, 4})
assert.Address(addr).NotEquals(nil)
addr2 := v2net.IPAddress([]byte{1, 2, 3, 4})
assert.Address(addr).Equals(addr2)
addr3 := v2net.IPAddress([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6})
assert.Address(addr).NotEquals(addr3)
addr4 := v2net.IPAddress([]byte{1, 2, 3, 5})
assert.Address(addr).NotEquals(addr4)
}
func TestIPv6AddressEquals(t *testing.T) {
assert := assert.On(t)
addr := v2net.IPAddress([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6})
assert.Bool(addr.Equals(nil)).IsFalse()
addr2 := v2net.IPAddress([]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6})
assert.Bool(addr.Equals(addr2)).IsTrue()
addr3 := v2net.IPAddress([]byte{1, 2, 3, 4})
assert.Bool(addr.Equals(addr3)).IsFalse()
addr4 := v2net.IPAddress([]byte{1, 3, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6})
assert.Bool(addr.Equals(addr4)).IsFalse()
}
func TestDomainAddressEquals(t *testing.T) {
assert := assert.On(t)
addr := v2net.DomainAddress("v2ray.com")
assert.Bool(addr.Equals(nil)).IsFalse()
addr2 := v2net.DomainAddress("v2ray.com")
assert.Bool(addr.Equals(addr2)).IsTrue()
addr3 := v2net.DomainAddress("www.v2ray.com")
assert.Bool(addr.Equals(addr3)).IsFalse()
addr4 := v2net.IPAddress([]byte{1, 3, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6})
assert.Bool(addr.Equals(addr4)).IsFalse()
}

View File

@ -48,10 +48,6 @@ func (this Destination) String() string {
return this.Network.UrlPrefix() + ":" + this.NetAddr()
}
func (this Destination) Equals(another Destination) bool {
return this.Network == another.Network && this.Port == another.Port && this.Address.Equals(another.Address)
}
func (this *Endpoint) AsDestination() Destination {
return Destination{
Network: this.Network,

View File

@ -24,35 +24,3 @@ func TestUDPDestination(t *testing.T) {
assert.Destination(dest).IsUDP()
assert.Destination(dest).EqualsString("udp:[2001:4860:4860::8888]:53")
}
func TestTCPDestinationEquals(t *testing.T) {
assert := assert.On(t)
dest := v2net.TCPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
assert.Bool(dest.Equals(v2net.Destination{})).IsFalse()
dest2 := v2net.TCPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
assert.Bool(dest.Equals(dest2)).IsTrue()
dest3 := v2net.UDPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
assert.Bool(dest.Equals(dest3)).IsFalse()
dest4 := v2net.TCPDestination(v2net.DomainAddress("v2ray.com"), 80)
assert.Bool(dest.Equals(dest4)).IsFalse()
}
func TestUDPDestinationEquals(t *testing.T) {
assert := assert.On(t)
dest := v2net.UDPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
assert.Bool(dest.Equals(v2net.Destination{})).IsFalse()
dest2 := v2net.UDPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
assert.Bool(dest.Equals(dest2)).IsTrue()
dest3 := v2net.TCPDestination(v2net.IPAddress([]byte{1, 2, 3, 4}), 80)
assert.Bool(dest.Equals(dest3)).IsFalse()
dest4 := v2net.UDPDestination(v2net.DomainAddress("v2ray.com"), 80)
assert.Bool(dest.Equals(dest4)).IsFalse()
}

View File

@ -20,13 +20,13 @@ type AddressSubject struct {
}
func (subject *AddressSubject) NotEquals(another v2net.Address) {
if subject.value.Equals(another) {
if subject.value == another {
subject.Fail("not equals to", another.String())
}
}
func (subject *AddressSubject) Equals(another v2net.Address) {
if !subject.value.Equals(another) {
if subject.value != another {
subject.Fail("equals to", another.String())
}
}