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:
@@ -80,6 +80,74 @@ func TestInetArraySet(t *testing.T) {
|
||||
source: (([]net.IP)(nil)),
|
||||
result: pgtype.InetArray{Status: pgtype.Null},
|
||||
},
|
||||
{
|
||||
source: [][]net.IP{{mustParseCIDR(t, "127.0.0.1/32").IP}, {mustParseCIDR(t, "10.0.0.1/32").IP}},
|
||||
result: pgtype.InetArray{
|
||||
Elements: []pgtype.Inet{
|
||||
{IPNet: mustParseCIDR(t, "127.0.0.1/32"), Status: pgtype.Present},
|
||||
{IPNet: mustParseCIDR(t, "10.0.0.1/32"), Status: pgtype.Present}},
|
||||
Dimensions: []pgtype.ArrayDimension{{LowerBound: 1, Length: 2}, {LowerBound: 1, Length: 1}},
|
||||
Status: pgtype.Present},
|
||||
},
|
||||
{
|
||||
source: [][][][]*net.IPNet{
|
||||
{{{
|
||||
mustParseCIDR(t, "127.0.0.1/24"),
|
||||
mustParseCIDR(t, "10.0.0.1/24"),
|
||||
mustParseCIDR(t, "172.16.0.1/16")}}},
|
||||
{{{
|
||||
mustParseCIDR(t, "192.168.0.1/16"),
|
||||
mustParseCIDR(t, "224.0.0.1/24"),
|
||||
mustParseCIDR(t, "169.168.0.1/16")}}}},
|
||||
result: pgtype.InetArray{
|
||||
Elements: []pgtype.Inet{
|
||||
{IPNet: mustParseCIDR(t, "127.0.0.1/24"), Status: pgtype.Present},
|
||||
{IPNet: mustParseCIDR(t, "10.0.0.1/24"), Status: pgtype.Present},
|
||||
{IPNet: mustParseCIDR(t, "172.16.0.1/16"), Status: pgtype.Present},
|
||||
{IPNet: mustParseCIDR(t, "192.168.0.1/16"), Status: pgtype.Present},
|
||||
{IPNet: mustParseCIDR(t, "224.0.0.1/24"), Status: pgtype.Present},
|
||||
{IPNet: mustParseCIDR(t, "169.168.0.1/16"), 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.IP{{mustParseCIDR(t, "127.0.0.1/32").IP}, {mustParseCIDR(t, "10.0.0.1/32").IP}},
|
||||
result: pgtype.InetArray{
|
||||
Elements: []pgtype.Inet{
|
||||
{IPNet: mustParseCIDR(t, "127.0.0.1/32"), Status: pgtype.Present},
|
||||
{IPNet: mustParseCIDR(t, "10.0.0.1/32"), Status: pgtype.Present}},
|
||||
Dimensions: []pgtype.ArrayDimension{{LowerBound: 1, Length: 2}, {LowerBound: 1, Length: 1}},
|
||||
Status: pgtype.Present},
|
||||
},
|
||||
{
|
||||
source: [2][1][1][3]*net.IPNet{
|
||||
{{{
|
||||
mustParseCIDR(t, "127.0.0.1/24"),
|
||||
mustParseCIDR(t, "10.0.0.1/24"),
|
||||
mustParseCIDR(t, "172.16.0.1/16")}}},
|
||||
{{{
|
||||
mustParseCIDR(t, "192.168.0.1/16"),
|
||||
mustParseCIDR(t, "224.0.0.1/24"),
|
||||
mustParseCIDR(t, "169.168.0.1/16")}}}},
|
||||
result: pgtype.InetArray{
|
||||
Elements: []pgtype.Inet{
|
||||
{IPNet: mustParseCIDR(t, "127.0.0.1/24"), Status: pgtype.Present},
|
||||
{IPNet: mustParseCIDR(t, "10.0.0.1/24"), Status: pgtype.Present},
|
||||
{IPNet: mustParseCIDR(t, "172.16.0.1/16"), Status: pgtype.Present},
|
||||
{IPNet: mustParseCIDR(t, "192.168.0.1/16"), Status: pgtype.Present},
|
||||
{IPNet: mustParseCIDR(t, "224.0.0.1/24"), Status: pgtype.Present},
|
||||
{IPNet: mustParseCIDR(t, "169.168.0.1/16"), 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 {
|
||||
@@ -98,6 +166,10 @@ func TestInetArraySet(t *testing.T) {
|
||||
func TestInetArrayAssignTo(t *testing.T) {
|
||||
var ipnetSlice []*net.IPNet
|
||||
var ipSlice []net.IP
|
||||
var ipSliceDim2 [][]net.IP
|
||||
var ipnetSliceDim4 [][][][]*net.IPNet
|
||||
var ipArrayDim2 [2][1]net.IP
|
||||
var ipnetArrayDim4 [2][1][1][3]*net.IPNet
|
||||
|
||||
simpleTests := []struct {
|
||||
src pgtype.InetArray
|
||||
@@ -150,6 +222,78 @@ func TestInetArrayAssignTo(t *testing.T) {
|
||||
dst: &ipSlice,
|
||||
expected: (([]net.IP)(nil)),
|
||||
},
|
||||
{
|
||||
src: pgtype.InetArray{
|
||||
Elements: []pgtype.Inet{
|
||||
{IPNet: mustParseCIDR(t, "127.0.0.1/32"), Status: pgtype.Present},
|
||||
{IPNet: mustParseCIDR(t, "10.0.0.1/32"), Status: pgtype.Present}},
|
||||
Dimensions: []pgtype.ArrayDimension{{LowerBound: 1, Length: 2}, {LowerBound: 1, Length: 1}},
|
||||
Status: pgtype.Present},
|
||||
dst: &ipSliceDim2,
|
||||
expected: [][]net.IP{{mustParseCIDR(t, "127.0.0.1/32").IP}, {mustParseCIDR(t, "10.0.0.1/32").IP}},
|
||||
},
|
||||
{
|
||||
src: pgtype.InetArray{
|
||||
Elements: []pgtype.Inet{
|
||||
{IPNet: mustParseCIDR(t, "127.0.0.1/24"), Status: pgtype.Present},
|
||||
{IPNet: mustParseCIDR(t, "10.0.0.1/24"), Status: pgtype.Present},
|
||||
{IPNet: mustParseCIDR(t, "172.16.0.1/16"), Status: pgtype.Present},
|
||||
{IPNet: mustParseCIDR(t, "192.168.0.1/16"), Status: pgtype.Present},
|
||||
{IPNet: mustParseCIDR(t, "224.0.0.1/24"), Status: pgtype.Present},
|
||||
{IPNet: mustParseCIDR(t, "169.168.0.1/16"), 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: &ipnetSliceDim4,
|
||||
expected: [][][][]*net.IPNet{
|
||||
{{{
|
||||
mustParseCIDR(t, "127.0.0.1/24"),
|
||||
mustParseCIDR(t, "10.0.0.1/24"),
|
||||
mustParseCIDR(t, "172.16.0.1/16")}}},
|
||||
{{{
|
||||
mustParseCIDR(t, "192.168.0.1/16"),
|
||||
mustParseCIDR(t, "224.0.0.1/24"),
|
||||
mustParseCIDR(t, "169.168.0.1/16")}}}},
|
||||
},
|
||||
{
|
||||
src: pgtype.InetArray{
|
||||
Elements: []pgtype.Inet{
|
||||
{IPNet: mustParseCIDR(t, "127.0.0.1/32"), Status: pgtype.Present},
|
||||
{IPNet: mustParseCIDR(t, "10.0.0.1/32"), Status: pgtype.Present}},
|
||||
Dimensions: []pgtype.ArrayDimension{{LowerBound: 1, Length: 2}, {LowerBound: 1, Length: 1}},
|
||||
Status: pgtype.Present},
|
||||
dst: &ipArrayDim2,
|
||||
expected: [2][1]net.IP{{mustParseCIDR(t, "127.0.0.1/32").IP}, {mustParseCIDR(t, "10.0.0.1/32").IP}},
|
||||
},
|
||||
{
|
||||
src: pgtype.InetArray{
|
||||
Elements: []pgtype.Inet{
|
||||
{IPNet: mustParseCIDR(t, "127.0.0.1/24"), Status: pgtype.Present},
|
||||
{IPNet: mustParseCIDR(t, "10.0.0.1/24"), Status: pgtype.Present},
|
||||
{IPNet: mustParseCIDR(t, "172.16.0.1/16"), Status: pgtype.Present},
|
||||
{IPNet: mustParseCIDR(t, "192.168.0.1/16"), Status: pgtype.Present},
|
||||
{IPNet: mustParseCIDR(t, "224.0.0.1/24"), Status: pgtype.Present},
|
||||
{IPNet: mustParseCIDR(t, "169.168.0.1/16"), 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: &ipnetArrayDim4,
|
||||
expected: [2][1][1][3]*net.IPNet{
|
||||
{{{
|
||||
mustParseCIDR(t, "127.0.0.1/24"),
|
||||
mustParseCIDR(t, "10.0.0.1/24"),
|
||||
mustParseCIDR(t, "172.16.0.1/16")}}},
|
||||
{{{
|
||||
mustParseCIDR(t, "192.168.0.1/16"),
|
||||
mustParseCIDR(t, "224.0.0.1/24"),
|
||||
mustParseCIDR(t, "169.168.0.1/16")}}}},
|
||||
},
|
||||
}
|
||||
|
||||
for i, tt := range simpleTests {
|
||||
|
||||
Reference in New Issue
Block a user