From 92a75c9563600a174e9ee8334853f99ed560492a Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Fri, 2 Oct 2015 18:40:20 +0900 Subject: 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. --- src/tokenizer_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/tokenizer_test.go') diff --git a/src/tokenizer_test.go b/src/tokenizer_test.go index 0f95aa13..b0924402 100644 --- a/src/tokenizer_test.go +++ b/src/tokenizer_test.go @@ -44,22 +44,22 @@ func TestTokenize(t *testing.T) { // AWK-style input := " abc: def: ghi " tokens := Tokenize([]rune(input), Delimiter{}) - if string(tokens[0].text) != "abc: " || tokens[0].prefixLength != 2 { + if string(tokens[0].text) != "abc: " || tokens[0].prefixLength != 2 || tokens[0].trimLength != 4 { t.Errorf("%s", tokens) } // With delimiter tokens = Tokenize([]rune(input), delimiterRegexp(":")) - if string(tokens[0].text) != " abc:" || tokens[0].prefixLength != 0 { + if string(tokens[0].text) != " abc:" || tokens[0].prefixLength != 0 || tokens[0].trimLength != 4 { t.Errorf("%s", tokens) } // With delimiter regex tokens = Tokenize([]rune(input), delimiterRegexp("\\s+")) - if string(tokens[0].text) != " " || tokens[0].prefixLength != 0 || - string(tokens[1].text) != "abc: " || tokens[1].prefixLength != 2 || - string(tokens[2].text) != "def: " || tokens[2].prefixLength != 8 || - string(tokens[3].text) != "ghi " || tokens[3].prefixLength != 14 { + if string(tokens[0].text) != " " || tokens[0].prefixLength != 0 || tokens[0].trimLength != 0 || + string(tokens[1].text) != "abc: " || tokens[1].prefixLength != 2 || tokens[1].trimLength != 4 || + string(tokens[2].text) != "def: " || tokens[2].prefixLength != 8 || tokens[2].trimLength != 4 || + string(tokens[3].text) != "ghi " || tokens[3].prefixLength != 14 || tokens[3].trimLength != 3 { t.Errorf("%s", tokens) } } -- cgit v1.2.3