You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
fx/search_test.go

43 lines
885 B
Go

package main
import (
"fmt"
"reflect"
"regexp"
"testing"
)
func Test_splitByFoundIndexes(t *testing.T) {
s := fmt.Sprintf("%q", "0 aaa 123 \"bbb 44\" ccc 5")
re := regexp.MustCompile("\"?\\d+\"?")
indexes := re.FindAllStringIndex(s, -1)
chunks := explode(s, indexes)
expected := []string{"", "\"0", " aaa ", "123", " \\\"bbb ", "44", "\\\" ccc ", "5\"", ""}
ok := reflect.DeepEqual(chunks, expected)
if !ok {
t.Errorf(
"split error:\n"+
" got %v,\n"+
" expected %v",
stringify(chunks),
stringify(expected),
)
}
}
func Test_splitByFoundIndexes_empty(t *testing.T) {
s := fmt.Sprintf("%q", "foo")
chunks := explode(s, nil)
expected := []string{"\"foo\""}
ok := reflect.DeepEqual(chunks, expected)
if !ok {
t.Errorf(
"split error:\n"+
" got %v,\n"+
" expected %v",
stringify(chunks),
stringify(expected),
)
}
}