diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2015-10-02 18:40:20 +0900 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2015-10-02 18:40:20 +0900 |
commit | 92a75c9563600a174e9ee8334853f99ed560492a (patch) | |
tree | c65a17633ee57dbfbbafa4b351c41bbbfffa3f9f /test | |
parent | 7c7a30c472463e0115adcf8bc2a792b48c03bf08 (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.rb | 47 |
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 |