Commit ddcf6b4d authored by Eric Myhre's avatar Eric Myhre

All nullable and optional cases tested & passing.

I started doing double-duty in tests to keep the volume down:
the block for nullables tests both 'nullable' and 'nullable optional';
and the optionals similarly.  Will make failures require more careful
reading to discern, but probably a fine trade.
parent bcf7b05c
......@@ -45,6 +45,10 @@ func erp(n ipld.Node, e error) interface{} {
// No iterators are exercised (marshal/unmarshal are good at that).
// No representations are exercised (that's a whole 'nother topic).
func TestGeneratedStructWithVariousFieldOptionality(t *testing.T) {
// There's a lot of cases to cover so a shorthand labels helper funcs:
// - 'v' -- value in that entry
// - 'z' -- null in that entry
// - 'u' -- undefined/absent entry
build_vvvvv := func(t *testing.T, ns ipld.NodeStyle) schema.TypedNode {
nb := ns.NewBuilder()
ma, err := nb.BeginMap(5)
......@@ -64,13 +68,14 @@ func TestGeneratedStructWithVariousFieldOptionality(t *testing.T) {
}
testLookups_vvvvv := func(t *testing.T, n ipld.Node) {
Wish(t, n.ReprKind(), ShouldEqual, ipld.ReprKind_Map)
Wish(t, n.Length(), ShouldEqual, 5)
Wish(t, plzStr(n.LookupString("f1")), ShouldEqual, "a")
Wish(t, plzStr(n.LookupString("f2")), ShouldEqual, "b")
Wish(t, plzStr(n.LookupString("f3")), ShouldEqual, "c")
Wish(t, plzStr(n.LookupString("f4")), ShouldEqual, "d")
Wish(t, plzStr(n.LookupString("f5")), ShouldEqual, "e")
}
build_vvzvv := func(t *testing.T, ns ipld.NodeStyle) schema.TypedNode {
build_vvzzv := func(t *testing.T, ns ipld.NodeStyle) schema.TypedNode {
nb := ns.NewBuilder()
ma, err := nb.BeginMap(5)
Require(t, err, ShouldEqual, nil)
......@@ -81,18 +86,41 @@ func TestGeneratedStructWithVariousFieldOptionality(t *testing.T) {
Wish(t, ma.AssembleKey().AssignString("f3"), ShouldEqual, nil)
Wish(t, ma.AssembleValue().AssignNull(), ShouldEqual, nil)
Wish(t, ma.AssembleKey().AssignString("f4"), ShouldEqual, nil)
Wish(t, ma.AssembleValue().AssignString("d"), ShouldEqual, nil)
Wish(t, ma.AssembleValue().AssignNull(), ShouldEqual, nil)
Wish(t, ma.AssembleKey().AssignString("f5"), ShouldEqual, nil)
Wish(t, ma.AssembleValue().AssignString("e"), ShouldEqual, nil)
Wish(t, ma.Finish(), ShouldEqual, nil)
return nb.Build().(schema.TypedNode)
}
testLookups_vvzvv := func(t *testing.T, n ipld.Node) {
testLookups_vvzzv := func(t *testing.T, n ipld.Node) {
Wish(t, n.ReprKind(), ShouldEqual, ipld.ReprKind_Map)
Wish(t, n.Length(), ShouldEqual, 5)
Wish(t, plzStr(n.LookupString("f1")), ShouldEqual, "a")
Wish(t, plzStr(n.LookupString("f2")), ShouldEqual, "b")
Wish(t, erp(n.LookupString("f3")), ShouldEqual, ipld.Null)
Wish(t, plzStr(n.LookupString("f4")), ShouldEqual, "d")
Wish(t, erp(n.LookupString("f4")), ShouldEqual, ipld.Null)
Wish(t, plzStr(n.LookupString("f5")), ShouldEqual, "e")
}
build_vuvuv := func(t *testing.T, ns ipld.NodeStyle) schema.TypedNode {
nb := ns.NewBuilder()
ma, err := nb.BeginMap(3)
Require(t, err, ShouldEqual, nil)
Wish(t, ma.AssembleKey().AssignString("f1"), ShouldEqual, nil)
Wish(t, ma.AssembleValue().AssignString("a"), ShouldEqual, nil)
Wish(t, ma.AssembleKey().AssignString("f3"), ShouldEqual, nil)
Wish(t, ma.AssembleValue().AssignString("c"), ShouldEqual, nil)
Wish(t, ma.AssembleKey().AssignString("f5"), ShouldEqual, nil)
Wish(t, ma.AssembleValue().AssignString("e"), ShouldEqual, nil)
Wish(t, ma.Finish(), ShouldEqual, nil)
return nb.Build().(schema.TypedNode)
}
testLookups_vuvuv := func(t *testing.T, n ipld.Node) {
Wish(t, n.ReprKind(), ShouldEqual, ipld.ReprKind_Map)
Wish(t, n.Length(), ShouldEqual, 5)
Wish(t, plzStr(n.LookupString("f1")), ShouldEqual, "a")
Wish(t, erp(n.LookupString("f2")), ShouldEqual, ipld.Undef)
Wish(t, plzStr(n.LookupString("f3")), ShouldEqual, "c")
Wish(t, erp(n.LookupString("f4")), ShouldEqual, ipld.Undef)
Wish(t, plzStr(n.LookupString("f5")), ShouldEqual, "e")
}
......@@ -114,21 +142,37 @@ func TestGeneratedStructWithVariousFieldOptionality(t *testing.T) {
// Test lookup methods.
testLookups_vvvvv(t, n)
})
t.Run("setting null nullable", func(t *testing.T) {
t.Run("setting nulls", func(t *testing.T) {
// Test building.
n := build_vvzvv(t, _Stroct__Style{})
n := build_vvzzv(t, _Stroct__Style{})
// Assert directly against expected memory state.
Wish(t, n, ShouldEqual, &_Stroct{
f1: _String{"a"},
f2: _String__Maybe{schema.Maybe_Value, _String{"b"}},
f3: _String__Maybe{schema.Maybe_Null, _String{""}},
f4: _String__Maybe{schema.Maybe_Value, _String{"d"}},
f4: _String__Maybe{schema.Maybe_Null, _String{""}},
f5: _String__Maybe{schema.Maybe_Value, _String{"e"}},
})
// Test lookup methods.
testLookups_vvzvv(t, n)
testLookups_vvzzv(t, n)
})
t.Run("not setting optionals", func(t *testing.T) {
// Test building.
n := build_vuvuv(t, _Stroct__Style{})
// Assert directly against expected memory state.
Wish(t, n, ShouldEqual, &_Stroct{
f1: _String{"a"},
f2: _String__Maybe{schema.Maybe_Absent, _String{""}},
f3: _String__Maybe{schema.Maybe_Value, _String{"c"}},
f4: _String__Maybe{schema.Maybe_Absent, _String{""}},
f5: _String__Maybe{schema.Maybe_Value, _String{"e"}},
})
// Test lookup methods.
testLookups_vuvuv(t, n)
})
})
})
......@@ -150,21 +194,37 @@ func TestGeneratedStructWithVariousFieldOptionality(t *testing.T) {
// Test lookup methods.
testLookups_vvvvv(t, n)
})
t.Run("setting null nullable", func(t *testing.T) {
t.Run("setting nulls", func(t *testing.T) {
// Test building.
n := build_vvzvv(t, _Stract__Style{})
n := build_vvzzv(t, _Stract__Style{})
// Assert directly against expected memory state.
Wish(t, n, ShouldEqual, &_Stract{
f1: _Strang{"a"},
f2: _Strang__Maybe{schema.Maybe_Value, &_Strang{"b"}},
f3: _Strang__Maybe{schema.Maybe_Null, nil},
f4: _Strang__Maybe{schema.Maybe_Value, &_Strang{"d"}},
f4: _Strang__Maybe{schema.Maybe_Null, nil},
f5: _Strang__Maybe{schema.Maybe_Value, &_Strang{"e"}},
})
// Test lookup methods.
testLookups_vvzzv(t, n)
})
t.Run("not setting optionals", func(t *testing.T) {
// Test building.
n := build_vuvuv(t, _Stract__Style{})
// Assert directly against expected memory state.
Wish(t, n, ShouldEqual, &_Stract{
f1: _Strang{"a"},
f2: _Strang__Maybe{schema.Maybe_Absent, nil},
f3: _Strang__Maybe{schema.Maybe_Value, &_Strang{"c"}},
f4: _Strang__Maybe{schema.Maybe_Absent, nil},
f5: _Strang__Maybe{schema.Maybe_Value, &_Strang{"e"}},
})
// Test lookup methods.
testLookups_vvzvv(t, n)
testLookups_vuvuv(t, n)
})
})
})
......
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