...
1 package pgtype_test
2
3 import (
4 "reflect"
5 "testing"
6
7 "github.com/jackc/pgtype"
8 "github.com/jackc/pgtype/testutil"
9 )
10
11 func TestChar3Transcode(t *testing.T) {
12 testutil.TestSuccessfulTranscodeEqFunc(t, "char(3)", []interface{}{
13 &pgtype.BPChar{String: "a ", Status: pgtype.Present},
14 &pgtype.BPChar{String: " a ", Status: pgtype.Present},
15 &pgtype.BPChar{String: "嗨 ", Status: pgtype.Present},
16 &pgtype.BPChar{String: " ", Status: pgtype.Present},
17 &pgtype.BPChar{Status: pgtype.Null},
18 }, func(aa, bb interface{}) bool {
19 a := aa.(pgtype.BPChar)
20 b := bb.(pgtype.BPChar)
21
22 return a.Status == b.Status && a.String == b.String
23 })
24 }
25
26 func TestBPCharAssignTo(t *testing.T) {
27 var (
28 str string
29 run rune
30 )
31 simpleTests := []struct {
32 src pgtype.BPChar
33 dst interface{}
34 expected interface{}
35 }{
36 {src: pgtype.BPChar{String: "simple", Status: pgtype.Present}, dst: &str, expected: "simple"},
37 {src: pgtype.BPChar{String: "嗨", Status: pgtype.Present}, dst: &run, expected: '嗨'},
38 }
39
40 for i, tt := range simpleTests {
41 err := tt.src.AssignTo(tt.dst)
42 if err != nil {
43 t.Errorf("%d: %v", i, err)
44 }
45
46 if dst := reflect.ValueOf(tt.dst).Elem().Interface(); dst != tt.expected {
47 t.Errorf("%d: expected %v to assign %v, but result was %v", i, tt.src, tt.expected, dst)
48 }
49 }
50
51 }
52
View as plain text