1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
13 type valueConverterTest
struct {
23 var valueConverterTests
= []valueConverterTest
{
24 {Bool
, "true", true, ""},
25 {Bool
, "True", true, ""},
26 {Bool
, []byte("t"), true, ""},
27 {Bool
, true, true, ""},
28 {Bool
, "1", true, ""},
30 {Bool
, int64(1), true, ""},
31 {Bool
, uint16(1), true, ""},
32 {Bool
, "false", false, ""},
33 {Bool
, false, false, ""},
34 {Bool
, "0", false, ""},
36 {Bool
, int64(0), false, ""},
37 {Bool
, uint16(0), false, ""},
38 {c
: Bool
, in
: "foo", err
: "sql/driver: couldn't convert \"foo\" into type bool"},
39 {c
: Bool
, in
: 2, err
: "sql/driver: couldn't convert 2 into type bool"},
40 {DefaultParameterConverter
, now
, now
, ""},
41 {DefaultParameterConverter
, (*int64)(nil), nil, ""},
42 {DefaultParameterConverter
, &answer
, answer
, ""},
43 {DefaultParameterConverter
, &now
, now
, ""},
46 func TestValueConverters(t
*testing
.T
) {
47 for i
, tt
:= range valueConverterTests
{
48 out
, err
:= tt
.c
.ConvertValue(tt
.in
)
54 t
.Errorf("test %d: %T(%T(%v)) error = %q; want error = %q",
55 i
, tt
.c
, tt
.in
, tt
.in
, goterr
, tt
.err
)
60 if !reflect
.DeepEqual(out
, tt
.out
) {
61 t
.Errorf("test %d: %T(%T(%v)) = %v (%T); want %v (%T)",
62 i
, tt
.c
, tt
.in
, tt
.in
, out
, out
, tt
.out
, tt
.out
)