Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(49)

Side by Side Diff: src/pkg/database/sql/convert_test.go

Issue 7962044: code review 7962044: database/sql: optimized []byte copy + []byte(nil) -> *i...
Patch Set: diff -r 07ed29a4f9f5 https://code.google.com/p/go Created 12 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pkg/database/sql/convert.go ('k') | src/pkg/database/sql/sql.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Go Authors. All rights reserved. 1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package sql 5 package sql
6 6
7 import ( 7 import (
8 "database/sql/driver" 8 "database/sql/driver"
9 "fmt" 9 "fmt"
10 "reflect" 10 "reflect"
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 {s: interface{}(nil), d: &scanptr, wantnil: true}, 136 {s: interface{}(nil), d: &scanptr, wantnil: true},
137 {s: int64(42), d: &scanptr, wantptr: &answer}, 137 {s: int64(42), d: &scanptr, wantptr: &answer},
138 138
139 // To interface{} 139 // To interface{}
140 {s: float64(1.5), d: &scaniface, wantiface: float64(1.5)}, 140 {s: float64(1.5), d: &scaniface, wantiface: float64(1.5)},
141 {s: int64(1), d: &scaniface, wantiface: int64(1)}, 141 {s: int64(1), d: &scaniface, wantiface: int64(1)},
142 {s: "str", d: &scaniface, wantiface: "str"}, 142 {s: "str", d: &scaniface, wantiface: "str"},
143 {s: []byte("byteslice"), d: &scaniface, wantiface: []byte("byteslice")}, 143 {s: []byte("byteslice"), d: &scaniface, wantiface: []byte("byteslice")},
144 {s: true, d: &scaniface, wantiface: true}, 144 {s: true, d: &scaniface, wantiface: true},
145 {s: nil, d: &scaniface}, 145 {s: nil, d: &scaniface},
146 {s: []byte(nil), d: &scaniface, wantiface: []byte(nil)},
146 } 147 }
147 148
148 func intPtrValue(intptr interface{}) interface{} { 149 func intPtrValue(intptr interface{}) interface{} {
149 return reflect.Indirect(reflect.Indirect(reflect.ValueOf(intptr))).Int() 150 return reflect.Indirect(reflect.Indirect(reflect.ValueOf(intptr))).Int()
150 } 151 }
151 152
152 func intValue(intptr interface{}) int64 { 153 func intValue(intptr interface{}) int64 {
153 return reflect.Indirect(reflect.ValueOf(intptr)).Int() 154 return reflect.Indirect(reflect.ValueOf(intptr)).Int()
154 } 155 }
155 156
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 errf("want pointer to %v, got %v", *ct.wantptr, intPtrValue(ct.d)) 215 errf("want pointer to %v, got %v", *ct.wantptr, intPtrValue(ct.d))
215 } 216 }
216 } 217 }
217 if ifptr, ok := ct.d.(*interface{}); ok { 218 if ifptr, ok := ct.d.(*interface{}); ok {
218 if !reflect.DeepEqual(ct.wantiface, scaniface) { 219 if !reflect.DeepEqual(ct.wantiface, scaniface) {
219 errf("want interface %#v, got %#v", ct.wantiface , scaniface) 220 errf("want interface %#v, got %#v", ct.wantiface , scaniface)
220 continue 221 continue
221 } 222 }
222 if srcBytes, ok := ct.s.([]byte); ok { 223 if srcBytes, ok := ct.s.([]byte); ok {
223 dstBytes := (*ifptr).([]byte) 224 dstBytes := (*ifptr).([]byte)
224 » » » » if &dstBytes[0] == &srcBytes[0] { 225 » » » » if len(srcBytes) > 0 && &dstBytes[0] == &srcByte s[0] {
225 errf("copy into interface{} didn't copy []byte data") 226 errf("copy into interface{} didn't copy []byte data")
226 } 227 }
227 } 228 }
228 } 229 }
229 } 230 }
230 } 231 }
231 232
232 func TestNullString(t *testing.T) { 233 func TestNullString(t *testing.T) {
233 var ns NullString 234 var ns NullString
234 convertAssign(&ns, []byte("foo")) 235 convertAssign(&ns, []byte("foo"))
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 } 272 }
272 if tt.err != "" { 273 if tt.err != "" {
273 continue 274 continue
274 } 275 }
275 if !reflect.DeepEqual(out, tt.out) { 276 if !reflect.DeepEqual(out, tt.out) {
276 t.Errorf("test %d: %s(%T(%v)) = %v (%T); want %v (%T)", 277 t.Errorf("test %d: %s(%T(%v)) = %v (%T); want %v (%T)",
277 i, tt.c, tt.in, tt.in, out, out, tt.out, tt.out) 278 i, tt.c, tt.in, tt.in, out, out, tt.out, tt.out)
278 } 279 }
279 } 280 }
280 } 281 }
OLDNEW
« no previous file with comments | « src/pkg/database/sql/convert.go ('k') | src/pkg/database/sql/sql.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b