Feature/cover unit test (#81)

This commit is contained in:
libin
2024-07-31 19:51:01 +08:00
committed by GitHub
parent 0990bbce4d
commit a59af60d9a
60 changed files with 2571 additions and 2606 deletions

View File

@@ -1,24 +1,50 @@
package sliceUtil
import "testing"
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestIsSlice(t *testing.T) {
var tests = []struct {
testCases := []struct {
name string
input any
want bool
}{
{[]int{1, 1, 3}, true},
{[]any{1, 2, "a"}, true},
{[]map[string]any{
{"1": 1},
{"c": 89},
}, true},
{"1234", false},
{make(chan int), false},
{
name: "slice of int",
input: []int{1, 1, 3},
want: true,
},
{
name: "slice of any",
input: []any{1, 2, "a"},
want: true,
},
{
name: "slice of map",
input: []map[string]any{
{"1": 1},
{"c": 89},
},
want: true,
},
{
name: "string",
input: "1234",
want: false,
},
{
name: "channel",
input: make(chan int),
want: false,
},
}
for _, test := range tests {
if got := IsSlice(test.input); got != test.want {
t.Errorf("IsSlice(%v) = %v; want %v", test.input, got, test.want)
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
got := IsSlice(tc.input)
assert.Equal(t, tc.want, got)
})
}
}