Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix comment on Decapsulate #181

Merged
merged 2 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ type Multiaddr interface {
//
Encapsulate(Multiaddr) Multiaddr

// Decapsultate removes a Multiaddr wrapping. For example:
// Decapsulate removes a Multiaddr wrapping. For example:
//
// /ip4/1.2.3.4/tcp/80 decapsulate /ip4/1.2.3.4 = /tcp/80
// /ip4/1.2.3.4/tcp/80 decapsulate /tcp/80 = /ip4/1.2.3.4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also document what happens if you try to decapsulate something that's not there at the right hand side of the multiaddr (it returns nil).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should! But the behavior is /ip4/1.2.3.4/tcp/80 decapsulate /udp/80 = /ip4/1.2.3.4/tcp/80

//
Decapsulate(Multiaddr) Multiaddr

Expand Down
9 changes: 9 additions & 0 deletions multiaddr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,15 @@ func TestEncapsulate(t *testing.T) {
}
}

func TestDecapsulateComment(t *testing.T) {
// shows the behavior from the interface comment
m := StringCast("/ip4/1.2.3.4/tcp/80")
rest := m.Decapsulate(StringCast("/tcp/80"))
if rest.String() != "/ip4/1.2.3.4" {
t.Fatalf("Documented behavior is not correct. Expected %v saw %v", "/ip4/1.2.3.4/", rest.String())
}
}

func assertValueForProto(t *testing.T, a Multiaddr, p int, exp string) {
t.Logf("checking for %s in %s", ProtocolWithCode(p).Name, a)
fv, err := a.ValueForProtocol(p)
Expand Down