Commit a0da09a0 authored by Eric Myhre's avatar Eric Myhre

Type system compat tests outline.

This is an idea on how we might try to test these features, but
there's quite a bit of work to go -- these aren't connected yet.

Making the 'newNb' functions for the runtime/wrapper-based typed.Node
implementations will be easy enough.  Making them connect for the
codegenerated stuff might need more interesting glue, and I'm still not
entirely sure how to go about making good tests for something that
involves running the compiler more than once.
Signed-off-by: default avatarEric Myhre <hash@exultant.us>
parent 99058684
// The `schema/tests` package contains behavioral tests for type-constrained
// Node implementations -- meant to work with either codegenerated Nodes OR
// with the runtime typed.Node wrappers, checking for the same behavior on each.
package tests
package tests
import (
"testing"
. "github.com/warpfork/go-wish"
ipld "github.com/ipld/go-ipld-prime"
ipldfree "github.com/ipld/go-ipld-prime/impl/free"
"github.com/ipld/go-ipld-prime/schema"
)
func TestFoo(t *testing.T, newNb func(typ schema.Type) ipld.NodeBuilder) {
tString := schema.SpawnString("String")
tStroct := schema.SpawnStruct("Stroct",
[]schema.StructField{
schema.SpawnStructField("f1", tString, false, false),
schema.SpawnStructField("f2", tString, true, false),
schema.SpawnStructField("f3", tString, true, true),
schema.SpawnStructField("f4", tString, false, false),
},
schema.StructRepresentation_Map{},
)
nbString := newNb(tString)
nbStroct := newNb(tStroct)
var n1 ipld.Node
t.Run("test building", func(t *testing.T) {
t.Run("all values valid", func(t *testing.T) {
mb, err := nbStroct.CreateMap()
Wish(t, err, ShouldEqual, nil)
// Set 'f1' to a valid, typed string.
v, _ := nbString.CreateString("asdf")
Wish(t, mb.Insert(ipldfree.String("f1"), v), ShouldEqual, nil)
// Skip setting 'f2' -- it's optional.
// Set 'f3' to null. Nulls aren't typed.
Wish(t, mb.Insert(ipldfree.String("f3"), ipld.Null), ShouldEqual, nil)
// Set 'f4' to a valid, typed string.
v, _ = nbString.CreateString("qwer")
Wish(t, mb.Insert(ipldfree.String("f4"), v), ShouldEqual, nil)
n1, err = mb.Build()
Wish(t, err, ShouldEqual, nil)
})
t.Run("wrong type rejected", func(t *testing.T) {
})
t.Run("invalid key rejected", func(t *testing.T) {
})
t.Run("missing nonoptional rejected", func(t *testing.T) {
})
t.Run("null nonnullable rejected", func(t *testing.T) {
})
})
t.Run("reading", func(t *testing.T) {
t.Run("regular fields", func(t *testing.T) {
v, err := n1.TraverseField("f1")
Wish(t, err, ShouldEqual, nil)
v2, _ := nbString.CreateString("asdf")
Wish(t, v, ShouldEqual, v2)
})
t.Run("optional absent fields", func(t *testing.T) {
})
t.Run("null nullable fields", func(t *testing.T) {
})
t.Run("invalid key", func(t *testing.T) {
})
t.Run("iterating", func(t *testing.T) {
})
})
t.Run("test parsing", func(t *testing.T) {
t.Run("strict order", func(t *testing.T) {
// FUTURE
})
})
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment