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
dms3
go-path
Commits
eb2707ce
Commit
eb2707ce
authored
Apr 24, 2018
by
Łukasz Magiera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
path: add tests for ipld paths
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
parent
16bf087f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
2 deletions
+9
-2
path.go
path.go
+3
-2
path_test.go
path_test.go
+6
-0
No files found.
path.go
View file @
eb2707ce
...
...
@@ -59,10 +59,11 @@ func (p Path) String() string {
return
string
(
p
)
}
// IsJustAKey returns true if the path is of the form <key> or /ipfs/<key>.
// IsJustAKey returns true if the path is of the form <key> or /ipfs/<key>, or
// /ipld/<key>
func
(
p
Path
)
IsJustAKey
()
bool
{
parts
:=
p
.
Segments
()
return
len
(
parts
)
==
2
&&
parts
[
0
]
==
"ipfs"
return
len
(
parts
)
==
2
&&
(
parts
[
0
]
==
"ipfs"
||
parts
[
0
]
==
"ipld"
)
}
// PopLastSegment returns a new Path without its final segment, and the final
...
...
path_test.go
View file @
eb2707ce
...
...
@@ -9,6 +9,9 @@ func TestPathParsing(t *testing.T) {
"/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n"
:
true
,
"/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a"
:
true
,
"/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a/b/c/d/e/f"
:
true
,
"/ipld/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n"
:
true
,
"/ipld/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a"
:
true
,
"/ipld/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a/b/c/d/e/f"
:
true
,
"/ipns/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a/b/c/d/e/f"
:
true
,
"/ipns/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n"
:
true
,
"QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a/b/c/d/e/f"
:
true
,
...
...
@@ -36,6 +39,8 @@ func TestIsJustAKey(t *testing.T) {
"/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a"
:
false
,
"/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a/b"
:
false
,
"/ipns/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n"
:
false
,
"/ipld/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a/b"
:
false
,
"/ipld/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n"
:
true
,
}
for
p
,
expected
:=
range
cases
{
...
...
@@ -57,6 +62,7 @@ func TestPopLastSegment(t *testing.T) {
"/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a"
:
[]
string
{
"/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n"
,
"a"
},
"/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a/b"
:
[]
string
{
"/ipfs/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/a"
,
"b"
},
"/ipns/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/x/y/z"
:
[]
string
{
"/ipns/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/x/y"
,
"z"
},
"/ipld/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/x/y/z"
:
[]
string
{
"/ipld/QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n/x/y"
,
"z"
},
}
for
p
,
expected
:=
range
cases
{
...
...
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