2
0

Add multidimensional array and slice support.

Adds array support - previously only slices were supported.
Adds new test cases for multidimensional arrays and slices.
All previous test cases are unmodified and passed (fully backwards compatible).
Removes hard-coded type conversions for arrays, instead now relies on the type support of the array element's type conversion support.
Less maintenance for arrays, new type conversions are automatically supported when array's element gains new type support.
Simplifies typed_array_gen.sh generator script by removing the hard-coded single-dimensional types for arrays.
Only typed_array.go.erb and typed_array_gen.sh have been changed + 1 new auxiliary function in array.go file + additional tests in test files for each array. Other changes are from generated code.
This commit is contained in:
Simo Haasanen
2020-08-07 13:10:32 +01:00
parent d831ba712a
commit 449a8a4f8e
46 changed files with 6193 additions and 3113 deletions
+152
View File
@@ -44,6 +44,78 @@ func TestMacaddrArraySet(t *testing.T) {
source: (([]net.HardwareAddr)(nil)),
result: pgtype.MacaddrArray{Status: pgtype.Null},
},
{
source: [][]net.HardwareAddr{
{mustParseMacaddr(t, "01:23:45:67:89:ab")},
{mustParseMacaddr(t, "cd:ef:01:23:45:67")}},
result: pgtype.MacaddrArray{
Elements: []pgtype.Macaddr{
{Addr: mustParseMacaddr(t, "01:23:45:67:89:ab"), Status: pgtype.Present},
{Addr: mustParseMacaddr(t, "cd:ef:01:23:45:67"), Status: pgtype.Present}},
Dimensions: []pgtype.ArrayDimension{{LowerBound: 1, Length: 2}, {LowerBound: 1, Length: 1}},
Status: pgtype.Present},
},
{
source: [][][][]net.HardwareAddr{
{{{
mustParseMacaddr(t, "01:23:45:67:89:ab"),
mustParseMacaddr(t, "cd:ef:01:23:45:67"),
mustParseMacaddr(t, "89:ab:cd:ef:01:23")}}},
{{{
mustParseMacaddr(t, "45:67:89:ab:cd:ef"),
mustParseMacaddr(t, "fe:dc:ba:98:76:54"),
mustParseMacaddr(t, "32:10:fe:dc:ba:98")}}}},
result: pgtype.MacaddrArray{
Elements: []pgtype.Macaddr{
{Addr: mustParseMacaddr(t, "01:23:45:67:89:ab"), Status: pgtype.Present},
{Addr: mustParseMacaddr(t, "cd:ef:01:23:45:67"), Status: pgtype.Present},
{Addr: mustParseMacaddr(t, "89:ab:cd:ef:01:23"), Status: pgtype.Present},
{Addr: mustParseMacaddr(t, "45:67:89:ab:cd:ef"), Status: pgtype.Present},
{Addr: mustParseMacaddr(t, "fe:dc:ba:98:76:54"), Status: pgtype.Present},
{Addr: mustParseMacaddr(t, "32:10:fe:dc:ba:98"), Status: pgtype.Present}},
Dimensions: []pgtype.ArrayDimension{
{LowerBound: 1, Length: 2},
{LowerBound: 1, Length: 1},
{LowerBound: 1, Length: 1},
{LowerBound: 1, Length: 3}},
Status: pgtype.Present},
},
{
source: [2][1]net.HardwareAddr{
{mustParseMacaddr(t, "01:23:45:67:89:ab")},
{mustParseMacaddr(t, "cd:ef:01:23:45:67")}},
result: pgtype.MacaddrArray{
Elements: []pgtype.Macaddr{
{Addr: mustParseMacaddr(t, "01:23:45:67:89:ab"), Status: pgtype.Present},
{Addr: mustParseMacaddr(t, "cd:ef:01:23:45:67"), Status: pgtype.Present}},
Dimensions: []pgtype.ArrayDimension{{LowerBound: 1, Length: 2}, {LowerBound: 1, Length: 1}},
Status: pgtype.Present},
},
{
source: [2][1][1][3]net.HardwareAddr{
{{{
mustParseMacaddr(t, "01:23:45:67:89:ab"),
mustParseMacaddr(t, "cd:ef:01:23:45:67"),
mustParseMacaddr(t, "89:ab:cd:ef:01:23")}}},
{{{
mustParseMacaddr(t, "45:67:89:ab:cd:ef"),
mustParseMacaddr(t, "fe:dc:ba:98:76:54"),
mustParseMacaddr(t, "32:10:fe:dc:ba:98")}}}},
result: pgtype.MacaddrArray{
Elements: []pgtype.Macaddr{
{Addr: mustParseMacaddr(t, "01:23:45:67:89:ab"), Status: pgtype.Present},
{Addr: mustParseMacaddr(t, "cd:ef:01:23:45:67"), Status: pgtype.Present},
{Addr: mustParseMacaddr(t, "89:ab:cd:ef:01:23"), Status: pgtype.Present},
{Addr: mustParseMacaddr(t, "45:67:89:ab:cd:ef"), Status: pgtype.Present},
{Addr: mustParseMacaddr(t, "fe:dc:ba:98:76:54"), Status: pgtype.Present},
{Addr: mustParseMacaddr(t, "32:10:fe:dc:ba:98"), Status: pgtype.Present}},
Dimensions: []pgtype.ArrayDimension{
{LowerBound: 1, Length: 2},
{LowerBound: 1, Length: 1},
{LowerBound: 1, Length: 1},
{LowerBound: 1, Length: 3}},
Status: pgtype.Present},
},
}
for i, tt := range successfulTests {
@@ -61,6 +133,10 @@ func TestMacaddrArraySet(t *testing.T) {
func TestMacaddrArrayAssignTo(t *testing.T) {
var macaddrSlice []net.HardwareAddr
var macaddrSliceDim2 [][]net.HardwareAddr
var macaddrSliceDim4 [][][][]net.HardwareAddr
var macaddrArrayDim2 [2][1]net.HardwareAddr
var macaddrArrayDim4 [2][1][1][3]net.HardwareAddr
simpleTests := []struct {
src pgtype.MacaddrArray
@@ -90,6 +166,82 @@ func TestMacaddrArrayAssignTo(t *testing.T) {
dst: &macaddrSlice,
expected: (([]net.HardwareAddr)(nil)),
},
{
src: pgtype.MacaddrArray{
Elements: []pgtype.Macaddr{
{Addr: mustParseMacaddr(t, "01:23:45:67:89:ab"), Status: pgtype.Present},
{Addr: mustParseMacaddr(t, "cd:ef:01:23:45:67"), Status: pgtype.Present}},
Dimensions: []pgtype.ArrayDimension{{LowerBound: 1, Length: 2}, {LowerBound: 1, Length: 1}},
Status: pgtype.Present},
dst: &macaddrSliceDim2,
expected: [][]net.HardwareAddr{
{mustParseMacaddr(t, "01:23:45:67:89:ab")},
{mustParseMacaddr(t, "cd:ef:01:23:45:67")}},
},
{
src: pgtype.MacaddrArray{
Elements: []pgtype.Macaddr{
{Addr: mustParseMacaddr(t, "01:23:45:67:89:ab"), Status: pgtype.Present},
{Addr: mustParseMacaddr(t, "cd:ef:01:23:45:67"), Status: pgtype.Present},
{Addr: mustParseMacaddr(t, "89:ab:cd:ef:01:23"), Status: pgtype.Present},
{Addr: mustParseMacaddr(t, "45:67:89:ab:cd:ef"), Status: pgtype.Present},
{Addr: mustParseMacaddr(t, "fe:dc:ba:98:76:54"), Status: pgtype.Present},
{Addr: mustParseMacaddr(t, "32:10:fe:dc:ba:98"), Status: pgtype.Present}},
Dimensions: []pgtype.ArrayDimension{
{LowerBound: 1, Length: 2},
{LowerBound: 1, Length: 1},
{LowerBound: 1, Length: 1},
{LowerBound: 1, Length: 3}},
Status: pgtype.Present},
dst: &macaddrSliceDim4,
expected: [][][][]net.HardwareAddr{
{{{
mustParseMacaddr(t, "01:23:45:67:89:ab"),
mustParseMacaddr(t, "cd:ef:01:23:45:67"),
mustParseMacaddr(t, "89:ab:cd:ef:01:23")}}},
{{{
mustParseMacaddr(t, "45:67:89:ab:cd:ef"),
mustParseMacaddr(t, "fe:dc:ba:98:76:54"),
mustParseMacaddr(t, "32:10:fe:dc:ba:98")}}}},
},
{
src: pgtype.MacaddrArray{
Elements: []pgtype.Macaddr{
{Addr: mustParseMacaddr(t, "01:23:45:67:89:ab"), Status: pgtype.Present},
{Addr: mustParseMacaddr(t, "cd:ef:01:23:45:67"), Status: pgtype.Present}},
Dimensions: []pgtype.ArrayDimension{{LowerBound: 1, Length: 2}, {LowerBound: 1, Length: 1}},
Status: pgtype.Present},
dst: &macaddrArrayDim2,
expected: [2][1]net.HardwareAddr{
{mustParseMacaddr(t, "01:23:45:67:89:ab")},
{mustParseMacaddr(t, "cd:ef:01:23:45:67")}},
},
{
src: pgtype.MacaddrArray{
Elements: []pgtype.Macaddr{
{Addr: mustParseMacaddr(t, "01:23:45:67:89:ab"), Status: pgtype.Present},
{Addr: mustParseMacaddr(t, "cd:ef:01:23:45:67"), Status: pgtype.Present},
{Addr: mustParseMacaddr(t, "89:ab:cd:ef:01:23"), Status: pgtype.Present},
{Addr: mustParseMacaddr(t, "45:67:89:ab:cd:ef"), Status: pgtype.Present},
{Addr: mustParseMacaddr(t, "fe:dc:ba:98:76:54"), Status: pgtype.Present},
{Addr: mustParseMacaddr(t, "32:10:fe:dc:ba:98"), Status: pgtype.Present}},
Dimensions: []pgtype.ArrayDimension{
{LowerBound: 1, Length: 2},
{LowerBound: 1, Length: 1},
{LowerBound: 1, Length: 1},
{LowerBound: 1, Length: 3}},
Status: pgtype.Present},
dst: &macaddrArrayDim4,
expected: [2][1][1][3]net.HardwareAddr{
{{{
mustParseMacaddr(t, "01:23:45:67:89:ab"),
mustParseMacaddr(t, "cd:ef:01:23:45:67"),
mustParseMacaddr(t, "89:ab:cd:ef:01:23")}}},
{{{
mustParseMacaddr(t, "45:67:89:ab:cd:ef"),
mustParseMacaddr(t, "fe:dc:ba:98:76:54"),
mustParseMacaddr(t, "32:10:fe:dc:ba:98")}}}},
},
}
for i, tt := range simpleTests {