Skip to content

Commit

Permalink
add missing types to pointers package (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
charless-splunk authored Apr 8, 2019
1 parent 01b8a11 commit 68565cf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pointer/pointer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ func Uint32(i uint32) *uint32 {
return &i
}

// Uint64 returns a pointer to a uint64
func Uint64(i uint64) *uint64 {
return &i
}

// String returns a pointer to a string
func String(i string) *string {
return &i
Expand All @@ -51,6 +56,11 @@ func Bool(b bool) *bool {
return &b
}

// Float32 returns a pointer to a float32
func Float32(f float32) *float32 {
return &f
}

// Float64 returns a pointer to a float64
func Float64(b float64) *float64 {
return &b
Expand Down
6 changes: 6 additions & 0 deletions pointer/pointer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ type Person struct {
Uint32 *uint32
Uint *uint
Uint16 *uint16
Uint64 *uint64

Int *int
Int64 *int64
Bool *bool
Float32 *float32
Float64 *float64
}

Expand Down Expand Up @@ -62,9 +64,11 @@ func TestFillDefaultFrom(t *testing.T) {
Uint32: Uint32(1),
Uint: Uint(2),
Uint16: Uint16(3),
Uint64: Uint64(4),
Int: Int(5),
Int64: Int64(6),
Bool: Bool(true),
Float32: Float32(5.0),
Float64: Float64(4.0),
Coworkers: []Person{
{
Expand All @@ -82,11 +86,13 @@ func TestFillDefaultFrom(t *testing.T) {
So(*p.Uint32, ShouldEqual, 1)
So(*p.Uint, ShouldEqual, 2)
So(*p.Uint16, ShouldEqual, 3)
So(*p.Uint64, ShouldEqual, 4)
So(*p.Int, ShouldEqual, 5)
So(*p.Int64, ShouldEqual, 6)
So(p.Job.Pay(), ShouldEqual, 100)
So(len(p.Coworkers), ShouldEqual, 1)
So(*p.Bool, ShouldBeTrue)
So(*p.Float32, ShouldEqual, 5.0)
So(*p.Float64, ShouldEqual, 4.0)
So(*p.Coworkers[0].Name, ShouldEqual, "jack")
So(p.Tk, ShouldHaveSameTypeAs, timekeeper.RealTime{})
Expand Down

0 comments on commit 68565cf

Please sign in to comment.