1 package pgtype_test
2
3 import (
4 "testing"
5
6 "github.com/jackc/pgtype"
7 "github.com/jackc/pgtype/testutil"
8 )
9
10 func TestInt4multirangeTranscode(t *testing.T) {
11 testutil.TestSuccessfulTranscode(t, "int4multirange", []interface{}{
12 &pgtype.Int4multirange{
13 Ranges: nil,
14 Status: pgtype.Present,
15 },
16 &pgtype.Int4multirange{
17 Ranges: []pgtype.Int4range{
18 {
19 Lower: pgtype.Int4{Int: -543, Status: pgtype.Present},
20 Upper: pgtype.Int4{Int: 342, Status: pgtype.Present},
21 LowerType: pgtype.Inclusive,
22 UpperType: pgtype.Exclusive,
23 Status: pgtype.Present,
24 },
25 },
26 Status: pgtype.Present,
27 },
28 &pgtype.Int4multirange{
29 Ranges: []pgtype.Int4range{
30 {
31 Lower: pgtype.Int4{Int: -42, Status: pgtype.Present},
32 Upper: pgtype.Int4{Int: -5, Status: pgtype.Present},
33 LowerType: pgtype.Inclusive,
34 UpperType: pgtype.Exclusive,
35 Status: pgtype.Present,
36 },
37 {
38 Lower: pgtype.Int4{Int: 5, Status: pgtype.Present},
39 Upper: pgtype.Int4{Int: 42, Status: pgtype.Present},
40 LowerType: pgtype.Inclusive,
41 UpperType: pgtype.Exclusive,
42 Status: pgtype.Present,
43 },
44 {
45 Lower: pgtype.Int4{Int: 52, Status: pgtype.Present},
46 LowerType: pgtype.Inclusive,
47 UpperType: pgtype.Unbounded,
48 Status: pgtype.Present,
49 },
50 },
51 Status: pgtype.Present,
52 },
53 })
54 }
55
56 func TestInt4multirangeNormalize(t *testing.T) {
57 testutil.TestSuccessfulNormalize(t, []testutil.NormalizeTest{
58 {
59 SQL: "select int4multirange(int4range(1, 14, '(]'), int4range(20, 25, '()'))",
60 Value: pgtype.Int4multirange{
61 Ranges: []pgtype.Int4range{
62 {
63 Lower: pgtype.Int4{Int: 2, Status: pgtype.Present},
64 Upper: pgtype.Int4{Int: 15, Status: pgtype.Present},
65 LowerType: pgtype.Inclusive,
66 UpperType: pgtype.Exclusive,
67 Status: pgtype.Present,
68 },
69 {
70 Lower: pgtype.Int4{Int: 21, Status: pgtype.Present},
71 Upper: pgtype.Int4{Int: 25, Status: pgtype.Present},
72 LowerType: pgtype.Inclusive,
73 UpperType: pgtype.Exclusive,
74 Status: pgtype.Present,
75 },
76 },
77 Status: pgtype.Present,
78 },
79 },
80 })
81 }
82
View as plain text