Skip to content

Commit

Permalink
refactor: rename functions in pointer package (#25)
Browse files Browse the repository at this point in the history
This PR changes the function names in the pointer package so they sound
better when called.
  • Loading branch information
loozhengyuan authored Mar 3, 2021
1 parent 909ac5b commit 4265633
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ All notable changes to this project will be documented in this file.
### Changed

* Disallow checks from returning errors ([#21](https://github.com/loozhengyuan/grench/pull/21))
* Rename functions in pointer package ([#25](https://github.com/loozhengyuan/grench/pull/25))

<!-- END Unreleased -->

Expand Down
28 changes: 14 additions & 14 deletions pkg/pointer/pointer.go
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
// Package pointer provides pointer helper functions.
package pointer

// IntPtr returns the pointer of the int input.
func IntPtr(i int) *int {
// Int returns the pointer of the int input.
func Int(i int) *int {
return &i
}

// Int32Ptr returns the pointer of the int32 input.
func Int32Ptr(i int32) *int32 {
// Int32 returns the pointer of the int32 input.
func Int32(i int32) *int32 {
return &i
}

// Int64Ptr returns the pointer of the int64 input.
func Int64Ptr(i int64) *int64 {
// Int64 returns the pointer of the int64 input.
func Int64(i int64) *int64 {
return &i
}

// Float32Ptr returns the pointer of the float32 input.
func Float32Ptr(f float32) *float32 {
// Float32 returns the pointer of the float32 input.
func Float32(f float32) *float32 {
return &f
}

// Float64Ptr returns the pointer of the float64 input.
func Float64Ptr(f float64) *float64 {
// Float64 returns the pointer of the float64 input.
func Float64(f float64) *float64 {
return &f
}

// BoolPtr returns the pointer of the bool input.
func BoolPtr(b bool) *bool {
// Bool returns the pointer of the bool input.
func Bool(b bool) *bool {
return &b
}

// StringPtr returns the pointer of the string input.
func StringPtr(s string) *string {
// String returns the pointer of the string input.
func String(s string) *string {
return &s
}
28 changes: 14 additions & 14 deletions pkg/pointer/pointer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"testing"
)

func TestIntPtr(t *testing.T) {
func TestInt(t *testing.T) {
cases := map[string]struct {
input int
}{
Expand All @@ -15,15 +15,15 @@ func TestIntPtr(t *testing.T) {
tc := tc // capture range variable
t.Run(name, func(t *testing.T) {
t.Parallel()
got := *IntPtr(tc.input) // deference from output
got := *Int(tc.input) // deference from output
if got != tc.input {
t.Errorf("value mismatch:\ngot:\t%#v\nwant:\t%#v", got, tc.input)
}
})
}
}

func TestInt32Ptr(t *testing.T) {
func TestInt32(t *testing.T) {
cases := map[string]struct {
input int32
}{
Expand All @@ -34,15 +34,15 @@ func TestInt32Ptr(t *testing.T) {
tc := tc // capture range variable
t.Run(name, func(t *testing.T) {
t.Parallel()
got := *Int32Ptr(tc.input) // deference from output
got := *Int32(tc.input) // deference from output
if got != tc.input {
t.Errorf("value mismatch:\ngot:\t%#v\nwant:\t%#v", got, tc.input)
}
})
}
}

func TestInt64Ptr(t *testing.T) {
func TestInt64(t *testing.T) {
cases := map[string]struct {
input int64
}{
Expand All @@ -53,15 +53,15 @@ func TestInt64Ptr(t *testing.T) {
tc := tc // capture range variable
t.Run(name, func(t *testing.T) {
t.Parallel()
got := *Int64Ptr(tc.input) // deference from output
got := *Int64(tc.input) // deference from output
if got != tc.input {
t.Errorf("value mismatch:\ngot:\t%#v\nwant:\t%#v", got, tc.input)
}
})
}
}

func TestFloat32Ptr(t *testing.T) {
func TestFloat32(t *testing.T) {
cases := map[string]struct {
input float32
}{
Expand All @@ -72,15 +72,15 @@ func TestFloat32Ptr(t *testing.T) {
tc := tc // capture range variable
t.Run(name, func(t *testing.T) {
t.Parallel()
got := *Float32Ptr(tc.input) // deference from output
got := *Float32(tc.input) // deference from output
if got != tc.input {
t.Errorf("value mismatch:\ngot:\t%#v\nwant:\t%#v", got, tc.input)
}
})
}
}

func TestFloat64Ptr(t *testing.T) {
func TestFloat64(t *testing.T) {
cases := map[string]struct {
input float64
}{
Expand All @@ -91,15 +91,15 @@ func TestFloat64Ptr(t *testing.T) {
tc := tc // capture range variable
t.Run(name, func(t *testing.T) {
t.Parallel()
got := *Float64Ptr(tc.input) // deference from output
got := *Float64(tc.input) // deference from output
if got != tc.input {
t.Errorf("value mismatch:\ngot:\t%#v\nwant:\t%#v", got, tc.input)
}
})
}
}

func TestBoolPtr(t *testing.T) {
func TestBool(t *testing.T) {
cases := map[string]struct {
input bool
}{
Expand All @@ -110,15 +110,15 @@ func TestBoolPtr(t *testing.T) {
tc := tc // capture range variable
t.Run(name, func(t *testing.T) {
t.Parallel()
got := *BoolPtr(tc.input) // deference from output
got := *Bool(tc.input) // deference from output
if got != tc.input {
t.Errorf("value mismatch:\ngot:\t%#v\nwant:\t%#v", got, tc.input)
}
})
}
}

func TestStringPtr(t *testing.T) {
func TestString(t *testing.T) {
cases := map[string]struct {
input string
}{
Expand All @@ -129,7 +129,7 @@ func TestStringPtr(t *testing.T) {
tc := tc // capture range variable
t.Run(name, func(t *testing.T) {
t.Parallel()
got := *StringPtr(tc.input) // deference from output
got := *String(tc.input) // deference from output
if got != tc.input {
t.Errorf("value mismatch:\ngot:\t%#v\nwant:\t%#v", got, tc.input)
}
Expand Down

0 comments on commit 4265633

Please sign in to comment.