diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2016-08-14 04:23:37 +0900 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2016-08-14 04:30:55 +0900 |
commit | d9c8a9a880dd9fc28c9fb466bd1c81cd6a8a159c (patch) | |
tree | 98a2018200734947aa6fa40552f3ccc7463404a2 /src/util/chars_test.go | |
parent | ddc7bb9064042a0d5da9546eaf6ff888dca63f0c (diff) |
[perf] Remove memory copy when using string delimiter
Diffstat (limited to 'src/util/chars_test.go')
-rw-r--r-- | src/util/chars_test.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/util/chars_test.go b/src/util/chars_test.go index 2cb6fc76..12c629d5 100644 --- a/src/util/chars_test.go +++ b/src/util/chars_test.go @@ -55,3 +55,28 @@ func TestTrimLength(t *testing.T) { check(" h o ", 5) check(" ", 0) } + +func TestSplit(t *testing.T) { + check := func(str string, delim string, tokens ...string) { + input := ToChars([]byte(str)) + result := input.Split(delim) + if len(result) != len(tokens) { + t.Errorf("Invalid Split result for '%s': %d tokens found (expected %d): %s", + str, len(result), len(tokens), result) + } + for idx, token := range tokens { + if result[idx].ToString() != token { + t.Errorf("Invalid Split result for '%s': %s (expected %s)", + str, result[idx].ToString(), token) + } + } + } + check("abc:def::", ":", "abc:", "def:", ":") + check("abc:def::", "-", "abc:def::") + check("abc", "", "a", "b", "c") + check("abc", "a", "a", "bc") + check("abc", "ab", "ab", "c") + check("abc", "abc", "abc") + check("abc", "abcd", "abc") + check("", "abcd", "") +} |