mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-18 14:39:49 +02:00
small string split join optimization
This commit is contained in:
38
internal/utils/strutils/split_join_test.go
Normal file
38
internal/utils/strutils/split_join_test.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package strutils_test
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
. "github.com/yusing/go-proxy/internal/utils/strutils"
|
||||
. "github.com/yusing/go-proxy/internal/utils/testing"
|
||||
)
|
||||
|
||||
var alphaNumeric = func() string {
|
||||
var s strings.Builder
|
||||
for i := range 'z' - 'a' + 1 {
|
||||
s.WriteRune('a' + i)
|
||||
s.WriteRune('A' + i)
|
||||
s.WriteRune(',')
|
||||
}
|
||||
for i := range '9' - '0' + 1 {
|
||||
s.WriteRune('0' + i)
|
||||
s.WriteRune(',')
|
||||
}
|
||||
return s.String()
|
||||
}()
|
||||
|
||||
func TestSplit(t *testing.T) {
|
||||
tests := map[string]rune{
|
||||
"": 0,
|
||||
"1": '1',
|
||||
",": ',',
|
||||
}
|
||||
for sep, rsep := range tests {
|
||||
t.Run(sep, func(t *testing.T) {
|
||||
expected := strings.Split(alphaNumeric, sep)
|
||||
ExpectDeepEqual(t, SplitRune(alphaNumeric, rsep), expected)
|
||||
ExpectEqual(t, JoinRune(expected, rsep), alphaNumeric)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user