-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbits_test.go
57 lines (52 loc) · 1.83 KB
/
bits_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
package pgtype_test
import (
"bytes"
"context"
"testing"
"github.com/jackc/pgx/v5/pgtype"
"github.com/jackc/pgx/v5/pgxtest"
)
func isExpectedEqBits(a any) func(any) bool {
return func(v any) bool {
ab := a.(pgtype.Bits)
vb := v.(pgtype.Bits)
return bytes.Equal(ab.Bytes, vb.Bytes) && ab.Len == vb.Len && ab.Valid == vb.Valid
}
}
func TestBitsCodecBit(t *testing.T) {
pgxtest.RunValueRoundTripTests(context.Background(), t, defaultConnTestRunner, nil, "bit(40)", []pgxtest.ValueRoundTripTest{
{
pgtype.Bits{Bytes: []byte{0, 0, 0, 0, 0}, Len: 40, Valid: true},
new(pgtype.Bits),
isExpectedEqBits(pgtype.Bits{Bytes: []byte{0, 0, 0, 0, 0}, Len: 40, Valid: true}),
},
{
pgtype.Bits{Bytes: []byte{0, 1, 128, 254, 255}, Len: 40, Valid: true},
new(pgtype.Bits),
isExpectedEqBits(pgtype.Bits{Bytes: []byte{0, 1, 128, 254, 255}, Len: 40, Valid: true}),
},
{pgtype.Bits{}, new(pgtype.Bits), isExpectedEqBits(pgtype.Bits{})},
{nil, new(pgtype.Bits), isExpectedEqBits(pgtype.Bits{})},
})
}
func TestBitsCodecVarbit(t *testing.T) {
pgxtest.RunValueRoundTripTests(context.Background(), t, defaultConnTestRunner, nil, "varbit", []pgxtest.ValueRoundTripTest{
{
pgtype.Bits{Bytes: []byte{}, Len: 0, Valid: true},
new(pgtype.Bits),
isExpectedEqBits(pgtype.Bits{Bytes: []byte{}, Len: 0, Valid: true}),
},
{
pgtype.Bits{Bytes: []byte{0, 1, 128, 254, 255}, Len: 40, Valid: true},
new(pgtype.Bits),
isExpectedEqBits(pgtype.Bits{Bytes: []byte{0, 1, 128, 254, 255}, Len: 40, Valid: true}),
},
{
pgtype.Bits{Bytes: []byte{0, 1, 128, 254, 128}, Len: 33, Valid: true},
new(pgtype.Bits),
isExpectedEqBits(pgtype.Bits{Bytes: []byte{0, 1, 128, 254, 128}, Len: 33, Valid: true}),
},
{pgtype.Bits{}, new(pgtype.Bits), isExpectedEqBits(pgtype.Bits{})},
{nil, new(pgtype.Bits), isExpectedEqBits(pgtype.Bits{})},
})
}