-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjoin_test.go
More file actions
107 lines (100 loc) · 2.22 KB
/
join_test.go
File metadata and controls
107 lines (100 loc) · 2.22 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package fmt_test
import (
"testing"
. "github.com/tinywasm/fmt"
)
func TestJoinMethod(t *testing.T) {
tests := []struct {
name string
input []string
sep string
expected string
}{
{
name: "Join with default space separator",
input: []string{"Hello", "World"},
sep: "",
expected: "Hello World",
},
{
name: "Join with custom separator",
input: []string{"hello", "world", "example"},
sep: "-",
expected: "hello-world-example",
},
{
name: "Join with semicolon separator",
input: []string{"apple", "orange", "banana"},
sep: ";",
expected: "apple;orange;banana",
},
{
name: "Empty slice",
input: []string{},
sep: ",",
expected: "",
},
{
name: "Single element",
input: []string{"test"},
sep: ":",
expected: "test",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var out string
if tt.sep == "" {
out = Convert(tt.input).Join().String()
} else {
out = Convert(tt.input).Join(tt.sep).String()
}
if out != tt.expected {
t.Errorf("Join test %q: expected %q, got %q",
tt.name, tt.expected, out)
}
})
}
}
func TestJoinChainMethods(t *testing.T) {
tests := []struct {
name string
input []string
function func([]string) string
expected string
}{
{
name: "Join with ToUpper",
input: []string{"hello", "world"},
expected: "HELLO WORLD",
function: func(input []string) string {
return Convert(input).Join().ToUpper().String()
},
},
{
name: "Join with custom separator and ToLower",
input: []string{"HELLO", "WORLD"},
expected: "hello-world",
function: func(input []string) string {
return Convert(input).Join("-").ToLower().String()
},
},
{
name: "Join with Capitalize",
input: []string{"hello", "world"},
expected: "Hello World",
function: func(input []string) string {
return Convert(input).Join().Capitalize().String()
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
out := tt.function(tt.input)
if out != tt.expected {
t.Errorf("Chain test %q: expected %q, got %q",
tt.name, tt.expected, out)
}
})
}
}