0
0
mirror of https://github.com/thegeeklab/wp-plugin-go.git synced 2024-11-25 09:30:39 +00:00
wp-plugin-go/types/stringslice_test.go

31 lines
773 B
Go
Raw Normal View History

package types
import (
"testing"
2024-03-11 08:23:17 +00:00
"github.com/stretchr/testify/assert"
)
func TestSplitWithEscaping(t *testing.T) {
tests := []struct {
name string
2024-03-11 08:23:17 +00:00
input string
output []string
}{
{name: "empty string", input: "", output: []string{}},
{name: "simple comma separated", input: "a,b", output: []string{"a", "b"}},
{name: "multiple commas", input: ",,,", output: []string{"", "", "", ""}},
{name: "escaped comma", input: ",a\\,", output: []string{"", "a,"}},
{name: "escaped backslash", input: "a,b\\,c\\\\d,e", output: []string{"a", "b,c\\\\d", "e"}},
}
2024-03-11 08:23:17 +00:00
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
strings := splitWithEscaping(tt.input, ",", "\\")
got, want := strings, tt.output
assert.Equal(t, got, want)
})
}
}