Skip to content

Commit e656885

Browse files
committed
more tests
1 parent 26709a6 commit e656885

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

testing/go/types_test.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,25 +82,38 @@ var typesTests = []ScriptTest{
8282
Name: "Bit type",
8383
Focus: true,
8484
SetUpScript: []string{
85-
"CREATE TABLE t_bit (id INTEGER primary key, v1 BIT(8));",
86-
"INSERT INTO t_bit VALUES (1, B'11011010'), (2, B'00101011');",
85+
"CREATE TABLE t_bit (id INTEGER primary key, v1 BIT(8), v2 BIT(3));",
86+
"INSERT INTO t_bit VALUES (1, B'11011010', '101'), (2, B'00101011', '000');",
8787
},
8888
Assertions: []ScriptTestAssertion{
8989
{
9090
Query: "SELECT * FROM t_bit ORDER BY id;",
9191
Expected: []sql.Row{
92-
{1, pgtype.Bits{Bytes: []uint8{0xda}, Len: 8, Valid: true}},
93-
{2, pgtype.Bits{Bytes: []uint8{0x2b}, Len: 8, Valid: true}},
92+
// TODO: the pg library is interpreting the bit string `101` as `a0` (right-padded with zeroes) instead of `05`, not sure if that's correct or not
93+
{1, pgtype.Bits{Bytes: []uint8{0xda}, Len: 8, Valid: true}, pgtype.Bits{Bytes: []uint8{0xa0}, Len: 3, Valid: true}},
94+
{2, pgtype.Bits{Bytes: []uint8{0x2b}, Len: 8, Valid: true}, pgtype.Bits{Bytes: []uint8{0x0}, Len: 3, Valid: true}},
9495
},
9596
},
9697
{
97-
Query: "INSERT INTO t_bit VALUES (3, B'101');",
98+
Query: "INSERT INTO t_bit VALUES (3, B'101', '111');",
9899
ExpectedErr: "bit string length 3 does not match type bit(8)",
99100
},
100101
{
101-
Query: "INSERT INTO t_bit VALUES (3, B'1001000110');",
102+
Query: "INSERT INTO t_bit VALUES (3, B'1001000110', '111');",
102103
ExpectedErr: "bit string length 10 does not match type bit(8)",
103104
},
105+
{
106+
Query: "INSERT INTO t_bit VALUES (3, B'10010001', '11100100');",
107+
ExpectedErr: "bit string length 8 does not match type bit(3)",
108+
},
109+
{
110+
Query: "INSERT INTO t_bit VALUES (3, B'10012345', '111');",
111+
ExpectedErr: "not a valid binary digit",
112+
},
113+
{
114+
Query: "INSERT INTO t_bit VALUES (3, '10012345', '111');",
115+
ExpectedErr: "not a valid binary digit",
116+
},
104117
},
105118
},
106119
{

0 commit comments

Comments
 (0)