forked from jackc/pgtype
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbpchar_test.go
51 lines (43 loc) · 1.28 KB
/
bpchar_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
package pgtype_test
import (
"reflect"
"testing"
"github.com/jackc/pgtype"
"github.com/jackc/pgtype/testutil"
)
func TestChar3Transcode(t *testing.T) {
testutil.TestSuccessfulTranscodeEqFunc(t, "char(3)", []interface{}{
&pgtype.BPChar{String: "a ", Status: pgtype.Present},
&pgtype.BPChar{String: " a ", Status: pgtype.Present},
&pgtype.BPChar{String: "嗨 ", Status: pgtype.Present},
&pgtype.BPChar{String: " ", Status: pgtype.Present},
&pgtype.BPChar{Status: pgtype.Null},
}, func(aa, bb interface{}) bool {
a := aa.(pgtype.BPChar)
b := bb.(pgtype.BPChar)
return a.Status == b.Status && a.String == b.String
})
}
func TestBPCharAssignTo(t *testing.T) {
var (
str string
run rune
)
simpleTests := []struct {
src pgtype.BPChar
dst interface{}
expected interface{}
}{
{src: pgtype.BPChar{String: "simple", Status: pgtype.Present}, dst: &str, expected: "simple"},
{src: pgtype.BPChar{String: "嗨", Status: pgtype.Present}, dst: &run, expected: '嗨'},
}
for i, tt := range simpleTests {
err := tt.src.AssignTo(tt.dst)
if err != nil {
t.Errorf("%d: %v", i, err)
}
if dst := reflect.ValueOf(tt.dst).Elem().Interface(); dst != tt.expected {
t.Errorf("%d: expected %v to assign %v, but result was %v", i, tt.src, tt.expected, dst)
}
}
}