given the following function:
func convertValue(contents string) (int, error) {
return strconv.Atoi(contents)
}
when I run the following test
var convertValues = []struct {
contents string
value int
}{
{"9223372036854775807", math.MaxInt64},
{"−9223372036854775808", math.MinInt64},
}
func TestConvertValue(t *testing.T) {
for _, values := range convertValues {
value, err := convertValue(values.contents)
if err != nil {
t.Error("Expecting", values.value, "but got error", err.Error())
}
if value != values.value {
t.Error("Expecting ", values.value, ", but got ", value)
}
}
}
it works for MaxInt64, but not for MinInt64. I'm running this on a MacBookPro, so it's running in 64bit. I have double checked this with the following
func TestIntSize(t *testing.T) {
const PtrSize = 32 << uintptr(^uintptr(0)>>63)
fmt.Println(runtime.GOOS, runtime.GOARCH)
fmt.Println(strconv.IntSize, PtrSize)
}
and it returned
darwin amd64
64 64
What am I doing wrong?