Skip to content

Commit

Permalink
test: adding test for cast
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie authored Jul 30, 2024
1 parent cf3447e commit 16b3da9
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions cast/ptr_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package cast_test

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/zeiss/pkg/cast"
)

func TestPtr(t *testing.T) {
t.Parallel()

tests := []struct {
name string
v any
}{
{"success", 1},
{"success", "hello"},
{"success", struct{}{}},
{"success", []int{1, 2, 3}},
{"success", map[string]int{"a": 1, "b": 2}},
}

for _, tt := range tests {
tt := tt

t.Run(tt.name, func(t *testing.T) {
t.Parallel()

p := &tt.v
got := cast.Ptr(tt.v)
assert.Equal(t, p, got)
})
}
}

func TestValue(t *testing.T) {
t.Parallel()

tests := []struct {
name string
v any
}{
{"success", 1},
{"success", "hello"},
{"success", struct{}{}},
{"success", []int{1, 2, 3}},
{"success", map[string]int{"a": 1, "b": 2}},
}

for _, tt := range tests {
tt := tt

t.Run(tt.name, func(t *testing.T) {
t.Parallel()

got := cast.Value(&tt.v)
assert.Equal(t, tt.v, got)
})
}
}

0 comments on commit 16b3da9

Please sign in to comment.