2
0

Add basic array transcoding for int16, int32, and int64

This commit is contained in:
Jack Christensen
2013-07-20 19:51:01 -05:00
parent 8b27a73a08
commit 0d75daf12e
4 changed files with 293 additions and 0 deletions
+93
View File
@@ -60,3 +60,96 @@ func TestTimestampTzTranscode(t *testing.T) {
t.Errorf("Did not transcode time successfully: %v is not %v", outputTime, inputTime)
}
}
func TestInt2SliceTranscode(t *testing.T) {
testEqual := func(a, b []int16) {
if len(a) != len(b) {
t.Errorf("Did not transcode []int16 successfully: %v is not %v", a, b)
}
for i := range a {
if a[i] != b[i] {
t.Errorf("Did not transcode []int16 successfully: %v is not %v", a, b)
}
}
}
conn := getSharedConnection(t)
inputNumbers := []int16{1, 2, 3, 4, 5, 6, 7, 8}
var outputNumbers []int16
outputNumbers = mustSelectValue(t, conn, "select $1::int2[]", inputNumbers).([]int16)
testEqual(inputNumbers, outputNumbers)
mustPrepare(t, conn, "testTranscode", "select $1::int2[]")
defer func() {
if err := conn.Deallocate("testTranscode"); err != nil {
t.Fatalf("Unable to deallocate prepared statement: %v", err)
}
}()
outputNumbers = mustSelectValue(t, conn, "testTranscode", inputNumbers).([]int16)
testEqual(inputNumbers, outputNumbers)
}
func TestInt4SliceTranscode(t *testing.T) {
testEqual := func(a, b []int32) {
if len(a) != len(b) {
t.Errorf("Did not transcode []int32 successfully: %v is not %v", a, b)
}
for i := range a {
if a[i] != b[i] {
t.Errorf("Did not transcode []int32 successfully: %v is not %v", a, b)
}
}
}
conn := getSharedConnection(t)
inputNumbers := []int32{1, 2, 3, 4, 5, 6, 7, 8}
var outputNumbers []int32
outputNumbers = mustSelectValue(t, conn, "select $1::int4[]", inputNumbers).([]int32)
testEqual(inputNumbers, outputNumbers)
mustPrepare(t, conn, "testTranscode", "select $1::int4[]")
defer func() {
if err := conn.Deallocate("testTranscode"); err != nil {
t.Fatalf("Unable to deallocate prepared statement: %v", err)
}
}()
outputNumbers = mustSelectValue(t, conn, "testTranscode", inputNumbers).([]int32)
testEqual(inputNumbers, outputNumbers)
}
func TestInt8SliceTranscode(t *testing.T) {
testEqual := func(a, b []int64) {
if len(a) != len(b) {
t.Errorf("Did not transcode []int64 successfully: %v is not %v", a, b)
}
for i := range a {
if a[i] != b[i] {
t.Errorf("Did not transcode []int64 successfully: %v is not %v", a, b)
}
}
}
conn := getSharedConnection(t)
inputNumbers := []int64{1, 2, 3, 4, 5, 6, 7, 8}
var outputNumbers []int64
outputNumbers = mustSelectValue(t, conn, "select $1::int8[]", inputNumbers).([]int64)
testEqual(inputNumbers, outputNumbers)
mustPrepare(t, conn, "testTranscode", "select $1::int8[]")
defer func() {
if err := conn.Deallocate("testTranscode"); err != nil {
t.Fatalf("Unable to deallocate prepared statement: %v", err)
}
}()
outputNumbers = mustSelectValue(t, conn, "testTranscode", inputNumbers).([]int64)
testEqual(inputNumbers, outputNumbers)
}