1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
|
package to
import (
"reflect"
"testing"
)
func TestString(t *testing.T) {
v := ""
if String(&v) != v {
t.Errorf("to: String failed to return the correct string -- expected %v, received %v",
v, String(&v))
}
}
func TestStringHandlesNil(t *testing.T) {
if String(nil) != "" {
t.Errorf("to: String failed to correctly convert nil -- expected %v, received %v",
"", String(nil))
}
}
func TestStringPtr(t *testing.T) {
v := ""
if *StringPtr(v) != v {
t.Errorf("to: StringPtr failed to return the correct string -- expected %v, received %v",
v, *StringPtr(v))
}
}
func TestStringSlice(t *testing.T) {
v := []string{}
if out := StringSlice(&v); !reflect.DeepEqual(out, v) {
t.Errorf("to: StringSlice failed to return the correct slice -- expected %v, received %v",
v, out)
}
}
func TestStringSliceHandlesNil(t *testing.T) {
if out := StringSlice(nil); out != nil {
t.Errorf("to: StringSlice failed to correctly convert nil -- expected %v, received %v",
nil, out)
}
}
func TestStringSlicePtr(t *testing.T) {
v := []string{"a", "b"}
if out := StringSlicePtr(v); !reflect.DeepEqual(*out, v) {
t.Errorf("to: StringSlicePtr failed to return the correct slice -- expected %v, received %v",
v, *out)
}
}
func TestStringMap(t *testing.T) {
msp := map[string]*string{"foo": StringPtr("foo"), "bar": StringPtr("bar"), "baz": StringPtr("baz")}
for k, v := range StringMap(msp) {
if *msp[k] != v {
t.Errorf("to: StringMap incorrectly converted an entry -- expected [%s]%v, received[%s]%v",
k, v, k, *msp[k])
}
}
}
func TestStringMapHandlesNil(t *testing.T) {
msp := map[string]*string{"foo": StringPtr("foo"), "bar": nil, "baz": StringPtr("baz")}
for k, v := range StringMap(msp) {
if msp[k] == nil && v != "" {
t.Errorf("to: StringMap incorrectly converted a nil entry -- expected [%s]%v, received[%s]%v",
k, v, k, *msp[k])
}
}
}
func TestStringMapPtr(t *testing.T) {
ms := map[string]string{"foo": "foo", "bar": "bar", "baz": "baz"}
for k, msp := range *StringMapPtr(ms) {
if ms[k] != *msp {
t.Errorf("to: StringMapPtr incorrectly converted an entry -- expected [%s]%v, received[%s]%v",
k, ms[k], k, *msp)
}
}
}
func TestBool(t *testing.T) {
v := false
if Bool(&v) != v {
t.Errorf("to: Bool failed to return the correct string -- expected %v, received %v",
v, Bool(&v))
}
}
func TestBoolHandlesNil(t *testing.T) {
if Bool(nil) != false {
t.Errorf("to: Bool failed to correctly convert nil -- expected %v, received %v",
false, Bool(nil))
}
}
func TestBoolPtr(t *testing.T) {
v := false
if *BoolPtr(v) != v {
t.Errorf("to: BoolPtr failed to return the correct string -- expected %v, received %v",
v, *BoolPtr(v))
}
}
func TestInt(t *testing.T) {
v := 0
if Int(&v) != v {
t.Errorf("to: Int failed to return the correct string -- expected %v, received %v",
v, Int(&v))
}
}
func TestIntHandlesNil(t *testing.T) {
if Int(nil) != 0 {
t.Errorf("to: Int failed to correctly convert nil -- expected %v, received %v",
0, Int(nil))
}
}
func TestIntPtr(t *testing.T) {
v := 0
if *IntPtr(v) != v {
t.Errorf("to: IntPtr failed to return the correct string -- expected %v, received %v",
v, *IntPtr(v))
}
}
func TestInt32(t *testing.T) {
v := int32(0)
if Int32(&v) != v {
t.Errorf("to: Int32 failed to return the correct string -- expected %v, received %v",
v, Int32(&v))
}
}
func TestInt32HandlesNil(t *testing.T) {
if Int32(nil) != int32(0) {
t.Errorf("to: Int32 failed to correctly convert nil -- expected %v, received %v",
0, Int32(nil))
}
}
func TestInt32Ptr(t *testing.T) {
v := int32(0)
if *Int32Ptr(v) != v {
t.Errorf("to: Int32Ptr failed to return the correct string -- expected %v, received %v",
v, *Int32Ptr(v))
}
}
func TestInt64(t *testing.T) {
v := int64(0)
if Int64(&v) != v {
t.Errorf("to: Int64 failed to return the correct string -- expected %v, received %v",
v, Int64(&v))
}
}
func TestInt64HandlesNil(t *testing.T) {
if Int64(nil) != int64(0) {
t.Errorf("to: Int64 failed to correctly convert nil -- expected %v, received %v",
0, Int64(nil))
}
}
func TestInt64Ptr(t *testing.T) {
v := int64(0)
if *Int64Ptr(v) != v {
t.Errorf("to: Int64Ptr failed to return the correct string -- expected %v, received %v",
v, *Int64Ptr(v))
}
}
func TestFloat32(t *testing.T) {
v := float32(0)
if Float32(&v) != v {
t.Errorf("to: Float32 failed to return the correct string -- expected %v, received %v",
v, Float32(&v))
}
}
func TestFloat32HandlesNil(t *testing.T) {
if Float32(nil) != float32(0) {
t.Errorf("to: Float32 failed to correctly convert nil -- expected %v, received %v",
0, Float32(nil))
}
}
func TestFloat32Ptr(t *testing.T) {
v := float32(0)
if *Float32Ptr(v) != v {
t.Errorf("to: Float32Ptr failed to return the correct string -- expected %v, received %v",
v, *Float32Ptr(v))
}
}
func TestFloat64(t *testing.T) {
v := float64(0)
if Float64(&v) != v {
t.Errorf("to: Float64 failed to return the correct string -- expected %v, received %v",
v, Float64(&v))
}
}
func TestFloat64HandlesNil(t *testing.T) {
if Float64(nil) != float64(0) {
t.Errorf("to: Float64 failed to correctly convert nil -- expected %v, received %v",
0, Float64(nil))
}
}
func TestFloat64Ptr(t *testing.T) {
v := float64(0)
if *Float64Ptr(v) != v {
t.Errorf("to: Float64Ptr failed to return the correct string -- expected %v, received %v",
v, *Float64Ptr(v))
}
}
|