Add helpers for float pointers. (#1559)

This commit is contained in:
Markus Thömmes 2020-07-27 10:13:59 +02:00 committed by GitHub
parent 9c17340fef
commit 9a051b3dec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 2 deletions

View File

@ -30,6 +30,18 @@ func Int64(i int64) *int64 {
return &i
}
// Float32 is a helper for turning floats into pointers for use in
// API types that want *float32.
func Float32(f float32) *float32 {
return &f
}
// Float64 is a helper for turning floats into pointers for use in
// API types that want *float64.
func Float64(f float64) *float64 {
return &f
}
// Bool is a helper for turning bools into pointers for use in
// API types that want *bool.
func Bool(b bool) *bool {

View File

@ -21,9 +21,8 @@ import (
"time"
)
const want = 55
func TestInt32(t *testing.T) {
const want = 55
gotPtr := Int32(want)
if want != *gotPtr {
t.Errorf("Int32() = &%v, wanted %v", *gotPtr, want)
@ -31,12 +30,29 @@ func TestInt32(t *testing.T) {
}
func TestInt64(t *testing.T) {
const want = 55
gotPtr := Int64(want)
if want != *gotPtr {
t.Errorf("Int64() = &%v, wanted %v", *gotPtr, want)
}
}
func TestFloat32(t *testing.T) {
const want = 1.25
gotPtr := Float32(want)
if want != *gotPtr {
t.Errorf("Float32() = &%v, wanted %v", *gotPtr, want)
}
}
func TestFloat64(t *testing.T) {
const want = 1.25
gotPtr := Float64(want)
if want != *gotPtr {
t.Errorf("Float64() = &%v, wanted %v", *gotPtr, want)
}
}
func TestBool(t *testing.T) {
const want = true
gotPtr := Bool(want)