ee93440ac1
Added ValueRoundTripTest to pgxtest Removed pgtype/testutil pgtype tests now run with all (applicable) query modes. This gives better coverage than before and revealed several bugs which are also fixed in this commit.
60 lines
1.4 KiB
Go
60 lines
1.4 KiB
Go
package pgtype_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
"github.com/jackc/pgx/v5/pgxtest"
|
|
)
|
|
|
|
func isExpectedEqPolygon(a interface{}) func(interface{}) bool {
|
|
return func(v interface{}) bool {
|
|
ap := a.(pgtype.Polygon)
|
|
vp := v.(pgtype.Polygon)
|
|
|
|
if !(ap.Valid == vp.Valid && len(ap.P) == len(vp.P)) {
|
|
return false
|
|
}
|
|
|
|
for i := range ap.P {
|
|
if ap.P[i] != vp.P[i] {
|
|
return false
|
|
}
|
|
}
|
|
|
|
return true
|
|
}
|
|
}
|
|
|
|
func TestPolygonTranscode(t *testing.T) {
|
|
skipCockroachDB(t, "Server does not support type polygon")
|
|
|
|
pgxtest.RunValueRoundTripTests(context.Background(), t, defaultConnTestRunner, nil, "polygon", []pgxtest.ValueRoundTripTest{
|
|
{
|
|
pgtype.Polygon{
|
|
P: []pgtype.Vec2{{3.14, 1.678901234}, {7.1, 5.234}, {5.0, 3.234}},
|
|
Valid: true,
|
|
},
|
|
new(pgtype.Polygon),
|
|
isExpectedEqPolygon(pgtype.Polygon{
|
|
P: []pgtype.Vec2{{3.14, 1.678901234}, {7.1, 5.234}, {5.0, 3.234}},
|
|
Valid: true,
|
|
}),
|
|
},
|
|
{
|
|
pgtype.Polygon{
|
|
P: []pgtype.Vec2{{3.14, -1.678}, {7.1, -5.234}, {23.1, 9.34}},
|
|
Valid: true,
|
|
},
|
|
new(pgtype.Polygon),
|
|
isExpectedEqPolygon(pgtype.Polygon{
|
|
P: []pgtype.Vec2{{3.14, -1.678}, {7.1, -5.234}, {23.1, 9.34}},
|
|
Valid: true,
|
|
}),
|
|
},
|
|
{pgtype.Polygon{}, new(pgtype.Polygon), isExpectedEqPolygon(pgtype.Polygon{})},
|
|
{nil, new(pgtype.Polygon), isExpectedEqPolygon(pgtype.Polygon{})},
|
|
})
|
|
}
|