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
50e2df1e
Commit
50e2df1e
authored
Apr 27, 2020
by
Eric Myhre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add more test specs for list and map nesting.
parent
44af1145
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
115 additions
and
0 deletions
+115
-0
node/basic/list_test.go
node/basic/list_test.go
+11
-0
node/basic/map_test.go
node/basic/map_test.go
+1
-0
node/tests/listSpecs.go
node/tests/listSpecs.go
+63
-0
node/tests/mapSpecs.go
node/tests/mapSpecs.go
+40
-0
No files found.
node/basic/list_test.go
0 → 100644
View file @
50e2df1e
package
basicnode
import
(
"testing"
"github.com/ipld/go-ipld-prime/node/tests"
)
func
TestList
(
t
*
testing
.
T
)
{
tests
.
SpecTestListString
(
t
,
Style__List
{})
}
node/basic/map_test.go
View file @
50e2df1e
...
...
@@ -9,6 +9,7 @@ import (
func
TestMap
(
t
*
testing
.
T
)
{
tests
.
SpecTestMapStrInt
(
t
,
Style__Map
{})
tests
.
SpecTestMapStrMapStrInt
(
t
,
Style__Map
{})
tests
.
SpecTestMapStrListStr
(
t
,
Style__Map
{})
}
func
BenchmarkMapStrInt_3n_AssembleStandard
(
b
*
testing
.
B
)
{
...
...
node/tests/listSpecs.go
0 → 100644
View file @
50e2df1e
package
tests
import
(
"testing"
.
"github.com/warpfork/go-wish"
ipld
"github.com/ipld/go-ipld-prime"
"github.com/ipld/go-ipld-prime/fluent"
"github.com/ipld/go-ipld-prime/must"
)
func
SpecTestListString
(
t
*
testing
.
T
,
ns
ipld
.
NodeStyle
)
{
t
.
Run
(
"list<string>, 3 entries"
,
func
(
t
*
testing
.
T
)
{
n
:=
fluent
.
MustBuildList
(
ns
,
3
,
func
(
la
fluent
.
ListAssembler
)
{
la
.
AssembleValue
()
.
AssignString
(
"one"
)
la
.
AssembleValue
()
.
AssignString
(
"two"
)
la
.
AssembleValue
()
.
AssignString
(
"three"
)
})
t
.
Run
(
"reads back out"
,
func
(
t
*
testing
.
T
)
{
Wish
(
t
,
n
.
Length
(),
ShouldEqual
,
3
)
v
,
err
:=
n
.
LookupIndex
(
0
)
Wish
(
t
,
err
,
ShouldEqual
,
nil
)
Wish
(
t
,
must
.
String
(
v
),
ShouldEqual
,
"one"
)
v
,
err
=
n
.
LookupIndex
(
1
)
Wish
(
t
,
err
,
ShouldEqual
,
nil
)
Wish
(
t
,
must
.
String
(
v
),
ShouldEqual
,
"two"
)
v
,
err
=
n
.
LookupIndex
(
2
)
Wish
(
t
,
err
,
ShouldEqual
,
nil
)
Wish
(
t
,
must
.
String
(
v
),
ShouldEqual
,
"three"
)
})
t
.
Run
(
"reads via iteration"
,
func
(
t
*
testing
.
T
)
{
itr
:=
n
.
ListIterator
()
Wish
(
t
,
itr
.
Done
(),
ShouldEqual
,
false
)
idx
,
v
,
err
:=
itr
.
Next
()
Wish
(
t
,
err
,
ShouldEqual
,
nil
)
Wish
(
t
,
idx
,
ShouldEqual
,
0
)
Wish
(
t
,
must
.
String
(
v
),
ShouldEqual
,
"one"
)
Wish
(
t
,
itr
.
Done
(),
ShouldEqual
,
false
)
idx
,
v
,
err
=
itr
.
Next
()
Wish
(
t
,
err
,
ShouldEqual
,
nil
)
Wish
(
t
,
idx
,
ShouldEqual
,
1
)
Wish
(
t
,
must
.
String
(
v
),
ShouldEqual
,
"two"
)
Wish
(
t
,
itr
.
Done
(),
ShouldEqual
,
false
)
idx
,
v
,
err
=
itr
.
Next
()
Wish
(
t
,
err
,
ShouldEqual
,
nil
)
Wish
(
t
,
idx
,
ShouldEqual
,
2
)
Wish
(
t
,
must
.
String
(
v
),
ShouldEqual
,
"three"
)
Wish
(
t
,
itr
.
Done
(),
ShouldEqual
,
true
)
idx
,
v
,
err
=
itr
.
Next
()
Wish
(
t
,
err
,
ShouldEqual
,
ipld
.
ErrIteratorOverread
{})
Wish
(
t
,
idx
,
ShouldEqual
,
-
1
)
Wish
(
t
,
v
,
ShouldEqual
,
nil
)
})
})
}
node/tests/mapSpecs.go
View file @
50e2df1e
...
...
@@ -186,3 +186,43 @@ func SpecTestMapStrMapStrInt(t *testing.T, ns ipld.NodeStyle) {
})
})
}
func
SpecTestMapStrListStr
(
t
*
testing
.
T
,
ns
ipld
.
NodeStyle
)
{
t
.
Run
(
"map<str,list<str>>"
,
func
(
t
*
testing
.
T
)
{
nb
:=
ns
.
NewBuilder
()
ma
,
err
:=
nb
.
BeginMap
(
3
)
must
.
NotError
(
err
)
must
.
NotError
(
ma
.
AssembleKey
()
.
AssignString
(
"asdf"
))
func
(
la
ipld
.
ListAssembler
,
err
error
)
{
must
.
NotError
(
la
.
AssembleValue
()
.
AssignString
(
"eleven"
))
must
.
NotError
(
la
.
AssembleValue
()
.
AssignString
(
"twelve"
))
must
.
NotError
(
la
.
AssembleValue
()
.
AssignString
(
"thirteen"
))
must
.
NotError
(
la
.
Finish
())
}(
ma
.
AssembleValue
()
.
BeginList
(
3
))
must
.
NotError
(
ma
.
AssembleKey
()
.
AssignString
(
"qwer"
))
func
(
la
ipld
.
ListAssembler
,
err
error
)
{
must
.
NotError
(
la
.
AssembleValue
()
.
AssignString
(
"twentyone"
))
must
.
NotError
(
la
.
AssembleValue
()
.
AssignString
(
"twentytwo"
))
must
.
NotError
(
la
.
Finish
())
}(
ma
.
AssembleValue
()
.
BeginList
(
2
))
must
.
NotError
(
ma
.
AssembleKey
()
.
AssignString
(
"zxcv"
))
func
(
la
ipld
.
ListAssembler
,
err
error
)
{
must
.
NotError
(
la
.
AssembleValue
()
.
AssignString
(
"thirtyone"
))
must
.
NotError
(
la
.
Finish
())
}(
ma
.
AssembleValue
()
.
BeginList
(
1
))
must
.
NotError
(
ma
.
Finish
())
n
:=
nb
.
Build
()
t
.
Run
(
"reads back out"
,
func
(
t
*
testing
.
T
)
{
Wish
(
t
,
n
.
Length
(),
ShouldEqual
,
3
)
v
,
err
:=
n
.
LookupString
(
"qwer"
)
Wish
(
t
,
err
,
ShouldEqual
,
nil
)
v2
,
err
:=
v
.
LookupIndex
(
1
)
Wish
(
t
,
err
,
ShouldEqual
,
nil
)
v3
,
err
:=
v2
.
AsString
()
Wish
(
t
,
err
,
ShouldEqual
,
nil
)
Wish
(
t
,
v3
,
ShouldEqual
,
"twentytwo"
)
})
})
}
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