Skip to content

Commit

Permalink
adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mzack9999 committed May 6, 2023
1 parent 852aa89 commit a10ba05
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
File renamed without changes.
36 changes: 36 additions & 0 deletions ptr/ptr_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package ptr

import (
"github.com/stretchr/testify/require"
"testing"
)

func TestSafe(t *testing.T) {
type args[T any] struct {
v *T
}
type testCase[T any] struct {
name string
args args[T]
want T
}
tests := []testCase[int]{
{
name: "struct=>int - NilPointer",
args: args[int]{v: nil},
want: 0,
},
{
name: "struct=>int - NonNilPointer",
args: args[int]{v: new(int)},
want: 0,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := Safe(tt.args.v)
require.Equal(t, tt.want, got, "Safe() = %v, want %v", got, tt.want)
})
}
}

0 comments on commit a10ba05

Please sign in to comment.