Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
mf
go-multiaddr
Commits
74443fca
Commit
74443fca
authored
Sep 16, 2014
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Equal func
parent
0624ab3b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
0 deletions
+40
-0
index.go
index.go
+6
-0
multiaddr_test.go
multiaddr_test.go
+34
-0
No files found.
index.go
View file @
74443fca
package
multiaddr
import
(
"bytes"
"fmt"
"strings"
)
...
...
@@ -19,6 +20,11 @@ func NewMultiaddr(s string) (*Multiaddr, error) {
return
&
Multiaddr
{
Bytes
:
b
},
nil
}
// Equal tests whether two multiaddrs are equal
func
(
m
*
Multiaddr
)
Equal
(
m2
*
Multiaddr
)
bool
{
return
bytes
.
Equal
(
m
.
Bytes
,
m2
.
Bytes
)
}
// String returns the string representation of a Multiaddr
func
(
m
*
Multiaddr
)
String
()
(
string
,
error
)
{
return
bytesToString
(
m
.
Bytes
)
...
...
multiaddr_test.go
View file @
74443fca
...
...
@@ -6,6 +6,40 @@ import (
"testing"
)
func
newMultiaddr
(
t
*
testing
.
T
,
a
string
)
*
Multiaddr
{
m
,
err
:=
NewMultiaddr
(
a
)
if
err
!=
nil
{
t
.
Error
(
err
)
}
return
m
}
func
TestEqual
(
t
*
testing
.
T
)
{
m1
:=
newMultiaddr
(
t
,
"/ip4/127.0.0.1/udp/1234"
)
m2
:=
newMultiaddr
(
t
,
"/ip4/127.0.0.1/tcp/1234"
)
m3
:=
newMultiaddr
(
t
,
"/ip4/127.0.0.1/tcp/1234"
)
if
m1
.
Equal
(
m2
)
{
t
.
Error
(
"should not be equal"
)
}
if
m2
.
Equal
(
m1
)
{
t
.
Error
(
"should not be equal"
)
}
if
!
m2
.
Equal
(
m3
)
{
t
.
Error
(
"should be equal"
)
}
if
!
m3
.
Equal
(
m2
)
{
t
.
Error
(
"should be equal"
)
}
if
!
m1
.
Equal
(
m1
)
{
t
.
Error
(
"should be equal"
)
}
}
func
TestStringToBytes
(
t
*
testing
.
T
)
{
testString
:=
func
(
s
string
,
h
string
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment