2023-08-19 13:25:53 +00:00
|
|
|
package types
|
2022-10-31 14:37:50 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSplitWithEscaping(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
Input string
|
|
|
|
Output []string
|
|
|
|
}{
|
|
|
|
{"", []string{}},
|
|
|
|
{"a,b", []string{"a", "b"}},
|
|
|
|
{",,,", []string{"", "", "", ""}},
|
|
|
|
{",a\\,", []string{"", "a,"}},
|
|
|
|
{"a,b\\,c\\\\d,e", []string{"a", "b,c\\\\d", "e"}},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
strings := splitWithEscaping(test.Input, ",", "\\")
|
|
|
|
got, want := strings, test.Output
|
2023-02-08 09:16:01 +00:00
|
|
|
|
2022-10-31 14:37:50 +00:00
|
|
|
if !reflect.DeepEqual(got, want) {
|
|
|
|
t.Errorf("Got tag %v, want %v", got, want)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|