summaryrefslogtreecommitdiff
path: root/src/util/util_test.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2015-10-02 18:40:20 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2015-10-02 18:40:20 +0900
commit92a75c9563600a174e9ee8334853f99ed560492a (patch)
treec65a17633ee57dbfbbafa4b351c41bbbfffa3f9f /src/util/util_test.go
parent7c7a30c472463e0115adcf8bc2a792b48c03bf08 (diff)
downloadfzf-92a75c9563600a174e9ee8334853f99ed560492a.tar.gz
Use trimmed length when --nth is used with --tiebreak=length
This change improves sort ordering for aligned tabular input. Given the following input: apple juice 100 apple pie 200 fzf --nth=2 will now prefer the one with pie. Before this change fzf compared "juice " and "pie ", both of which have the same length.
Diffstat (limited to 'src/util/util_test.go')
-rw-r--r--src/util/util_test.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/util/util_test.go b/src/util/util_test.go
index 06cfd4f2..8aeaeac5 100644
--- a/src/util/util_test.go
+++ b/src/util/util_test.go
@@ -20,3 +20,23 @@ func TestContrain(t *testing.T) {
t.Error("Expected", 3)
}
}
+
+func TestTrimLen(t *testing.T) {
+ check := func(str string, exp int) {
+ trimmed := TrimLen([]rune(str))
+ if trimmed != exp {
+ t.Errorf("Invalid TrimLen 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)
+}