~ubuntu-branches/ubuntu/saucy/golang/saucy

« back to all changes in this revision

Viewing changes to src/pkg/database/sql/convert_test.go

  • Committer: Package Import Robot
  • Author(s): Adam Conrad
  • Date: 2013-07-08 05:52:37 UTC
  • mfrom: (29.1.1 sid)
  • Revision ID: package-import@ubuntu.com-20130708055237-at01839e0hp8z3ni
Tags: 2:1.1-1ubuntu1
016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
        wantint   int64
23
23
        wantuint  uint64
24
24
        wantstr   string
 
25
        wantbytes []byte
 
26
        wantraw   RawBytes
25
27
        wantf32   float32
26
28
        wantf64   float64
27
29
        wanttime  time.Time
35
37
// Target variables for scanning into.
36
38
var (
37
39
        scanstr    string
 
40
        scanbytes  []byte
 
41
        scanraw    RawBytes
38
42
        scanint    int
39
43
        scanint8   int8
40
44
        scanint16  int16
56
60
        {s: someTime, d: &scantime, wanttime: someTime},
57
61
 
58
62
        // To strings
 
63
        {s: "string", d: &scanstr, wantstr: "string"},
59
64
        {s: []byte("byteslice"), d: &scanstr, wantstr: "byteslice"},
60
65
        {s: 123, d: &scanstr, wantstr: "123"},
61
66
        {s: int8(123), d: &scanstr, wantstr: "123"},
66
71
        {s: uint64(123), d: &scanstr, wantstr: "123"},
67
72
        {s: 1.5, d: &scanstr, wantstr: "1.5"},
68
73
 
 
74
        // To []byte
 
75
        {s: nil, d: &scanbytes, wantbytes: nil},
 
76
        {s: "string", d: &scanbytes, wantbytes: []byte("string")},
 
77
        {s: []byte("byteslice"), d: &scanbytes, wantbytes: []byte("byteslice")},
 
78
        {s: 123, d: &scanbytes, wantbytes: []byte("123")},
 
79
        {s: int8(123), d: &scanbytes, wantbytes: []byte("123")},
 
80
        {s: int64(123), d: &scanbytes, wantbytes: []byte("123")},
 
81
        {s: uint8(123), d: &scanbytes, wantbytes: []byte("123")},
 
82
        {s: uint16(123), d: &scanbytes, wantbytes: []byte("123")},
 
83
        {s: uint32(123), d: &scanbytes, wantbytes: []byte("123")},
 
84
        {s: uint64(123), d: &scanbytes, wantbytes: []byte("123")},
 
85
        {s: 1.5, d: &scanbytes, wantbytes: []byte("1.5")},
 
86
 
 
87
        // To RawBytes
 
88
        {s: nil, d: &scanraw, wantraw: nil},
 
89
        {s: []byte("byteslice"), d: &scanraw, wantraw: RawBytes("byteslice")},
 
90
        {s: 123, d: &scanraw, wantraw: RawBytes("123")},
 
91
        {s: int8(123), d: &scanraw, wantraw: RawBytes("123")},
 
92
        {s: int64(123), d: &scanraw, wantraw: RawBytes("123")},
 
93
        {s: uint8(123), d: &scanraw, wantraw: RawBytes("123")},
 
94
        {s: uint16(123), d: &scanraw, wantraw: RawBytes("123")},
 
95
        {s: uint32(123), d: &scanraw, wantraw: RawBytes("123")},
 
96
        {s: uint64(123), d: &scanraw, wantraw: RawBytes("123")},
 
97
        {s: 1.5, d: &scanraw, wantraw: RawBytes("1.5")},
 
98
 
69
99
        // Strings to integers
70
100
        {s: "255", d: &scanuint8, wantuint: 255},
71
101
        {s: "256", d: &scanuint8, wanterr: `converting string "256" to a uint8: strconv.ParseUint: parsing "256": value out of range`},
113
143
        {s: []byte("byteslice"), d: &scaniface, wantiface: []byte("byteslice")},
114
144
        {s: true, d: &scaniface, wantiface: true},
115
145
        {s: nil, d: &scaniface},
 
146
        {s: []byte(nil), d: &scaniface, wantiface: []byte(nil)},
116
147
}
117
148
 
118
149
func intPtrValue(intptr interface{}) interface{} {
191
222
                        }
192
223
                        if srcBytes, ok := ct.s.([]byte); ok {
193
224
                                dstBytes := (*ifptr).([]byte)
194
 
                                if &dstBytes[0] == &srcBytes[0] {
 
225
                                if len(srcBytes) > 0 && &dstBytes[0] == &srcBytes[0] {
195
226
                                        errf("copy into interface{} didn't copy []byte data")
196
227
                                }
197
228
                        }