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
1dac0811
Commit
1dac0811
authored
Aug 06, 2019
by
hannahhoward
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(builder): extract to package
Extract the selector buidler to a seperate package
parent
e4e37206
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
247 additions
and
131 deletions
+247
-131
traversal/selector/builder/builder.go
traversal/selector/builder/builder.go
+22
-22
traversal/selector/builder/builder_test.go
traversal/selector/builder/builder_test.go
+114
-0
traversal/selector/exploreAll.go
traversal/selector/exploreAll.go
+1
-1
traversal/selector/exploreAll_test.go
traversal/selector/exploreAll_test.go
+3
-3
traversal/selector/exploreFields.go
traversal/selector/exploreFields.go
+1
-1
traversal/selector/exploreFields_test.go
traversal/selector/exploreFields_test.go
+4
-4
traversal/selector/exploreIndex.go
traversal/selector/exploreIndex.go
+2
-2
traversal/selector/exploreIndex_test.go
traversal/selector/exploreIndex_test.go
+11
-11
traversal/selector/exploreRange.go
traversal/selector/exploreRange.go
+3
-3
traversal/selector/exploreRange_test.go
traversal/selector/exploreRange_test.go
+27
-27
traversal/selector/exploreRecursive.go
traversal/selector/exploreRecursive.go
+2
-2
traversal/selector/exploreRecursive_test.go
traversal/selector/exploreRecursive_test.go
+18
-18
traversal/selector/exploreUnion_test.go
traversal/selector/exploreUnion_test.go
+6
-6
traversal/selector/fieldKeys.go
traversal/selector/fieldKeys.go
+19
-19
traversal/selector/selector.go
traversal/selector/selector.go
+8
-8
traversal/traverse_test.go
traversal/traverse_test.go
+6
-4
No files found.
traversal/selector/
selectorSpecB
uilder.go
→
traversal/selector/
builder/b
uilder.go
View file @
1dac0811
package
selecto
r
package
builde
r
import
(
ipld
"github.com/ipld/go-ipld-prime"
"github.com/ipld/go-ipld-prime/fluent"
selector
"github.com/ipld/go-ipld-prime/traversal/selector"
)
// SelectorSpec is a specification for a selector that can build
// a selector ipld.Node or an actual parsed Selector
type
SelectorSpec
interface
{
Node
()
ipld
.
Node
Selector
()
(
Selector
,
error
)
Selector
()
(
selector
.
Selector
,
error
)
}
// SelectorSpecBuilder is a utility interface to build selector ipld nodes
...
...
@@ -56,8 +57,8 @@ func (ss selectorSpec) Node() ipld.Node {
return
ss
.
n
}
func
(
ss
selectorSpec
)
Selector
()
(
Selector
,
error
)
{
return
ParseSelector
(
ss
.
n
)
func
(
ss
selectorSpec
)
Selector
()
(
selector
.
Selector
,
error
)
{
return
selector
.
ParseSelector
(
ss
.
n
)
}
// NewSelectorSpecBuilder creates a SelectorSpecBuilder from an underlying ipld NodeBuilder
...
...
@@ -69,7 +70,7 @@ func NewSelectorSpecBuilder(nb ipld.NodeBuilder) SelectorSpecBuilder {
func
(
ssb
*
selectorSpecBuilder
)
ExploreRecursiveEdge
()
SelectorSpec
{
return
selectorSpec
{
ssb
.
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
e
xploreRecursiveEdge
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_E
xploreRecursiveEdge
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
}),
}
}
...
...
@@ -77,9 +78,9 @@ func (ssb *selectorSpecBuilder) ExploreRecursiveEdge() SelectorSpec {
func
(
ssb
*
selectorSpecBuilder
)
ExploreRecursive
(
maxDepth
int
,
sequence
SelectorSpec
)
SelectorSpec
{
return
selectorSpec
{
ssb
.
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
e
xploreRecursive
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
m
axDepth
Key
),
vnb
.
CreateInt
(
maxDepth
))
mb
.
Insert
(
knb
.
CreateString
(
sequence
Key
),
sequence
.
Node
())
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_E
xploreRecursive
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_M
axDepth
),
vnb
.
CreateInt
(
maxDepth
))
mb
.
Insert
(
knb
.
CreateString
(
se
lector
.
SelectorKey_Se
quence
),
sequence
.
Node
())
}))
}),
}
...
...
@@ -88,8 +89,8 @@ func (ssb *selectorSpecBuilder) ExploreRecursive(maxDepth int, sequence Selector
func
(
ssb
*
selectorSpecBuilder
)
ExploreAll
(
next
SelectorSpec
)
SelectorSpec
{
return
selectorSpec
{
ssb
.
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
e
xploreAll
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
next
SelectorKey
),
next
.
Node
())
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_E
xploreAll
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey
_Next
),
next
.
Node
())
}))
}),
}
...
...
@@ -97,9 +98,9 @@ func (ssb *selectorSpecBuilder) ExploreAll(next SelectorSpec) SelectorSpec {
func
(
ssb
*
selectorSpecBuilder
)
ExploreIndex
(
index
int
,
next
SelectorSpec
)
SelectorSpec
{
return
selectorSpec
{
ssb
.
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
e
xploreIndex
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
indexKey
),
vnb
.
CreateInt
(
index
))
mb
.
Insert
(
knb
.
CreateString
(
next
SelectorKey
),
next
.
Node
())
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_E
xploreIndex
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_Index
),
vnb
.
CreateInt
(
index
))
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey
_Next
),
next
.
Node
())
}))
}),
}
...
...
@@ -108,10 +109,10 @@ func (ssb *selectorSpecBuilder) ExploreIndex(index int, next SelectorSpec) Selec
func
(
ssb
*
selectorSpecBuilder
)
ExploreRange
(
start
int
,
end
int
,
next
SelectorSpec
)
SelectorSpec
{
return
selectorSpec
{
ssb
.
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
e
xploreRange
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
start
Key
),
vnb
.
CreateInt
(
start
))
mb
.
Insert
(
knb
.
CreateString
(
endKey
),
vnb
.
CreateInt
(
end
))
mb
.
Insert
(
knb
.
CreateString
(
next
SelectorKey
),
next
.
Node
())
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_E
xploreRange
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
s
elector
.
SelectorKey_S
tart
),
vnb
.
CreateInt
(
start
))
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_End
),
vnb
.
CreateInt
(
end
))
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey
_Next
),
next
.
Node
())
}))
}),
}
...
...
@@ -120,11 +121,10 @@ func (ssb *selectorSpecBuilder) ExploreRange(start int, end int, next SelectorSp
func
(
ssb
*
selectorSpecBuilder
)
ExploreUnion
(
members
...
SelectorSpec
)
SelectorSpec
{
return
selectorSpec
{
ssb
.
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
e
xploreUnion
Key
),
vnb
.
CreateList
(
func
(
lb
fluent
.
ListBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_E
xploreUnion
),
vnb
.
CreateList
(
func
(
lb
fluent
.
ListBuilder
,
vnb
fluent
.
NodeBuilder
)
{
for
_
,
member
:=
range
members
{
lb
.
Append
(
member
.
Node
())
}
}))
}),
}
...
...
@@ -133,8 +133,8 @@ func (ssb *selectorSpecBuilder) ExploreUnion(members ...SelectorSpec) SelectorSp
func
(
ssb
*
selectorSpecBuilder
)
ExploreFields
(
specBuilder
ExploreFieldsSpecBuildingClosure
)
SelectorSpec
{
return
selectorSpec
{
ssb
.
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
e
xploreFields
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
fieldsKey
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_E
xploreFields
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_Fields
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
specBuilder
(
exploreFieldsSpecBuilder
{
mb
,
knb
})
}))
}))
...
...
@@ -145,7 +145,7 @@ func (ssb *selectorSpecBuilder) ExploreFields(specBuilder ExploreFieldsSpecBuild
func
(
ssb
*
selectorSpecBuilder
)
Matcher
()
SelectorSpec
{
return
selectorSpec
{
ssb
.
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
matcherKey
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_Matcher
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
}),
}
}
...
...
traversal/selector/
selectorSpecB
uilder_test.go
→
traversal/selector/
builder/b
uilder_test.go
View file @
1dac0811
package
selecto
r
package
builde
r
import
(
"testing"
"github.com/ipld/go-ipld-prime/fluent"
ipldfree
"github.com/ipld/go-ipld-prime/impl/free"
"github.com/ipld/go-ipld-prime/traversal/selector"
.
"github.com/warpfork/go-wish"
)
...
...
@@ -15,23 +16,23 @@ func TestBuildingSelectors(t *testing.T) {
t
.
Run
(
"Matcher builds matcher nodes"
,
func
(
t
*
testing
.
T
)
{
sn
:=
ssb
.
Matcher
()
.
Node
()
esn
:=
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
matcherKey
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_Matcher
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
})
Wish
(
t
,
sn
,
ShouldEqual
,
esn
)
})
t
.
Run
(
"ExploreRecursiveEdge builds ExploreRecursiveEdge nodes"
,
func
(
t
*
testing
.
T
)
{
sn
:=
ssb
.
ExploreRecursiveEdge
()
.
Node
()
esn
:=
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
e
xploreRecursiveEdge
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_E
xploreRecursiveEdge
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
})
Wish
(
t
,
sn
,
ShouldEqual
,
esn
)
})
t
.
Run
(
"ExploreAll builds ExploreAll nodes"
,
func
(
t
*
testing
.
T
)
{
sn
:=
ssb
.
ExploreAll
(
ssb
.
Matcher
())
.
Node
()
esn
:=
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
e
xploreAll
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
next
SelectorKey
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
matcherKey
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_E
xploreAll
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey
_Next
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_Matcher
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
}))
}))
})
...
...
@@ -40,10 +41,10 @@ func TestBuildingSelectors(t *testing.T) {
t
.
Run
(
"ExploreIndex builds ExploreIndex nodes"
,
func
(
t
*
testing
.
T
)
{
sn
:=
ssb
.
ExploreIndex
(
2
,
ssb
.
Matcher
())
.
Node
()
esn
:=
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
e
xploreIndex
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
indexKey
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
next
SelectorKey
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
matcherKey
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_E
xploreIndex
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_Index
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey
_Next
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_Matcher
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
}))
}))
})
...
...
@@ -52,11 +53,11 @@ func TestBuildingSelectors(t *testing.T) {
t
.
Run
(
"ExploreRange builds ExploreRange nodes"
,
func
(
t
*
testing
.
T
)
{
sn
:=
ssb
.
ExploreRange
(
2
,
3
,
ssb
.
Matcher
())
.
Node
()
esn
:=
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
e
xploreRange
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
start
Key
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
endKey
),
vnb
.
CreateInt
(
3
))
mb
.
Insert
(
knb
.
CreateString
(
next
SelectorKey
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
matcherKey
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_E
xploreRange
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
s
elector
.
SelectorKey_S
tart
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_End
),
vnb
.
CreateInt
(
3
))
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey
_Next
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_Matcher
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
}))
}))
})
...
...
@@ -65,12 +66,12 @@ func TestBuildingSelectors(t *testing.T) {
t
.
Run
(
"ExploreRecursive builds ExploreRecursive nodes"
,
func
(
t
*
testing
.
T
)
{
sn
:=
ssb
.
ExploreRecursive
(
2
,
ssb
.
ExploreAll
(
ssb
.
ExploreRecursiveEdge
()))
.
Node
()
esn
:=
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
e
xploreRecursive
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
m
axDepth
Key
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
sequence
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
e
xploreAll
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
next
SelectorKey
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
e
xploreRecursiveEdge
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_E
xploreRecursive
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_M
axDepth
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
se
lector
.
SelectorKey_Se
quence
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_E
xploreAll
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey
_Next
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_E
xploreRecursiveEdge
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
}))
}))
}))
...
...
@@ -81,15 +82,15 @@ func TestBuildingSelectors(t *testing.T) {
t
.
Run
(
"ExploreUnion builds ExploreUnion nodes"
,
func
(
t
*
testing
.
T
)
{
sn
:=
ssb
.
ExploreUnion
(
ssb
.
Matcher
(),
ssb
.
ExploreIndex
(
2
,
ssb
.
Matcher
()))
.
Node
()
esn
:=
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
e
xploreUnion
Key
),
vnb
.
CreateList
(
func
(
lb
fluent
.
ListBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_E
xploreUnion
),
vnb
.
CreateList
(
func
(
lb
fluent
.
ListBuilder
,
vnb
fluent
.
NodeBuilder
)
{
lb
.
Append
(
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
matcherKey
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_Matcher
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
}))
lb
.
Append
(
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
e
xploreIndex
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
indexKey
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
next
SelectorKey
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
matcherKey
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_E
xploreIndex
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_Index
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey
_Next
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_Matcher
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
}))
}))
}))
...
...
@@ -100,10 +101,10 @@ func TestBuildingSelectors(t *testing.T) {
t
.
Run
(
"ExploreFields builds ExploreFields nodes"
,
func
(
t
*
testing
.
T
)
{
sn
:=
ssb
.
ExploreFields
(
func
(
efsb
ExploreFieldsSpecBuilder
)
{
efsb
.
Insert
(
"applesauce"
,
ssb
.
Matcher
())
})
.
Node
()
esn
:=
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
e
xploreFields
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
fieldsKey
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_E
xploreFields
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_Fields
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
"applesauce"
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
matcherKey
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
mb
.
Insert
(
knb
.
CreateString
(
selector
.
SelectorKey_Matcher
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
}))
}))
}))
...
...
traversal/selector/exploreAll.go
View file @
1dac0811
...
...
@@ -32,7 +32,7 @@ func (pc ParseContext) ParseExploreAll(n ipld.Node) (Selector, error) {
if
n
.
ReprKind
()
!=
ipld
.
ReprKind_Map
{
return
nil
,
fmt
.
Errorf
(
"selector spec parse rejected: selector body must be a map"
)
}
next
,
err
:=
n
.
TraverseField
(
next
SelectorKey
)
next
,
err
:=
n
.
TraverseField
(
SelectorKey
_Next
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"selector spec parse rejected: next field must be present in ExploreAll selector"
)
}
...
...
traversal/selector/exploreAll_test.go
View file @
1dac0811
...
...
@@ -24,15 +24,15 @@ func TestParseExploreAll(t *testing.T) {
t
.
Run
(
"parsing map node without next field with invalid selector node should return child's error"
,
func
(
t
*
testing
.
T
)
{
sn
:=
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
next
SelectorKey
),
vnb
.
CreateInt
(
0
))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey
_Next
),
vnb
.
CreateInt
(
0
))
})
_
,
err
:=
ParseContext
{}
.
ParseExploreAll
(
sn
)
Wish
(
t
,
err
,
ShouldEqual
,
fmt
.
Errorf
(
"selector spec parse rejected: selector is a keyed union and thus must be a map"
))
})
t
.
Run
(
"parsing map node with next field with valid selector node should parse"
,
func
(
t
*
testing
.
T
)
{
sn
:=
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
next
SelectorKey
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
m
atcher
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey
_Next
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_M
atcher
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
}))
})
s
,
err
:=
ParseContext
{}
.
ParseExploreAll
(
sn
)
...
...
traversal/selector/exploreFields.go
View file @
1dac0811
...
...
@@ -44,7 +44,7 @@ func (pc ParseContext) ParseExploreFields(n ipld.Node) (Selector, error) {
if
n
.
ReprKind
()
!=
ipld
.
ReprKind_Map
{
return
nil
,
fmt
.
Errorf
(
"selector spec parse rejected: selector body must be a map"
)
}
fields
,
err
:=
n
.
TraverseField
(
f
ields
Key
)
fields
,
err
:=
n
.
TraverseField
(
SelectorKey_F
ields
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"selector spec parse rejected: fields in ExploreFields selector must be present"
)
}
...
...
traversal/selector/exploreFields_test.go
View file @
1dac0811
...
...
@@ -23,14 +23,14 @@ func TestParseExploreFields(t *testing.T) {
})
t
.
Run
(
"parsing map node with fields value that is not a map should error"
,
func
(
t
*
testing
.
T
)
{
sn
:=
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
f
ields
Key
),
vnb
.
CreateString
(
"cheese"
))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_F
ields
),
vnb
.
CreateString
(
"cheese"
))
})
_
,
err
:=
ParseContext
{}
.
ParseExploreFields
(
sn
)
Wish
(
t
,
err
,
ShouldEqual
,
fmt
.
Errorf
(
"selector spec parse rejected: fields in ExploreFields selector must be a map"
))
})
t
.
Run
(
"parsing map node with selector node in fields that is invalid should return child's error"
,
func
(
t
*
testing
.
T
)
{
sn
:=
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
f
ields
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_F
ields
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
"applesauce"
),
vnb
.
CreateInt
(
0
))
}))
})
...
...
@@ -39,9 +39,9 @@ func TestParseExploreFields(t *testing.T) {
})
t
.
Run
(
"parsing map node with fields value that is map of only valid selector node should parse"
,
func
(
t
*
testing
.
T
)
{
sn
:=
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
f
ields
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_F
ields
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
"applesauce"
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
m
atcher
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_M
atcher
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
}))
}))
})
...
...
traversal/selector/exploreIndex.go
View file @
1dac0811
...
...
@@ -43,7 +43,7 @@ func (pc ParseContext) ParseExploreIndex(n ipld.Node) (Selector, error) {
if
n
.
ReprKind
()
!=
ipld
.
ReprKind_Map
{
return
nil
,
fmt
.
Errorf
(
"selector spec parse rejected: selector body must be a map"
)
}
indexNode
,
err
:=
n
.
TraverseField
(
i
ndex
Key
)
indexNode
,
err
:=
n
.
TraverseField
(
SelectorKey_I
ndex
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"selector spec parse rejected: index field must be present in ExploreIndex selector"
)
}
...
...
@@ -51,7 +51,7 @@ func (pc ParseContext) ParseExploreIndex(n ipld.Node) (Selector, error) {
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"selector spec parse rejected: index field must be a number in ExploreIndex selector"
)
}
next
,
err
:=
n
.
TraverseField
(
next
SelectorKey
)
next
,
err
:=
n
.
TraverseField
(
SelectorKey
_Next
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"selector spec parse rejected: next field must be present in ExploreIndex selector"
)
}
...
...
traversal/selector/exploreIndex_test.go
View file @
1dac0811
...
...
@@ -19,15 +19,15 @@ func TestParseExploreIndex(t *testing.T) {
})
t
.
Run
(
"parsing map node without next field should error"
,
func
(
t
*
testing
.
T
)
{
sn
:=
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
i
ndex
Key
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_I
ndex
),
vnb
.
CreateInt
(
2
))
})
_
,
err
:=
ParseContext
{}
.
ParseExploreIndex
(
sn
)
Wish
(
t
,
err
,
ShouldEqual
,
fmt
.
Errorf
(
"selector spec parse rejected: next field must be present in ExploreIndex selector"
))
})
t
.
Run
(
"parsing map node without index field should error"
,
func
(
t
*
testing
.
T
)
{
sn
:=
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
next
SelectorKey
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
m
atcher
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey
_Next
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_M
atcher
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
}))
})
_
,
err
:=
ParseContext
{}
.
ParseExploreIndex
(
sn
)
...
...
@@ -35,9 +35,9 @@ func TestParseExploreIndex(t *testing.T) {
})
t
.
Run
(
"parsing map node with index field that is not an int should error"
,
func
(
t
*
testing
.
T
)
{
sn
:=
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
i
ndex
Key
),
vnb
.
CreateString
(
"cheese"
))
mb
.
Insert
(
knb
.
CreateString
(
next
SelectorKey
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
m
atcher
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_I
ndex
),
vnb
.
CreateString
(
"cheese"
))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey
_Next
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_M
atcher
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
}))
})
_
,
err
:=
ParseContext
{}
.
ParseExploreIndex
(
sn
)
...
...
@@ -45,17 +45,17 @@ func TestParseExploreIndex(t *testing.T) {
})
t
.
Run
(
"parsing map node with next field with invalid selector node should return child's error"
,
func
(
t
*
testing
.
T
)
{
sn
:=
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
i
ndex
Key
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
next
SelectorKey
),
vnb
.
CreateInt
(
0
))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_I
ndex
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey
_Next
),
vnb
.
CreateInt
(
0
))
})
_
,
err
:=
ParseContext
{}
.
ParseExploreIndex
(
sn
)
Wish
(
t
,
err
,
ShouldEqual
,
fmt
.
Errorf
(
"selector spec parse rejected: selector is a keyed union and thus must be a map"
))
})
t
.
Run
(
"parsing map node with next field with valid selector node should parse"
,
func
(
t
*
testing
.
T
)
{
sn
:=
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
i
ndex
Key
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
next
SelectorKey
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
m
atcher
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_I
ndex
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey
_Next
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_M
atcher
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
}))
})
s
,
err
:=
ParseContext
{}
.
ParseExploreIndex
(
sn
)
...
...
traversal/selector/exploreRange.go
View file @
1dac0811
...
...
@@ -47,7 +47,7 @@ func (pc ParseContext) ParseExploreRange(n ipld.Node) (Selector, error) {
if
n
.
ReprKind
()
!=
ipld
.
ReprKind_Map
{
return
nil
,
fmt
.
Errorf
(
"selector spec parse rejected: selector body must be a map"
)
}
startNode
,
err
:=
n
.
TraverseField
(
startKey
)
startNode
,
err
:=
n
.
TraverseField
(
SelectorKey_Start
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"selector spec parse rejected: start field must be present in ExploreRange selector"
)
}
...
...
@@ -55,7 +55,7 @@ func (pc ParseContext) ParseExploreRange(n ipld.Node) (Selector, error) {
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"selector spec parse rejected: start field must be a number in ExploreRange selector"
)
}
endNode
,
err
:=
n
.
TraverseField
(
endKey
)
endNode
,
err
:=
n
.
TraverseField
(
SelectorKey_End
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"selector spec parse rejected: end field must be present in ExploreRange selector"
)
}
...
...
@@ -66,7 +66,7 @@ func (pc ParseContext) ParseExploreRange(n ipld.Node) (Selector, error) {
if
startValue
>=
endValue
{
return
nil
,
fmt
.
Errorf
(
"selector spec parse rejected: end field must be greater than start field in ExploreRange selector"
)
}
next
,
err
:=
n
.
TraverseField
(
next
SelectorKey
)
next
,
err
:=
n
.
TraverseField
(
SelectorKey
_Next
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"selector spec parse rejected: next field must be present in ExploreRange selector"
)
}
...
...
traversal/selector/exploreRange_test.go
View file @
1dac0811
...
...
@@ -19,17 +19,17 @@ func TestParseExploreRange(t *testing.T) {
})
t
.
Run
(
"parsing map node without next field should error"
,
func
(
t
*
testing
.
T
)
{
sn
:=
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
startKey
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
endKey
),
vnb
.
CreateInt
(
3
))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_Start
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_End
),
vnb
.
CreateInt
(
3
))
})
_
,
err
:=
ParseContext
{}
.
ParseExploreRange
(
sn
)
Wish
(
t
,
err
,
ShouldEqual
,
fmt
.
Errorf
(
"selector spec parse rejected: next field must be present in ExploreRange selector"
))
})
t
.
Run
(
"parsing map node without start field should error"
,
func
(
t
*
testing
.
T
)
{
sn
:=
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
endKey
),
vnb
.
CreateInt
(
3
))
mb
.
Insert
(
knb
.
CreateString
(
next
SelectorKey
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
m
atcher
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_End
),
vnb
.
CreateInt
(
3
))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey
_Next
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_M
atcher
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
}))
})
_
,
err
:=
ParseContext
{}
.
ParseExploreRange
(
sn
)
...
...
@@ -37,10 +37,10 @@ func TestParseExploreRange(t *testing.T) {
})
t
.
Run
(
"parsing map node with start field that is not an int should error"
,
func
(
t
*
testing
.
T
)
{
sn
:=
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
startKey
),
vnb
.
CreateString
(
"cheese"
))
mb
.
Insert
(
knb
.
CreateString
(
endKey
),
vnb
.
CreateInt
(
3
))
mb
.
Insert
(
knb
.
CreateString
(
next
SelectorKey
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
m
atcher
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_Start
),
vnb
.
CreateString
(
"cheese"
))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_End
),
vnb
.
CreateInt
(
3
))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey
_Next
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_M
atcher
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
}))
})
_
,
err
:=
ParseContext
{}
.
ParseExploreRange
(
sn
)
...
...
@@ -48,9 +48,9 @@ func TestParseExploreRange(t *testing.T) {
})
t
.
Run
(
"parsing map node without end field should error"
,
func
(
t
*
testing
.
T
)
{
sn
:=
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
startKey
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
next
SelectorKey
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
m
atcher
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_Start
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey
_Next
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_M
atcher
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
}))
})
_
,
err
:=
ParseContext
{}
.
ParseExploreRange
(
sn
)
...
...
@@ -58,10 +58,10 @@ func TestParseExploreRange(t *testing.T) {
})
t
.
Run
(
"parsing map node with end field that is not an int should error"
,
func
(
t
*
testing
.
T
)
{
sn
:=
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
startKey
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
endKey
),
vnb
.
CreateString
(
"cheese"
))
mb
.
Insert
(
knb
.
CreateString
(
next
SelectorKey
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
m
atcher
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_Start
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_End
),
vnb
.
CreateString
(
"cheese"
))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey
_Next
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_M
atcher
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
}))
})
_
,
err
:=
ParseContext
{}
.
ParseExploreRange
(
sn
)
...
...
@@ -69,10 +69,10 @@ func TestParseExploreRange(t *testing.T) {
})
t
.
Run
(
"parsing map node where end is not greater than start should error"
,
func
(
t
*
testing
.
T
)
{
sn
:=
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
startKey
),
vnb
.
CreateInt
(
3
))
mb
.
Insert
(
knb
.
CreateString
(
endKey
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
next
SelectorKey
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
m
atcher
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_Start
),
vnb
.
CreateInt
(
3
))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_End
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey
_Next
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_M
atcher
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
}))
})
_
,
err
:=
ParseContext
{}
.
ParseExploreRange
(
sn
)
...
...
@@ -80,9 +80,9 @@ func TestParseExploreRange(t *testing.T) {
})
t
.
Run
(
"parsing map node with next field with invalid selector node should return child's error"
,
func
(
t
*
testing
.
T
)
{
sn
:=
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
startKey
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
endKey
),
vnb
.
CreateInt
(
3
))
mb
.
Insert
(
knb
.
CreateString
(
next
SelectorKey
),
vnb
.
CreateInt
(
0
))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_Start
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_End
),
vnb
.
CreateInt
(
3
))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey
_Next
),
vnb
.
CreateInt
(
0
))
})
_
,
err
:=
ParseContext
{}
.
ParseExploreRange
(
sn
)
Wish
(
t
,
err
,
ShouldEqual
,
fmt
.
Errorf
(
"selector spec parse rejected: selector is a keyed union and thus must be a map"
))
...
...
@@ -90,10 +90,10 @@ func TestParseExploreRange(t *testing.T) {
t
.
Run
(
"parsing map node with next field with valid selector node should parse"
,
func
(
t
*
testing
.
T
)
{
sn
:=
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
startKey
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
endKey
),
vnb
.
CreateInt
(
3
))
mb
.
Insert
(
knb
.
CreateString
(
next
SelectorKey
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
m
atcher
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_Start
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_End
),
vnb
.
CreateInt
(
3
))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey
_Next
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_M
atcher
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
}))
})
s
,
err
:=
ParseContext
{}
.
ParseExploreRange
(
sn
)
...
...
traversal/selector/exploreRecursive.go
View file @
1dac0811
...
...
@@ -81,7 +81,7 @@ func (pc ParseContext) ParseExploreRecursive(n ipld.Node) (Selector, error) {
return
nil
,
fmt
.
Errorf
(
"selector spec parse rejected: selector body must be a map"
)
}
maxDepthNode
,
err
:=
n
.
TraverseField
(
m
axDepth
Key
)
maxDepthNode
,
err
:=
n
.
TraverseField
(
SelectorKey_M
axDepth
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"selector spec parse rejected: maxDepth field must be present in ExploreRecursive selector"
)
}
...
...
@@ -89,7 +89,7 @@ func (pc ParseContext) ParseExploreRecursive(n ipld.Node) (Selector, error) {
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"selector spec parse rejected: maxDepth field must be a number in ExploreRecursive selector"
)
}
sequence
,
err
:=
n
.
TraverseField
(
s
equence
Key
)
sequence
,
err
:=
n
.
TraverseField
(
SelectorKey_S
equence
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"selector spec parse rejected: sequence field must be present in ExploreRecursive selector"
)
}
...
...
traversal/selector/exploreRecursive_test.go
View file @
1dac0811
...
...
@@ -20,15 +20,15 @@ func TestParseExploreRecursive(t *testing.T) {
})
t
.
Run
(
"parsing map node without sequence field should error"
,
func
(
t
*
testing
.
T
)
{
sn
:=
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
m
axDepth
Key
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_M
axDepth
),
vnb
.
CreateInt
(
2
))
})
_
,
err
:=
ParseContext
{}
.
ParseExploreRecursive
(
sn
)
Wish
(
t
,
err
,
ShouldEqual
,
fmt
.
Errorf
(
"selector spec parse rejected: sequence field must be present in ExploreRecursive selector"
))
})
t
.
Run
(
"parsing map node without maxDepth field should error"
,
func
(
t
*
testing
.
T
)
{
sn
:=
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
s
equence
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
m
atcher
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_S
equence
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_M
atcher
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
}))
})
_
,
err
:=
ParseContext
{}
.
ParseExploreRecursive
(
sn
)
...
...
@@ -36,9 +36,9 @@ func TestParseExploreRecursive(t *testing.T) {
})
t
.
Run
(
"parsing map node with maxDepth field that is not an int should error"
,
func
(
t
*
testing
.
T
)
{
sn
:=
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
m
axDepth
Key
),
vnb
.
CreateString
(
"cheese"
))
mb
.
Insert
(
knb
.
CreateString
(
s
equence
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
m
atcher
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_M
axDepth
),
vnb
.
CreateString
(
"cheese"
))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_S
equence
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_M
atcher
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
}))
})
_
,
err
:=
ParseContext
{}
.
ParseExploreRecursive
(
sn
)
...
...
@@ -46,19 +46,19 @@ func TestParseExploreRecursive(t *testing.T) {
})
t
.
Run
(
"parsing map node with sequence field with invalid selector node should return child's error"
,
func
(
t
*
testing
.
T
)
{
sn
:=
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
m
axDepth
Key
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
s
equence
Key
),
vnb
.
CreateInt
(
0
))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_M
axDepth
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_S
equence
),
vnb
.
CreateInt
(
0
))
})
_
,
err
:=
ParseContext
{}
.
ParseExploreRecursive
(
sn
)
Wish
(
t
,
err
,
ShouldEqual
,
fmt
.
Errorf
(
"selector spec parse rejected: selector is a keyed union and thus must be a map"
))
})
t
.
Run
(
"parsing map node with sequence field with valid selector w/o ExploreRecursiveEdge should not parse"
,
func
(
t
*
testing
.
T
)
{
sn
:=
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
m
axDepth
Key
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
s
equence
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
e
xploreAll
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
next
SelectorKey
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
m
atcher
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_M
axDepth
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_S
equence
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_E
xploreAll
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey
_Next
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_M
atcher
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
}))
}))
}))
...
...
@@ -73,11 +73,11 @@ func TestParseExploreRecursive(t *testing.T) {
})
t
.
Run
(
"parsing map node with sequence field with valid selector node should parse"
,
func
(
t
*
testing
.
T
)
{
sn
:=
fnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
m
axDepth
Key
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
s
equence
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
e
xploreAll
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
next
SelectorKey
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
e
xploreRecursiveEdge
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_M
axDepth
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_S
equence
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_E
xploreAll
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey
_Next
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_E
xploreRecursiveEdge
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
}))
}))
}))
...
...
traversal/selector/exploreUnion_test.go
View file @
1dac0811
...
...
@@ -20,7 +20,7 @@ func TestParseExploreUnion(t *testing.T) {
t
.
Run
(
"parsing list node where one node is invalid should return child's error"
,
func
(
t
*
testing
.
T
)
{
sn
:=
fnb
.
CreateList
(
func
(
lb
fluent
.
ListBuilder
,
vnb
fluent
.
NodeBuilder
)
{
lb
.
Append
(
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
m
atcher
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_M
atcher
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
}))
lb
.
Append
(
vnb
.
CreateInt
(
2
))
})
...
...
@@ -31,13 +31,13 @@ func TestParseExploreUnion(t *testing.T) {
t
.
Run
(
"parsing map node with next field with valid selector node should parse"
,
func
(
t
*
testing
.
T
)
{
sn
:=
fnb
.
CreateList
(
func
(
lb
fluent
.
ListBuilder
,
vnb
fluent
.
NodeBuilder
)
{
lb
.
Append
(
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
m
atcher
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_M
atcher
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
}))
lb
.
Append
(
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
e
xploreIndex
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
i
ndex
Key
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
next
SelectorKey
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
m
atcher
Key
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_E
xploreIndex
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_I
ndex
),
vnb
.
CreateInt
(
2
))
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey
_Next
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{
mb
.
Insert
(
knb
.
CreateString
(
SelectorKey_M
atcher
),
vnb
.
CreateMap
(
func
(
mb
fluent
.
MapBuilder
,
knb
fluent
.
NodeBuilder
,
vnb
fluent
.
NodeBuilder
)
{}))
}))
}))
}))
...
...
traversal/selector/fieldKeys.go
View file @
1dac0811
package
selector
const
(
matcherKey
=
"."
exploreAllKey
=
"a"
e
xploreFields
Key
=
"f"
e
xploreIndex
Key
=
"i"
e
xploreRange
Key
=
"r"
e
xploreRecursive
Key
=
"R"
e
xploreUnion
Key
=
"|"
e
xploreConditional
Key
=
"&"
e
xploreRecursiveEdge
Key
=
"@"
next
SelectorKey
=
">"
fieldsKey
=
"f>"
indexKey
=
"i"
startKey
=
"^"
endKey
=
"$"
sequenceKey
=
":>"
maxDepthKey
=
"d"
stopAtKey
=
"!"
conditionKey
=
"&"
SelectorKey_Matcher
=
"."
SelectorKey_ExploreAll
=
"a"
SelectorKey_E
xploreFields
=
"f"
SelectorKey_E
xploreIndex
=
"i"
SelectorKey_E
xploreRange
=
"r"
SelectorKey_E
xploreRecursive
=
"R"
SelectorKey_E
xploreUnion
=
"|"
SelectorKey_E
xploreConditional
=
"&"
SelectorKey_E
xploreRecursiveEdge
=
"@"
SelectorKey
_Next
=
">"
SelectorKey_Fields
=
"f>"
SelectorKey_Index
=
"i"
SelectorKey_Start
=
"^"
SelectorKey_End
=
"$"
SelectorKey_Sequence
=
":>"
SelectorKey_MaxDepth
=
"d"
SelectorKey_StopAt
=
"!"
SelectorKey_Condition
=
"&"
// not filling conditional keys since it's not complete
)
\ No newline at end of file
)
traversal/selector/selector.go
View file @
1dac0811
...
...
@@ -44,21 +44,21 @@ func (pc ParseContext) ParseSelector(n ipld.Node) (Selector, error) {
// Switch over the single key to determine which selector body comes next.
// (This switch is where the keyed union discriminators concretely happen.)
switch
kstr
{
case
e
xploreFields
Key
:
case
SelectorKey_E
xploreFields
:
return
pc
.
ParseExploreFields
(
v
)
case
e
xploreAll
Key
:
case
SelectorKey_E
xploreAll
:
return
pc
.
ParseExploreAll
(
v
)
case
e
xploreIndex
Key
:
case
SelectorKey_E
xploreIndex
:
return
pc
.
ParseExploreIndex
(
v
)
case
e
xploreRange
Key
:
case
SelectorKey_E
xploreRange
:
return
pc
.
ParseExploreRange
(
v
)
case
e
xploreUnion
Key
:
case
SelectorKey_E
xploreUnion
:
return
pc
.
ParseExploreUnion
(
v
)
case
e
xploreRecursive
Key
:
case
SelectorKey_E
xploreRecursive
:
return
pc
.
ParseExploreRecursive
(
v
)
case
e
xploreRecursiveEdge
Key
:
case
SelectorKey_E
xploreRecursiveEdge
:
return
pc
.
ParseExploreRecursiveEdge
(
v
)
case
m
atcher
Key
:
case
SelectorKey_M
atcher
:
return
pc
.
ParseMatcher
(
v
)
default
:
return
nil
,
fmt
.
Errorf
(
"selector spec parse rejected: %q is not a known member of the selector union"
,
kstr
)
...
...
traversal/traverse_test.go
View file @
1dac0811
...
...
@@ -10,6 +10,8 @@ import (
ipldfree
"github.com/ipld/go-ipld-prime/impl/free"
"github.com/ipld/go-ipld-prime/traversal"
"github.com/ipld/go-ipld-prime/traversal/selector"
"github.com/ipld/go-ipld-prime/traversal/selector/builder"
)
/* Remember, we've got the following fixtures in scope:
...
...
@@ -42,7 +44,7 @@ var (
// covers traverse using a variety of selectors.
// all cases here use one already-loaded Node; no link-loading exercised.
func
TestTraverse
(
t
*
testing
.
T
)
{
ssb
:=
selecto
r
.
NewSelectorSpecBuilder
(
ipldfree
.
NodeBuilder
())
ssb
:=
builde
r
.
NewSelectorSpecBuilder
(
ipldfree
.
NodeBuilder
())
t
.
Run
(
"traverse selecting true should visit the root"
,
func
(
t
*
testing
.
T
)
{
err
:=
traversal
.
Traverse
(
fnb
.
CreateString
(
"x"
),
selector
.
Matcher
{},
func
(
tp
traversal
.
TraversalProgress
,
n
ipld
.
Node
)
error
{
Wish
(
t
,
n
,
ShouldEqual
,
fnb
.
CreateString
(
"x"
))
...
...
@@ -60,7 +62,7 @@ func TestTraverse(t *testing.T) {
Wish
(
t
,
err
,
ShouldEqual
,
nil
)
})
t
.
Run
(
"traverse selecting fields should work"
,
func
(
t
*
testing
.
T
)
{
ss
:=
ssb
.
ExploreFields
(
func
(
efsb
selecto
r
.
ExploreFieldsSpecBuilder
)
{
ss
:=
ssb
.
ExploreFields
(
func
(
efsb
builde
r
.
ExploreFieldsSpecBuilder
)
{
efsb
.
Insert
(
"foo"
,
ssb
.
Matcher
())
efsb
.
Insert
(
"bar"
,
ssb
.
Matcher
())
})
...
...
@@ -83,9 +85,9 @@ func TestTraverse(t *testing.T) {
Wish
(
t
,
order
,
ShouldEqual
,
2
)
})
t
.
Run
(
"traverse selecting fields recursively should work"
,
func
(
t
*
testing
.
T
)
{
ss
:=
ssb
.
ExploreFields
(
func
(
efsb
selecto
r
.
ExploreFieldsSpecBuilder
)
{
ss
:=
ssb
.
ExploreFields
(
func
(
efsb
builde
r
.
ExploreFieldsSpecBuilder
)
{
efsb
.
Insert
(
"foo"
,
ssb
.
Matcher
())
efsb
.
Insert
(
"nested"
,
ssb
.
ExploreFields
(
func
(
efsb
selecto
r
.
ExploreFieldsSpecBuilder
)
{
efsb
.
Insert
(
"nested"
,
ssb
.
ExploreFields
(
func
(
efsb
builde
r
.
ExploreFieldsSpecBuilder
)
{
efsb
.
Insert
(
"nonlink"
,
ssb
.
Matcher
())
}))
})
...
...
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