summaryrefslogtreecommitdiffstats
path: root/test
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 /test
parent7c7a30c472463e0115adcf8bc2a792b48c03bf08 (diff)
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 'test')
-rw-r--r--test/test_go.rb47
1 files changed, 47 insertions, 0 deletions
diff --git a/test/test_go.rb b/test/test_go.rb
index e76b5200..77414ecd 100644
--- a/test/test_go.rb
+++ b/test/test_go.rb
@@ -527,6 +527,53 @@ class TestGoFZF < TestBase
assert_equal output, `cat #{tempname} | #{FZF} -fh -n2 -d:`.split($/)
end
+ def test_tiebreak_length_with_nth_trim_length
+ input = [
+ "apple juice bottle 1",
+ "apple ui bottle 2",
+ "app ice bottle 3",
+ "app ic bottle 4",
+ ]
+ writelines tempname, input
+
+ # len(1)
+ output = [
+ "app ice bottle 3",
+ "app ic bottle 4",
+ "apple juice bottle 1",
+ "apple ui bottle 2",
+ ]
+ assert_equal output, `cat #{tempname} | #{FZF} -fa -n1`.split($/)
+
+ # len(1 ~ 2)
+ output = [
+ "apple ui bottle 2",
+ "app ic bottle 4",
+ "apple juice bottle 1",
+ "app ice bottle 3",
+ ]
+ assert_equal output, `cat #{tempname} | #{FZF} -fai -n1..2`.split($/)
+
+ # len(1) + len(2)
+ output = [
+ "app ic bottle 4",
+ "app ice bottle 3",
+ "apple ui bottle 2",
+ "apple juice bottle 1",
+ ]
+ assert_equal output, `cat #{tempname} | #{FZF} -x -f"a i" -n1,2`.split($/)
+
+ # len(2)
+ output = [
+ "apple ui bottle 2",
+ "app ic bottle 4",
+ "app ice bottle 3",
+ "apple juice bottle 1",
+ ]
+ assert_equal output, `cat #{tempname} | #{FZF} -fi -n2`.split($/)
+ assert_equal output, `cat #{tempname} | #{FZF} -fi -n2,1..2`.split($/)
+ end
+
def test_tiebreak_end_backward_scan
input = %w[
foobar-fb