0
0
mirror of https://github.com/thegeeklab/wp-plugin-go.git synced 2024-09-21 18:22:45 +02:00
wp-plugin-go/types/stringslice_test.go

28 lines
582 B
Go
Raw Normal View History

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