pgx/jsonb_array_test.go

37 lines
812 B
Go

package pgtype_test
import (
"testing"
"github.com/jackc/pgtype"
"github.com/jackc/pgtype/testutil"
)
func TestJSONBArrayTranscode(t *testing.T) {
testutil.TestSuccessfulTranscode(t, "jsonb[]", []interface{}{
&pgtype.JSONBArray{
Elements: nil,
Dimensions: nil,
Valid: true,
},
&pgtype.JSONBArray{
Elements: []pgtype.JSONB{
{Bytes: []byte(`"foo"`), Valid: true},
{},
},
Dimensions: []pgtype.ArrayDimension{{Length: 2, LowerBound: 1}},
Valid: true,
},
&pgtype.JSONBArray{},
&pgtype.JSONBArray{
Elements: []pgtype.JSONB{
{Bytes: []byte(`"foo"`), Valid: true},
{Bytes: []byte("null"), Valid: true},
{Bytes: []byte("42"), Valid: true},
},
Dimensions: []pgtype.ArrayDimension{{Length: 3, LowerBound: 1}},
Valid: true,
},
})
}