github.com/jackc/pgx/v5@v5.5.5/pgtype/polygon_test.go (about) 1 package pgtype_test 2 3 import ( 4 "context" 5 "testing" 6 7 "github.com/jackc/pgx/v5/pgtype" 8 "github.com/jackc/pgx/v5/pgxtest" 9 ) 10 11 func isExpectedEqPolygon(a any) func(any) bool { 12 return func(v any) bool { 13 ap := a.(pgtype.Polygon) 14 vp := v.(pgtype.Polygon) 15 16 if !(ap.Valid == vp.Valid && len(ap.P) == len(vp.P)) { 17 return false 18 } 19 20 for i := range ap.P { 21 if ap.P[i] != vp.P[i] { 22 return false 23 } 24 } 25 26 return true 27 } 28 } 29 30 func TestPolygonTranscode(t *testing.T) { 31 skipCockroachDB(t, "Server does not support type polygon") 32 33 pgxtest.RunValueRoundTripTests(context.Background(), t, defaultConnTestRunner, nil, "polygon", []pgxtest.ValueRoundTripTest{ 34 { 35 pgtype.Polygon{ 36 P: []pgtype.Vec2{{3.14, 1.678901234}, {7.1, 5.234}, {5.0, 3.234}}, 37 Valid: true, 38 }, 39 new(pgtype.Polygon), 40 isExpectedEqPolygon(pgtype.Polygon{ 41 P: []pgtype.Vec2{{3.14, 1.678901234}, {7.1, 5.234}, {5.0, 3.234}}, 42 Valid: true, 43 }), 44 }, 45 { 46 pgtype.Polygon{ 47 P: []pgtype.Vec2{{3.14, -1.678}, {7.1, -5.234}, {23.1, 9.34}}, 48 Valid: true, 49 }, 50 new(pgtype.Polygon), 51 isExpectedEqPolygon(pgtype.Polygon{ 52 P: []pgtype.Vec2{{3.14, -1.678}, {7.1, -5.234}, {23.1, 9.34}}, 53 Valid: true, 54 }), 55 }, 56 {pgtype.Polygon{}, new(pgtype.Polygon), isExpectedEqPolygon(pgtype.Polygon{})}, 57 {nil, new(pgtype.Polygon), isExpectedEqPolygon(pgtype.Polygon{})}, 58 }) 59 }