OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [database/] [sql/] [driver/] [types_test.go] - Blame information for rev 747

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// 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.
4
 
5
package driver
6
 
7
import (
8
        "reflect"
9
        "testing"
10
        "time"
11
)
12
 
13
type valueConverterTest struct {
14
        c   ValueConverter
15
        in  interface{}
16
        out interface{}
17
        err string
18
}
19
 
20
var now = time.Now()
21
 
22
var valueConverterTests = []valueConverterTest{
23
        {Bool, "true", true, ""},
24
        {Bool, "True", true, ""},
25
        {Bool, []byte("t"), true, ""},
26
        {Bool, true, true, ""},
27
        {Bool, "1", true, ""},
28
        {Bool, 1, true, ""},
29
        {Bool, int64(1), true, ""},
30
        {Bool, uint16(1), true, ""},
31
        {Bool, "false", false, ""},
32
        {Bool, false, false, ""},
33
        {Bool, "0", false, ""},
34
        {Bool, 0, false, ""},
35
        {Bool, int64(0), false, ""},
36
        {Bool, uint16(0), false, ""},
37
        {c: Bool, in: "foo", err: "sql/driver: couldn't convert \"foo\" into type bool"},
38
        {c: Bool, in: 2, err: "sql/driver: couldn't convert 2 into type bool"},
39
        {DefaultParameterConverter, now, now, ""},
40
}
41
 
42
func TestValueConverters(t *testing.T) {
43
        for i, tt := range valueConverterTests {
44
                out, err := tt.c.ConvertValue(tt.in)
45
                goterr := ""
46
                if err != nil {
47
                        goterr = err.Error()
48
                }
49
                if goterr != tt.err {
50
                        t.Errorf("test %d: %s(%T(%v)) error = %q; want error = %q",
51
                                i, tt.c, tt.in, tt.in, goterr, tt.err)
52
                }
53
                if tt.err != "" {
54
                        continue
55
                }
56
                if !reflect.DeepEqual(out, tt.out) {
57
                        t.Errorf("test %d: %s(%T(%v)) = %v (%T); want %v (%T)",
58
                                i, tt.c, tt.in, tt.in, out, out, tt.out, tt.out)
59
                }
60
        }
61
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.