-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbox2d_test.go
67 lines (58 loc) · 2.06 KB
/
box2d_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package pgxgeos_test
import (
"context"
"testing"
"github.com/alecthomas/assert/v2"
"github.com/jackc/pgx/v5"
"github.com/twpayne/go-geos"
)
func TestBox2DCodecPointer(t *testing.T) {
defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, tb testing.TB, conn *pgx.Conn) {
tb.Helper()
box2D := geos.NewBox2D(1, 2, 3, 4)
var actual geos.Box2D
assert.NoError(tb, conn.QueryRow(ctx, "select $1::box2d", box2D).Scan(&actual))
assert.Equal(tb, *box2D, actual)
})
}
func TestBox2DCodecPointerToPointer(t *testing.T) {
defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, tb testing.TB, conn *pgx.Conn) {
tb.Helper()
box2D := geos.NewBox2D(1, 2, 3, 4)
var actual *geos.Box2D
assert.NoError(tb, conn.QueryRow(ctx, "select $1::box2d", box2D).Scan(&actual))
assert.Equal(tb, *box2D, *actual)
})
}
func TestBox2DCodecNull(t *testing.T) {
defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, tb testing.TB, conn *pgx.Conn) {
tb.Helper()
actual := geos.NewBox2D(1, 2, 3, 4)
assert.NoError(tb, conn.QueryRow(ctx, "select NULL::box2d").Scan(&actual))
assert.Zero(tb, actual)
})
}
func TestBox2DCodecScan(t *testing.T) {
defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, tb testing.TB, conn *pgx.Conn) {
tb.Helper()
original := geos.NewBox2D(1, 2, 3, 4)
rows, err := conn.Query(ctx, "select $1::box2d", original)
assert.NoError(t, err)
assert.True(t, rows.Next())
values, err := rows.Values()
assert.NoError(t, err)
assert.Equal(t, 1, len(values))
assert.Equal(t, *original, *values[0].(*geos.Box2D))
assert.False(t, rows.Next())
assert.NoError(t, rows.Err())
})
}
func TestBox2DCodecValue(t *testing.T) {
defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, tb testing.TB, conn *pgx.Conn) {
tb.Helper()
box2D := geos.Box2D{MinX: 1, MinY: 2, MaxX: 3, MaxY: 4}
var actual geos.Box2D
assert.NoError(tb, conn.QueryRow(ctx, "select $1::box2d", box2D).Scan(&actual))
assert.Equal(tb, box2D, actual)
})
}