mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-11-17 10:35:10 +00:00
c9f16b6430
When --with-nth is used, fzf used to preprocess each line and store the result as rune array, which was wasteful if the line only contains ascii characters.
47 lines
981 B
Go
47 lines
981 B
Go
package util
|
|
|
|
import "testing"
|
|
|
|
func TestToCharsAscii(t *testing.T) {
|
|
chars := ToChars([]byte("foobar"))
|
|
if !chars.inBytes || chars.ToString() != "foobar" || !chars.inBytes {
|
|
t.Error()
|
|
}
|
|
}
|
|
|
|
func TestCharsLength(t *testing.T) {
|
|
chars := ToChars([]byte("\tabc한글 "))
|
|
if chars.inBytes || chars.Length() != 8 || chars.TrimLength() != 5 {
|
|
t.Error()
|
|
}
|
|
}
|
|
|
|
func TestCharsToString(t *testing.T) {
|
|
text := "\tabc한글 "
|
|
chars := ToChars([]byte(text))
|
|
if chars.ToString() != text {
|
|
t.Error()
|
|
}
|
|
}
|
|
|
|
func TestTrimLength(t *testing.T) {
|
|
check := func(str string, exp uint16) {
|
|
chars := ToChars([]byte(str))
|
|
trimmed := chars.TrimLength()
|
|
if trimmed != exp {
|
|
t.Errorf("Invalid TrimLength result for '%s': %d (expected %d)",
|
|
str, trimmed, exp)
|
|
}
|
|
}
|
|
check("hello", 5)
|
|
check("hello ", 5)
|
|
check("hello ", 5)
|
|
check(" hello", 5)
|
|
check(" hello", 5)
|
|
check(" hello ", 5)
|
|
check(" hello ", 5)
|
|
check("h o", 5)
|
|
check(" h o ", 5)
|
|
check(" ", 0)
|
|
}
|