1 // Go MySQL Driver - A MySQL-Driver for Go's database/sql package
3 // Copyright 2017 The Go-MySQL-Driver Authors. All rights reserved.
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this file,
7 // You can obtain one at http://mozilla.org/MPL/2.0/.
16 func TestConvertDerivedString(t *testing.T) {
19 output, err := converter{}.ConvertValue(derived("value"))
21 t.Fatal("Derived string type not convertible", err)
24 if output != "value" {
25 t.Fatalf("Derived string type not converted, got %#v %T", output, output)
29 func TestConvertDerivedByteSlice(t *testing.T) {
32 output, err := converter{}.ConvertValue(derived("value"))
34 t.Fatal("Byte slice not convertible", err)
37 if bytes.Compare(output.([]byte), []byte("value")) != 0 {
38 t.Fatalf("Byte slice not converted, got %#v %T", output, output)
42 func TestConvertDerivedUnsupportedSlice(t *testing.T) {
45 _, err := converter{}.ConvertValue(derived{1})
46 if err == nil || err.Error() != "unsupported type mysql.derived, a slice of int" {
47 t.Fatal("Unexpected error", err)
51 func TestConvertDerivedBool(t *testing.T) {
54 output, err := converter{}.ConvertValue(derived(true))
56 t.Fatal("Derived bool type not convertible", err)
60 t.Fatalf("Derived bool type not converted, got %#v %T", output, output)
64 func TestConvertPointer(t *testing.T) {
67 output, err := converter{}.ConvertValue(&str)
69 t.Fatal("Pointer type not convertible", err)
72 if output != "value" {
73 t.Fatalf("Pointer type not converted, got %#v %T", output, output)
77 func TestConvertSignedIntegers(t *testing.T) {
78 values := []interface{}{
86 for _, value := range values {
87 output, err := converter{}.ConvertValue(value)
89 t.Fatalf("%T type not convertible %s", value, err)
92 if output != int64(-42) {
93 t.Fatalf("%T type not converted, got %#v %T", value, output, output)
98 func TestConvertUnsignedIntegers(t *testing.T) {
99 values := []interface{}{
107 for _, value := range values {
108 output, err := converter{}.ConvertValue(value)
110 t.Fatalf("%T type not convertible %s", value, err)
113 if output != int64(42) {
114 t.Fatalf("%T type not converted, got %#v %T", value, output, output)
118 output, err := converter{}.ConvertValue(^uint64(0))
120 t.Fatal("uint64 high-bit not convertible", err)
123 if output != "18446744073709551615" {
124 t.Fatalf("uint64 high-bit not converted, got %#v %T", output, output)