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
8567f995
Commit
8567f995
authored
Aug 22, 2020
by
Eric Myhre
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'kinded-union-gen'
parents
46f28529
4a3b0bd7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
88 additions
and
0 deletions
+88
-0
schema/gen/go/testUnionsKinded_test.go
schema/gen/go/testUnionsKinded_test.go
+88
-0
No files found.
schema/gen/go/testUnionsKinded_test.go
0 → 100644
View file @
8567f995
package
gengo
import
(
"testing"
.
"github.com/warpfork/go-wish"
"github.com/ipld/go-ipld-prime"
"github.com/ipld/go-ipld-prime/fluent"
"github.com/ipld/go-ipld-prime/must"
"github.com/ipld/go-ipld-prime/schema"
)
func
TestUnionKinded
(
t
*
testing
.
T
)
{
ts
:=
schema
.
TypeSystem
{}
ts
.
Init
()
adjCfg
:=
&
AdjunctCfg
{}
ts
.
Accumulate
(
schema
.
SpawnString
(
"String"
))
ts
.
Accumulate
(
schema
.
SpawnStruct
(
"SmolStruct"
,
[]
schema
.
StructField
{
schema
.
SpawnStructField
(
"s"
,
"String"
,
false
,
false
),
},
schema
.
SpawnStructRepresentationMap
(
map
[
string
]
string
{
"s"
:
"q"
,
}),
))
ts
.
Accumulate
(
schema
.
SpawnUnion
(
"WheeUnion"
,
[]
schema
.
TypeName
{
"String"
,
"SmolStruct"
,
},
schema
.
SpawnUnionRepresentationKinded
(
map
[
ipld
.
ReprKind
]
schema
.
TypeName
{
ipld
.
ReprKind_String
:
"String"
,
ipld
.
ReprKind_Map
:
"SmolStruct"
,
}),
))
test
:=
func
(
t
*
testing
.
T
,
getPrototypeByName
func
(
string
)
ipld
.
NodePrototype
)
{
np
:=
getPrototypeByName
(
"WheeUnion"
)
nrp
:=
getPrototypeByName
(
"WheeUnion.Repr"
)
var
n
schema
.
TypedNode
t
.
Run
(
"typed-create"
,
func
(
t
*
testing
.
T
)
{
n
=
fluent
.
MustBuildMap
(
np
,
1
,
func
(
na
fluent
.
MapAssembler
)
{
na
.
AssembleEntry
(
"SmolStruct"
)
.
CreateMap
(
1
,
func
(
na
fluent
.
MapAssembler
)
{
na
.
AssembleEntry
(
"s"
)
.
AssignString
(
"whee"
)
})
})
.
(
schema
.
TypedNode
)
t
.
Run
(
"typed-read"
,
func
(
t
*
testing
.
T
)
{
Require
(
t
,
n
.
ReprKind
(),
ShouldEqual
,
ipld
.
ReprKind_Map
)
Wish
(
t
,
n
.
Length
(),
ShouldEqual
,
1
)
n2
:=
must
.
Node
(
n
.
LookupByString
(
"SmolStruct"
))
Require
(
t
,
n2
.
ReprKind
(),
ShouldEqual
,
ipld
.
ReprKind_Map
)
Wish
(
t
,
must
.
String
(
must
.
Node
(
n2
.
LookupByString
(
"s"
))),
ShouldEqual
,
"whee"
)
})
t
.
Run
(
"repr-read"
,
func
(
t
*
testing
.
T
)
{
nr
:=
n
.
Representation
()
Require
(
t
,
nr
.
ReprKind
(),
ShouldEqual
,
ipld
.
ReprKind_Map
)
Wish
(
t
,
nr
.
Length
(),
ShouldEqual
,
1
)
Wish
(
t
,
must
.
String
(
must
.
Node
(
nr
.
LookupByString
(
"q"
))),
ShouldEqual
,
"whee"
)
})
})
t
.
Run
(
"repr-create"
,
func
(
t
*
testing
.
T
)
{
nr
:=
fluent
.
MustBuildMap
(
nrp
,
1
,
func
(
na
fluent
.
MapAssembler
)
{
na
.
AssembleEntry
(
"q"
)
.
AssignString
(
"whee"
)
})
Wish
(
t
,
n
,
ShouldEqual
,
nr
)
})
}
t
.
Run
(
"union-using-embed"
,
func
(
t
*
testing
.
T
)
{
adjCfg
.
CfgUnionMemlayout
=
map
[
schema
.
TypeName
]
string
{
"WheeUnion"
:
"embedAll"
}
prefix
:=
"union-kinded-using-embed"
pkgName
:=
"main"
genAndCompileAndTest
(
t
,
prefix
,
pkgName
,
ts
,
adjCfg
,
func
(
t
*
testing
.
T
,
getPrototypeByName
func
(
string
)
ipld
.
NodePrototype
)
{
test
(
t
,
getPrototypeByName
)
})
})
t
.
Run
(
"union-using-interface"
,
func
(
t
*
testing
.
T
)
{
adjCfg
.
CfgUnionMemlayout
=
map
[
schema
.
TypeName
]
string
{
"WheeUnion"
:
"interface"
}
prefix
:=
"union-kinded-using-interface"
pkgName
:=
"main"
genAndCompileAndTest
(
t
,
prefix
,
pkgName
,
ts
,
adjCfg
,
func
(
t
*
testing
.
T
,
getPrototypeByName
func
(
string
)
ipld
.
NodePrototype
)
{
test
(
t
,
getPrototypeByName
)
})
})
}
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