-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil_internal_test.go
73 lines (67 loc) · 1.35 KB
/
util_internal_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package hal
import (
"testing"
)
func TestGetStringOrStringSlice(t *testing.T) {
t.Parallel()
tests := []struct {
name string
input any
expected []string
}{
{
name: "nil input",
input: nil,
expected: []string{},
},
{
name: "string input",
input: "test",
expected: []string{"test"},
},
{
name: "string slice input",
input: []string{"test"},
expected: []string{"test"},
},
{
name: "empty string input",
input: "",
expected: []string{""},
},
{
name: "slice of strings",
input: []any{"test1", "test2", "test3"},
expected: []string{"test1", "test2", "test3"},
},
{
name: "empty slice",
input: []any{},
expected: []string{},
},
{
name: "slice with non-string values",
input: []any{1, "test", true},
expected: []string{"test"},
},
{
name: "unsupported type",
input: 123,
expected: []string{},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
result := getStringOrStringSlice(tt.input)
if len(result) != len(tt.expected) {
t.Errorf("got len %d, want len %d", len(result), len(tt.expected))
}
for i := range result {
if result[i] != tt.expected[i] {
t.Errorf("got %s, want %s at index %d", result[i], tt.expected[i], i)
}
}
})
}
}