github.com/jackc/pgx/v5@v5.5.5/pgtype/path_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 isExpectedEqPath(a any) func(any) bool { 12 return func(v any) bool { 13 ap := a.(pgtype.Path) 14 vp := v.(pgtype.Path) 15 16 if !(ap.Valid == vp.Valid && ap.Closed == vp.Closed && 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 TestPathTranscode(t *testing.T) { 31 skipCockroachDB(t, "Server does not support type path") 32 33 pgxtest.RunValueRoundTripTests(context.Background(), t, defaultConnTestRunner, nil, "path", []pgxtest.ValueRoundTripTest{ 34 { 35 pgtype.Path{ 36 P: []pgtype.Vec2{{3.14, 1.678901234}, {7.1, 5.234}}, 37 Closed: false, 38 Valid: true, 39 }, 40 new(pgtype.Path), 41 isExpectedEqPath(pgtype.Path{ 42 P: []pgtype.Vec2{{3.14, 1.678901234}, {7.1, 5.234}}, 43 Closed: false, 44 Valid: true, 45 }), 46 }, 47 { 48 pgtype.Path{ 49 P: []pgtype.Vec2{{3.14, 1.678}, {7.1, 5.234}, {23.1, 9.34}}, 50 Closed: true, 51 Valid: true, 52 }, 53 new(pgtype.Path), 54 isExpectedEqPath(pgtype.Path{ 55 P: []pgtype.Vec2{{3.14, 1.678}, {7.1, 5.234}, {23.1, 9.34}}, 56 Closed: true, 57 Valid: true, 58 }), 59 }, 60 { 61 pgtype.Path{ 62 P: []pgtype.Vec2{{7.1, 1.678}, {-13.14, -5.234}}, 63 Closed: true, 64 Valid: true, 65 }, 66 new(pgtype.Path), 67 isExpectedEqPath(pgtype.Path{ 68 P: []pgtype.Vec2{{7.1, 1.678}, {-13.14, -5.234}}, 69 Closed: true, 70 Valid: true, 71 }), 72 }, 73 {pgtype.Path{}, new(pgtype.Path), isExpectedEqPath(pgtype.Path{})}, 74 {nil, new(pgtype.Path), isExpectedEqPath(pgtype.Path{})}, 75 }) 76 }