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
ld
go-ld-prime
Commits
e798ae8c
Commit
e798ae8c
authored
Jun 17, 2021
by
Daniel Martí
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
node/basic: add Chooser
Fixes #185.
parent
ccb9eea4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
24 deletions
+26
-24
node/basic/any.go
node/basic/any.go
+14
-0
traversal/focus_test.go
traversal/focus_test.go
+6
-12
traversal/walk_test.go
traversal/walk_test.go
+6
-12
No files found.
node/basic/any.go
View file @
e798ae8c
...
...
@@ -11,6 +11,20 @@ var (
//_ ipld.NodeAssembler = &anyAssembler{}
)
// Note that we don't use a "var _" declaration to assert that Chooser
// implements traversal.LinkTargetNodePrototypeChooser, to keep basicnode's
// dependencies fairly light.
// Chooser implements traversal.LinkTargetNodePrototypeChooser.
//
// It can be used directly when loading links into the "any" prototype,
// or with another chooser layer on top, such as:
//
// prototypeChooser := dagpb.AddSupportToChooser(basicnode.Chooser)
func
Chooser
(
_
ipld
.
Link
,
_
ipld
.
LinkContext
)
(
ipld
.
NodePrototype
,
error
)
{
return
Prototype__Any
{},
nil
}
// anyNode is a union meant for alloc amortization; see anyAssembler.
// Note that anyBuilder doesn't use anyNode, because it's not aiming to amortize anything.
//
...
...
traversal/focus_test.go
View file @
e798ae8c
...
...
@@ -136,10 +136,8 @@ func TestFocusWithLinkLoading(t *testing.T) {
lsys
.
StorageReadOpener
=
(
&
store
)
.
OpenRead
err
:=
traversal
.
Progress
{
Cfg
:
&
traversal
.
Config
{
LinkSystem
:
lsys
,
LinkTargetNodePrototypeChooser
:
func
(
_
ipld
.
Link
,
_
ipld
.
LinkContext
)
(
ipld
.
NodePrototype
,
error
)
{
return
basicnode
.
Prototype__Any
{},
nil
},
LinkSystem
:
lsys
,
LinkTargetNodePrototypeChooser
:
basicnode
.
Chooser
,
},
}
.
Focus
(
rootNode
,
ipld
.
ParsePath
(
"linkedMap/nested/nonlink"
),
func
(
prog
traversal
.
Progress
,
n
ipld
.
Node
)
error
{
Wish
(
t
,
n
,
ShouldEqual
,
basicnode
.
NewString
(
"zoo"
))
...
...
@@ -168,10 +166,8 @@ func TestGetWithLinkLoading(t *testing.T) {
lsys
.
StorageReadOpener
=
(
&
store
)
.
OpenRead
n
,
err
:=
traversal
.
Progress
{
Cfg
:
&
traversal
.
Config
{
LinkSystem
:
lsys
,
LinkTargetNodePrototypeChooser
:
func
(
_
ipld
.
Link
,
_
ipld
.
LinkContext
)
(
ipld
.
NodePrototype
,
error
)
{
return
basicnode
.
Prototype__Any
{},
nil
},
LinkSystem
:
lsys
,
LinkTargetNodePrototypeChooser
:
basicnode
.
Chooser
,
},
}
.
Get
(
rootNode
,
ipld
.
ParsePath
(
"linkedMap/nested/nonlink"
))
Wish
(
t
,
err
,
ShouldEqual
,
nil
)
...
...
@@ -312,10 +308,8 @@ func TestFocusedTransformWithLinks(t *testing.T) {
lsys
.
StorageReadOpener
=
(
&
store
)
.
OpenRead
lsys
.
StorageWriteOpener
=
(
&
store2
)
.
OpenWrite
cfg
:=
traversal
.
Config
{
LinkSystem
:
lsys
,
LinkTargetNodePrototypeChooser
:
func
(
_
ipld
.
Link
,
_
ipld
.
LinkContext
)
(
ipld
.
NodePrototype
,
error
)
{
return
basicnode
.
Prototype
.
Any
,
nil
},
LinkSystem
:
lsys
,
LinkTargetNodePrototypeChooser
:
basicnode
.
Chooser
,
}
t
.
Run
(
"UpdateMapBeyondLink"
,
func
(
t
*
testing
.
T
)
{
n
,
err
:=
traversal
.
Progress
{
...
...
traversal/walk_test.go
View file @
e798ae8c
...
...
@@ -122,10 +122,8 @@ func TestWalkMatching(t *testing.T) {
lsys
.
StorageReadOpener
=
(
&
store
)
.
OpenRead
err
=
traversal
.
Progress
{
Cfg
:
&
traversal
.
Config
{
LinkSystem
:
lsys
,
LinkTargetNodePrototypeChooser
:
func
(
_
ipld
.
Link
,
_
ipld
.
LinkContext
)
(
ipld
.
NodePrototype
,
error
)
{
return
basicnode
.
Prototype__Any
{},
nil
},
LinkSystem
:
lsys
,
LinkTargetNodePrototypeChooser
:
basicnode
.
Chooser
,
},
}
.
WalkMatching
(
middleMapNode
,
s
,
func
(
prog
traversal
.
Progress
,
n
ipld
.
Node
)
error
{
switch
order
{
...
...
@@ -168,10 +166,8 @@ func TestWalkMatching(t *testing.T) {
lsys
.
StorageReadOpener
=
(
&
store
)
.
OpenRead
err
=
traversal
.
Progress
{
Cfg
:
&
traversal
.
Config
{
LinkSystem
:
lsys
,
LinkTargetNodePrototypeChooser
:
func
(
_
ipld
.
Link
,
_
ipld
.
LinkContext
)
(
ipld
.
NodePrototype
,
error
)
{
return
basicnode
.
Prototype__Any
{},
nil
},
LinkSystem
:
lsys
,
LinkTargetNodePrototypeChooser
:
basicnode
.
Chooser
,
},
}
.
WalkMatching
(
middleListNode
,
s
,
func
(
prog
traversal
.
Progress
,
n
ipld
.
Node
)
error
{
switch
order
{
...
...
@@ -213,10 +209,8 @@ func TestWalkMatching(t *testing.T) {
lsys
.
StorageReadOpener
=
(
&
store
)
.
OpenRead
err
=
traversal
.
Progress
{
Cfg
:
&
traversal
.
Config
{
LinkSystem
:
lsys
,
LinkTargetNodePrototypeChooser
:
func
(
_
ipld
.
Link
,
_
ipld
.
LinkContext
)
(
ipld
.
NodePrototype
,
error
)
{
return
basicnode
.
Prototype__Any
{},
nil
},
LinkSystem
:
lsys
,
LinkTargetNodePrototypeChooser
:
basicnode
.
Chooser
,
},
}
.
WalkMatching
(
rootNode
,
s
,
func
(
prog
traversal
.
Progress
,
n
ipld
.
Node
)
error
{
switch
order
{
...
...
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