...
 
Commits (2)
......@@ -208,10 +208,13 @@ func SplitTxt(value string) []string {
value = value[1 : len(value)-1]
}
r := []string{"("}
for len(value) > 0 {
for len(value) > MAX_TXT {
r = append(r, "\""+value[:MAX_TXT]+"\"")
value = value[MAX_TXT:]
}
if len(value) > 0 {
r = append(r, "\""+value+"\"")
}
r = append(r, ")")
return r
}
......
package main
import (
"reflect"
"strings"
"testing"
)
func TestSplitTxtEmpty(t *testing.T) {
src := ""
expected := []string{"\"\""}
r := SplitTxt(src)
if !reflect.DeepEqual(r, expected) {
t.Error("Expected", expected, "got", r)
}
}
func TestSplitTxtEmptyQuoted(t *testing.T) {
src := "\"\""
expected := []string{"\"\""}
r := SplitTxt(src)
if !reflect.DeepEqual(r, expected) {
t.Error("Expected", expected, "got", r)
}
}
func TestSplitTxtSingle(t *testing.T) {
src := "Lorem ipsum"
expected := []string{"\"Lorem ipsum\""}
r := SplitTxt(src)
if !reflect.DeepEqual(r, expected) {
t.Error("Expected", expected, "got", r)
}
}
func TestSplitTxtSingleQuoted(t *testing.T) {
src := "\"Lorem ipsum\""
expected := []string{"\"Lorem ipsum\""}
r := SplitTxt(src)
if !reflect.DeepEqual(r, expected) {
t.Error("Expected", expected, "got", r)
}
}
func TestSplitTxtMulti(t *testing.T) {
src := strings.Repeat("a", 130)
expected := []string{"(", "\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"", "\"aa\"", ")"}
r := SplitTxt(src)
if !reflect.DeepEqual(r, expected) {
t.Error("Expected", expected, "got", r)
}
}
func TestSplitTxtMultiQuoted(t *testing.T) {
src := "\"" + strings.Repeat("a", 260) + "\""
expected := []string{
"(",
"\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"", "\"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\"",
"\"aaaa\"",
")",
}
r := SplitTxt(src)
if !reflect.DeepEqual(r, expected) {
t.Error("Expected", expected, "got", r)
}
}