wp-go/helper/strings/strings_test.go

56 lines
1001 B
Go
Raw Normal View History

2023-01-21 11:31:23 +00:00
package strings
2023-01-13 04:31:35 +00:00
import (
"golang.org/x/exp/constraints"
"testing"
)
2023-01-13 04:31:35 +00:00
func TestStrJoin(t *testing.T) {
type args struct {
s []string
}
tests := []struct {
name string
args args
wantStr string
}{
{name: "t1", args: args{s: []string{"a", "b", "c"}}, wantStr: "abc"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
2023-01-21 11:31:23 +00:00
if gotStr := Join(tt.args.s...); gotStr != tt.wantStr {
t.Errorf("Join() = %v, want %v", gotStr, tt.wantStr)
2023-01-13 04:31:35 +00:00
}
})
}
}
func TestToInteger(t *testing.T) {
type args[T constraints.Integer] struct {
s string
z T
}
type testCase[T constraints.Integer] struct {
name string
args args[T]
want T
}
tests := []testCase[int64]{
{
name: "t1",
args: args[int64]{
"10",
0,
},
want: int64(10),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := ToInteger[int64](tt.args.s, tt.args.z); got != tt.want {
t.Errorf("StrToInt() = %v, want %v", got, tt.want)
}
})
}
}