Enhanced ranking algorithm
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Based on the patch by Matt Westcott (@mjwestcott). But with a more conservative approach: - Does not use linearly increasing penalties; It is agreed upon that we should prefer matching characters at the beginnings of the words, but it's not always clear that the relevance is inversely proportional to the distance from the beginning. - The approach here is more conservative in that the bonus is never large enough to override the matchlen, so it can be thought of as the first implicit tiebreak criterion. - One may argue the change breaks the contract of --tiebreak, but the judgement depends on the definition of "tie".
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+214 added−94 removed
- tests:+11 added−11 removed
- other:+203 added−83 removed
Provenance
- Commit
2f6d23b- Tree
7e80f65- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
5f63a7b
6 files changed+214 added−94 removed
modified:src/algo/algo_test.go+46 added-27 removed
3 unmodified lines4 "strings"5 "testing"6 )7 8-func assertMatch(t *testing.T, fun func(bool, bool, []rune, []rune) (int, int), caseSensitive bool, forward bool, input string, pattern string, sidx int, eidx int) {8+func assertMatch(t *testing.T, fun func(bool, bool, []rune, []rune) Result, caseSensitive, forward bool, input, pattern string, sidx int32, eidx int32, bonus int32) {9 if !caseSensitive {10 pattern = strings.ToLower(pattern)11 }12- s, e := fun(caseSensitive, forward, []rune(input), []rune(pattern))13- if s != sidx {14- t.Errorf("Invalid start index: %d (expected: %d, %s / %s)", s, sidx, input, pattern)12+ res := fun(caseSensitive, forward, []rune(input), []rune(pattern))13+ if res.Start != sidx {14+ t.Errorf("Invalid start index: %d (expected: %d, %s / %s)", res.Start, sidx, input, pattern)15 }16- if e != eidx {17- t.Errorf("Invalid end index: %d (expected: %d, %s / %s)", e, eidx, input, pattern)16+ if res.End != eidx {17+ t.Errorf("Invalid end index: %d (expected: %d, %s / %s)", res.End, eidx, input, pattern)18 }19+ if res.Bonus != bonus {20+ t.Errorf("Invalid bonus: %d (expected: %d, %s / %s)", res.Bonus, bonus, input, pattern)21+ }22 }23 24 func TestFuzzyMatch(t *testing.T) {22- assertMatch(t, FuzzyMatch, false, true, "fooBarbaz", "oBZ", 2, 9)23- assertMatch(t, FuzzyMatch, true, true, "fooBarbaz", "oBZ", -1, -1)24- assertMatch(t, FuzzyMatch, true, true, "fooBarbaz", "oBz", 2, 9)25- assertMatch(t, FuzzyMatch, true, true, "fooBarbaz", "fooBarbazz", -1, -1)25+ assertMatch(t, FuzzyMatch, false, true, "fooBarbaz", "oBZ", 2, 9, 2)26+ assertMatch(t, FuzzyMatch, false, true, "foo bar baz", "fbb", 0, 9, 8)27+ assertMatch(t, FuzzyMatch, false, true, "/AutomatorDocument.icns", "rdoc", 9, 13, 4)28+ assertMatch(t, FuzzyMatch, false, true, "/man1/zshcompctl.1", "zshc", 6, 10, 7)29+ assertMatch(t, FuzzyMatch, false, true, "/.oh-my-zsh/cache", "zshc", 8, 13, 8)30+ assertMatch(t, FuzzyMatch, false, true, "ab0123 456", "12356", 3, 10, 3)31+ assertMatch(t, FuzzyMatch, false, true, "abc123 456", "12356", 3, 10, 5)32+33+ assertMatch(t, FuzzyMatch, false, true, "foo/bar/baz", "fbb", 0, 9, 8)34+ assertMatch(t, FuzzyMatch, false, true, "fooBarBaz", "fbb", 0, 7, 6)35+ assertMatch(t, FuzzyMatch, false, true, "foo barbaz", "fbb", 0, 8, 6)36+ assertMatch(t, FuzzyMatch, false, true, "fooBar Baz", "foob", 0, 4, 8)37+ assertMatch(t, FuzzyMatch, true, true, "fooBarbaz", "oBZ", -1, -1, 0)38+ assertMatch(t, FuzzyMatch, true, true, "fooBarbaz", "oBz", 2, 9, 2)39+ assertMatch(t, FuzzyMatch, true, true, "Foo Bar Baz", "fbb", -1, -1, 0)40+ assertMatch(t, FuzzyMatch, true, true, "Foo/Bar/Baz", "FBB", 0, 9, 8)41+ assertMatch(t, FuzzyMatch, true, true, "FooBarBaz", "FBB", 0, 7, 6)42+ assertMatch(t, FuzzyMatch, true, true, "foo BarBaz", "fBB", 0, 8, 7)43+ assertMatch(t, FuzzyMatch, true, true, "FooBar Baz", "FooB", 0, 4, 8)44+ assertMatch(t, FuzzyMatch, true, true, "fooBarbaz", "fooBarbazz", -1, -1, 0)45 }46 47 func TestFuzzyMatchBackward(t *testing.T) {29- assertMatch(t, FuzzyMatch, false, true, "foobar fb", "fb", 0, 4)30- assertMatch(t, FuzzyMatch, false, false, "foobar fb", "fb", 7, 9)48+ assertMatch(t, FuzzyMatch, false, true, "foobar fb", "fb", 0, 4, 4)49+ assertMatch(t, FuzzyMatch, false, false, "foobar fb", "fb", 7, 9, 5)50 }51 52 func TestExactMatchNaive(t *testing.T) {53 for _, dir := range []bool{true, false} {35- assertMatch(t, ExactMatchNaive, false, dir, "fooBarbaz", "oBA", 2, 5)36- assertMatch(t, ExactMatchNaive, true, dir, "fooBarbaz", "oBA", -1, -1)37- assertMatch(t, ExactMatchNaive, true, dir, "fooBarbaz", "fooBarbazz", -1, -1)54+ assertMatch(t, ExactMatchNaive, false, dir, "fooBarbaz", "oBA", 2, 5, 0)55+ assertMatch(t, ExactMatchNaive, true, dir, "fooBarbaz", "oBA", -1, -1, 0)56+ assertMatch(t, ExactMatchNaive, true, dir, "fooBarbaz", "fooBarbazz", -1, -1, 0)57 }58 }59 60 func TestExactMatchNaiveBackward(t *testing.T) {42- assertMatch(t, ExactMatchNaive, false, true, "foobar foob", "oo", 1, 3)43- assertMatch(t, ExactMatchNaive, false, false, "foobar foob", "oo", 8, 10)61+ assertMatch(t, ExactMatchNaive, false, true, "foobar foob", "oo", 1, 3, 0)62+ assertMatch(t, ExactMatchNaive, false, false, "foobar foob", "oo", 8, 10, 0)63 }64 65 func TestPrefixMatch(t *testing.T) {66 for _, dir := range []bool{true, false} {48- assertMatch(t, PrefixMatch, false, dir, "fooBarbaz", "Foo", 0, 3)49- assertMatch(t, PrefixMatch, true, dir, "fooBarbaz", "Foo", -1, -1)50- assertMatch(t, PrefixMatch, false, dir, "fooBarbaz", "baz", -1, -1)67+ assertMatch(t, PrefixMatch, false, dir, "fooBarbaz", "Foo", 0, 3, 0)68+ assertMatch(t, PrefixMatch, true, dir, "fooBarbaz", "Foo", -1, -1, 0)69+ assertMatch(t, PrefixMatch, false, dir, "fooBarbaz", "baz", -1, -1, 0)70 }71 }72 73 func TestSuffixMatch(t *testing.T) {74 for _, dir := range []bool{true, false} {56- assertMatch(t, SuffixMatch, false, dir, "fooBarbaz", "Foo", -1, -1)57- assertMatch(t, SuffixMatch, false, dir, "fooBarbaz", "baz", 6, 9)58- assertMatch(t, SuffixMatch, true, dir, "fooBarbaz", "Baz", -1, -1)75+ assertMatch(t, SuffixMatch, false, dir, "fooBarbaz", "Foo", -1, -1, 0)76+ assertMatch(t, SuffixMatch, false, dir, "fooBarbaz", "baz", 6, 9, 0)77+ assertMatch(t, SuffixMatch, true, dir, "fooBarbaz", "Baz", -1, -1, 0)78 }79 }80 81 func TestEmptyPattern(t *testing.T) {82 for _, dir := range []bool{true, false} {64- assertMatch(t, FuzzyMatch, true, dir, "foobar", "", 0, 0)65- assertMatch(t, ExactMatchNaive, true, dir, "foobar", "", 0, 0)66- assertMatch(t, PrefixMatch, true, dir, "foobar", "", 0, 0)67- assertMatch(t, SuffixMatch, true, dir, "foobar", "", 6, 6)83+ assertMatch(t, FuzzyMatch, true, dir, "foobar", "", 0, 0, 0)84+ assertMatch(t, ExactMatchNaive, true, dir, "foobar", "", 0, 0, 0)85+ assertMatch(t, PrefixMatch, true, dir, "foobar", "", 0, 0, 0)86+ assertMatch(t, SuffixMatch, true, dir, "foobar", "", 6, 6, 0)87 }88 }modified:src/algo/algo.go+112 added-24 removed
20 unmodified lines21 }22 return runes[max-index-1]23 }24 25+// Result conatins the results of running a match function.26+type Result struct {27+ Start int3228+ End int3229+30+ // Items are basically sorted by the lengths of matched substrings.31+ // But we slightly adjust the score with bonus for better results.32+ Bonus int3233+}34+35+type charClass int36+37+const (38+ charNonWord charClass = iota39+ charLower40+ charUpper41+ charLetter42+ charNumber43+)44+45 // FuzzyMatch performs fuzzy-match26-func FuzzyMatch(caseSensitive bool, forward bool, runes []rune, pattern []rune) (int, int) {46+func FuzzyMatch(caseSensitive bool, forward bool, runes []rune, pattern []rune) Result {47 if len(pattern) == 0 {28- return 0, 048+ return Result{0, 0, 0}49 }50 51 // 0. (FIXME) How to find the shortest match?52 // a_____b__c__abc56 unmodified lines109 break110 }111 }112 }93- if forward {94- return sidx, eidx113+114+ // Calculate the bonus. This can't be done at the same time as the115+ // pattern scan above because 'forward' may be false.116+ if !forward {117+ sidx, eidx = lenRunes-eidx, lenRunes-sidx118 }96- return lenRunes - eidx, lenRunes - sidx119+120+ var bonus int32121+ pidx := 0122+ consecutive := false123+ prevClass := charNonWord124+ for index := 0; index < eidx; index++ {125+ char := runes[index]126+ var class charClass127+ if unicode.IsLower(char) {128+ class = charLower129+ } else if unicode.IsUpper(char) {130+ class = charUpper131+ } else if unicode.IsLetter(char) {132+ class = charLetter133+ } else if unicode.IsNumber(char) {134+ class = charNumber135+ } else {136+ class = charNonWord137+ }138+139+ var point int32140+ if prevClass == charNonWord && class != charNonWord {141+ // Word boundary142+ point = 2143+ } else if prevClass == charLower && class == charUpper ||144+ prevClass != charNumber && class == charNumber {145+ // camelCase letter123146+ point = 1147+ }148+ prevClass = class149+150+ if index >= sidx {151+ if !caseSensitive {152+ if char >= 'A' && char <= 'Z' {153+ char += 32154+ } else if char > unicode.MaxASCII {155+ char = unicode.To(unicode.LowerCase, char)156+ }157+ }158+ pchar := pattern[pidx]159+ if pchar == char {160+ // Boost bonus for the first character in the pattern161+ if pidx == 0 {162+ point *= 2163+ }164+ // Bonus to consecutive matching chars165+ if consecutive {166+ point++167+ }168+ bonus += point169+170+ if pidx++; pidx == lenPattern {171+ break172+ }173+ consecutive = true174+ } else {175+ consecutive = false176+ }177+ }178+ }179+180+ return Result{int32(sidx), int32(eidx), bonus}181 }98- return -1, -1182+ return Result{-1, -1, 0}183 }184 185 // ExactMatchNaive is a basic string searching algorithm that handles case186 // sensitivity. Although naive, it still performs better than the combination1 unmodified line188 // strings and patterns are not very long.189 //190 // We might try to implement better algorithms in the future:191 // http://en.wikipedia.org/wiki/String_searching_algorithm108-func ExactMatchNaive(caseSensitive bool, forward bool, runes []rune, pattern []rune) (int, int) {192+func ExactMatchNaive(caseSensitive bool, forward bool, runes []rune, pattern []rune) Result {193+ // Note: ExactMatchNaive always return a zero bonus.194 if len(pattern) == 0 {110- return 0, 0195+ return Result{0, 0, 0}196 }197 198 lenRunes := len(runes)199 lenPattern := len(pattern)200 201 if lenRunes < lenPattern {117- return -1, -1202+ return Result{-1, -1, 0}203 }204 205 pidx := 0206 for index := 0; index < lenRunes; index++ {9 unmodified lines216 if pchar == char {217 pidx++218 if pidx == lenPattern {219 if forward {135- return index - lenPattern + 1, index + 1220+ return Result{int32(index - lenPattern + 1), int32(index + 1), 0}221 }137- return lenRunes - (index + 1), lenRunes - (index - lenPattern + 1)222+ return Result{int32(lenRunes - (index + 1)), int32(lenRunes - (index - lenPattern + 1)), 0}223 }224 } else {225 index -= pidx226 pidx = 0227 }228 }144- return -1, -1229+ return Result{-1, -1, 0}230 }231 232 // PrefixMatch performs prefix-match148-func PrefixMatch(caseSensitive bool, forward bool, runes []rune, pattern []rune) (int, int) {233+func PrefixMatch(caseSensitive bool, forward bool, runes []rune, pattern []rune) Result {234+ // Note: PrefixMatch always return a zero bonus.235 if len(runes) < len(pattern) {150- return -1, -1236+ return Result{-1, -1, 0}237 }238 239 for index, r := range pattern {240 char := runes[index]241 if !caseSensitive {242 char = unicode.ToLower(char)243 }244 if char != r {159- return -1, -1245+ return Result{-1, -1, 0}246 }247 }162- return 0, len(pattern)248+ return Result{0, int32(len(pattern)), 0}249 }250 251 // SuffixMatch performs suffix-match166-func SuffixMatch(caseSensitive bool, forward bool, input []rune, pattern []rune) (int, int) {252+func SuffixMatch(caseSensitive bool, forward bool, input []rune, pattern []rune) Result {253+ // Note: SuffixMatch always return a zero bonus.254 runes := util.TrimRight(input)255 trimmedLen := len(runes)256 diff := trimmedLen - len(pattern)257 if diff < 0 {171- return -1, -1258+ return Result{-1, -1, 0}259 }260 261 for index, r := range pattern {262 char := runes[index+diff]263 if !caseSensitive {264 char = unicode.ToLower(char)265 }266 if char != r {180- return -1, -1267+ return Result{-1, -1, 0}268 }269 }183- return trimmedLen - len(pattern), trimmedLen270+ return Result{int32(trimmedLen - len(pattern)), int32(trimmedLen), 0}271 }272 273 // EqualMatch performs equal-match187-func EqualMatch(caseSensitive bool, forward bool, runes []rune, pattern []rune) (int, int) {274+func EqualMatch(caseSensitive bool, forward bool, runes []rune, pattern []rune) Result {275+ // Note: EqualMatch always return a zero bonus.276 if len(runes) != len(pattern) {189- return -1, -1277+ return Result{-1, -1, 0}278 }279 runesStr := string(runes)280 if !caseSensitive {281 runesStr = strings.ToLower(runesStr)282 }283 if runesStr == string(pattern) {196- return 0, len(pattern)284+ return Result{0, int32(len(pattern)), 0}285 }198- return -1, -1286+ return Result{-1, -1, 0}287 }modified:src/item.go+7 added-4 removed
21 unmodified lines22 transformed []Token23 offsets []Offset24 colors []ansiOffset25 rank [5]int3226+ bonus int3227 }28 29 // Sort criteria to use. Never changes once fzf is started.30 var sortCriteria []criterion42 unmodified lines73 }74 matchlen += end - begin75 }76 }76- if matchlen == 0 {77- matchlen = math.MaxInt3278- }77 rank := buildEmptyRank(item.Index())78 for idx, criterion := range sortCriteria {79 var val int3280 switch criterion {81 case byMatchLen:84- val = int32(matchlen)82+ if matchlen == 0 {83+ val = math.MaxInt3284+ } else {85+ // It is extremely unlikely that bonus exceeds 12886+ val = 128*int32(matchlen) - item.bonus87+ }88 case byLength:89 // It is guaranteed that .transformed in not null in normal execution90 if item.transformed != nil {91 // If offsets is empty, lenSum will be 0, but we don't care200 unmodified linesmodified:src/pattern_test.go+7 added-7 removed
68 unmodified lines69 defer clearPatternCache()70 clearPatternCache()71 pattern := BuildPattern(true, true, CaseSmart, true,72 []Range{}, Delimiter{}, []rune("'abc"))73- sidx, eidx := algo.ExactMatchNaive(73+ res := algo.ExactMatchNaive(74 pattern.caseSensitive, pattern.forward, []rune("aabbcc abc"), pattern.termSets[0][0].text)75- if sidx != 7 || eidx != 10 {76- t.Errorf("%s / %d / %d", pattern.termSets, sidx, eidx)75+ if res.Start != 7 || res.End != 10 {76+ t.Errorf("%s / %d / %d", pattern.termSets, res.Start, res.End)77 }78 }79 80 func TestEqual(t *testing.T) {81 defer clearPatternCache()82 clearPatternCache()83 pattern := BuildPattern(true, true, CaseSmart, true, []Range{}, Delimiter{}, []rune("^AbC$"))84 85- match := func(str string, sidxExpected int, eidxExpected int) {86- sidx, eidx := algo.EqualMatch(85+ match := func(str string, sidxExpected int32, eidxExpected int32) {86+ res := algo.EqualMatch(87 pattern.caseSensitive, pattern.forward, []rune(str), pattern.termSets[0][0].text)88- if sidx != sidxExpected || eidx != eidxExpected {89- t.Errorf("%s / %d / %d", pattern.termSets, sidx, eidx)88+ if res.Start != sidxExpected || res.End != eidxExpected {89+ t.Errorf("%s / %d / %d", pattern.termSets, res.Start, res.End)90 }91 }92 match("ABC", -1, -1)93 match("AbC", 0, 3)71 unmodified linesmodified:src/pattern.go+31 added-21 removed
47 unmodified lines48 termSets []termSet49 cacheable bool50 delimiter Delimiter51 nth []Range52- procFun map[termType]func(bool, bool, []rune, []rune) (int, int)52+ procFun map[termType]func(bool, bool, []rune, []rune) algo.Result53 }54 55 var (56 _patternCache map[string]*Pattern67 unmodified lines124 termSets: termSets,125 cacheable: cacheable,126 nth: nth,127 delimiter: delimiter,128- procFun: make(map[termType]func(bool, bool, []rune, []rune) (int, int))}128+ procFun: make(map[termType]func(bool, bool, []rune, []rune) algo.Result)}129 130 ptr.procFun[termFuzzy] = algo.FuzzyMatch131 ptr.procFun[termEqual] = algo.EqualMatch132 ptr.procFun[termExact] = algo.ExactMatchNaive141 unmodified lines274 func (p *Pattern) matchChunk(chunk *Chunk) []*Item {275 matches := []*Item{}276 if !p.extended {277 for _, item := range *chunk {278- if sidx, eidx, tlen := p.basicMatch(item); sidx >= 0 {278+ offset, bonus := p.basicMatch(item)279+ if sidx := offset[0]; sidx >= 0 {280 matches = append(matches,280- dupItem(item, []Offset{Offset{int32(sidx), int32(eidx), int32(tlen)}}))281+ dupItem(item, []Offset{offset}, bonus))282 }283 }284 } else {285 for _, item := range *chunk {285- if offsets := p.extendedMatch(item); len(offsets) == len(p.termSets) {286- matches = append(matches, dupItem(item, offsets))286+ if offsets, bonus := p.extendedMatch(item); len(offsets) == len(p.termSets) {287+ matches = append(matches, dupItem(item, offsets, bonus))288 }289 }290 }291 return matches1 unmodified line293 294 // MatchItem returns true if the Item is a match295 func (p *Pattern) MatchItem(item *Item) bool {296 if !p.extended {296- sidx, _, _ := p.basicMatch(item)297+ offset, _ := p.basicMatch(item)298+ sidx := offset[0]299 return sidx >= 0300 }299- offsets := p.extendedMatch(item)301+ offsets, _ := p.extendedMatch(item)302 return len(offsets) == len(p.termSets)303 }304 303-func dupItem(item *Item, offsets []Offset) *Item {305+func dupItem(item *Item, offsets []Offset, bonus int32) *Item {306 sort.Sort(ByOrder(offsets))307 return &Item{308 text: item.text,309 origText: item.origText,310 transformed: item.transformed,311 offsets: offsets,312+ bonus: bonus,313 colors: item.colors,314 rank: buildEmptyRank(item.Index())}315 }316 314-func (p *Pattern) basicMatch(item *Item) (int, int, int) {317+func (p *Pattern) basicMatch(item *Item) (Offset, int32) {318 input := p.prepareInput(item)319 if p.fuzzy {320 return p.iter(algo.FuzzyMatch, input, p.caseSensitive, p.forward, p.text)321 }322 return p.iter(algo.ExactMatchNaive, input, p.caseSensitive, p.forward, p.text)323 }324 322-func (p *Pattern) extendedMatch(item *Item) []Offset {325+func (p *Pattern) extendedMatch(item *Item) ([]Offset, int32) {326 input := p.prepareInput(item)327 offsets := []Offset{}328+ var totalBonus int32329 for _, termSet := range p.termSets {330 var offset *Offset331+ var bonus int32332 for _, term := range termSet {333 pfun := p.procFun[term.typ]329- if sidx, eidx, tlen := p.iter(pfun, input, term.caseSensitive, p.forward, term.text); sidx >= 0 {334+ off, pen := p.iter(pfun, input, term.caseSensitive, p.forward, term.text)335+ if sidx := off[0]; sidx >= 0 {336 if term.inv {337 continue338 }333- offset = &Offset{int32(sidx), int32(eidx), int32(tlen)}339+ offset, bonus = &off, pen340 break341 } else if term.inv {336- offset = &Offset{0, 0, 0}342+ offset, bonus = &Offset{0, 0, 0}, 0343 continue344 }345 }346 if offset != nil {347 offsets = append(offsets, *offset)348+ totalBonus += bonus349 }350 }344- return offsets351+ return offsets, totalBonus352 }353 354 func (p *Pattern) prepareInput(item *Item) []Token {355 if item.transformed != nil {10 unmodified lines366 item.transformed = ret367 return ret368 }369 363-func (p *Pattern) iter(pfun func(bool, bool, []rune, []rune) (int, int),364- tokens []Token, caseSensitive bool, forward bool, pattern []rune) (int, int, int) {370+func (p *Pattern) iter(pfun func(bool, bool, []rune, []rune) algo.Result,371+ tokens []Token, caseSensitive bool, forward bool, pattern []rune) (Offset, int32) {372 for _, part := range tokens {366- prefixLength := part.prefixLength367- if sidx, eidx := pfun(caseSensitive, forward, part.text, pattern); sidx >= 0 {368- return sidx + prefixLength, eidx + prefixLength, part.trimLength373+ prefixLength := int32(part.prefixLength)374+ if res := pfun(caseSensitive, forward, part.text, pattern); res.Start >= 0 {375+ var sidx int32 = res.Start + prefixLength376+ var eidx int32 = res.End + prefixLength377+ return Offset{sidx, eidx, int32(part.trimLength)}, res.Bonus378 }379 }371- return -1, -1, -1 // math.MaxUint16380+ // TODO: math.MaxUint16381+ return Offset{-1, -1, -1}, 0.0382 }modified:test/test_go.rb+11 added-11 removed
205 unmodified lines206 # Testing basic key bindings207 tmux.send_keys '99', 'C-a', '1', 'C-f', '3', 'C-b', 'C-h', 'C-u', 'C-e', 'C-y', 'C-k', 'Tab', 'BTab'208 tmux.until { |lines| lines[-2] == ' 856/100000' }209 lines = tmux.capture210- assert_equal '> 1391', lines[-4]210+ assert_equal '> 3910', lines[-4]211 assert_equal ' 391', lines[-3]212 assert_equal ' 856/100000', lines[-2]213 assert_equal '> 391', lines[-1]214 215 tmux.send_keys :Enter216- assert_equal '1391', readonce.chomp216+ assert_equal '3910', readonce.chomp217 end218 219 def test_fzf_default_command220 tmux.send_keys fzf.sub('FZF_DEFAULT_COMMAND=', "FZF_DEFAULT_COMMAND='echo hello'"), :Enter135 unmodified lines356 tmux.until { |lines| lines.last =~ /^> 5/ }357 tmux.send_keys :BTab, :BTab, :BTab358 tmux.until { |lines| lines[-2].include?('(3)') }359 tmux.send_keys :Enter360- assert_equal ['5', '5', '15', '25'], readonce.split($/)360+ assert_equal ['5', '5', '50', '51'], readonce.split($/)361 end362 end363 364 def test_query_unicode12 unmodified lines377 tmux.until { |lines| lines[-2].include?('(3)') }378 tmux.send_keys :Enter379 tmux.until { |lines| lines[-1] == '>' }380 tmux.send_keys 'C-K', :Enter381- assert_equal ['1919'], readonce.split($/)381+ assert_equal ['9090'], readonce.split($/)382 end383 384 def test_tac385 tmux.send_keys "seq 1 1000 | #{fzf :tac, :multi}", :Enter324 unmodified lines710 assert_equal output, `#{FZF} -fa -n1 < #{tempname}`.split($/)711 712 # len(1 ~ 2)713 output = [714- "apple ui bottle 2",714 "app ic bottle 4",716- "apple juice bottle 1",715 "app ice bottle 3",716+ "apple ui bottle 2",717+ "apple juice bottle 1",718 ]719 assert_equal output, `#{FZF} -fai -n1..2 < #{tempname}`.split($/)720 721 # len(1) + len(2)6 unmodified lines728 assert_equal output, `#{FZF} -x -f"a i" -n1,2 < #{tempname}`.split($/)729 730 # len(2)731 output = [732- "apple ui bottle 2",732 "app ic bottle 4",733 "app ice bottle 3",734+ "apple ui bottle 2",735 "apple juice bottle 1",736 ]737 assert_equal output, `#{FZF} -fi -n2 < #{tempname}`.split($/)738 assert_equal output, `#{FZF} -fi -n2,1..2 < #{tempname}`.split($/)203 unmodified lines942 tmux.until do |lines|943 lines[-2].include?('/90') &&944 lines[-3] == ' 1' &&945 lines[-4] == ' 2' &&946- lines[-13] == '> 15'946+ lines[-13] == '> 50'947 end948 tmux.send_keys :Down949 end950 tmux.send_keys :Enter951- assert_equal '15', readonce.chomp951+ assert_equal '50', readonce.chomp952 end953 954 def test_header_lines_reverse955 tmux.send_keys "seq 100 | #{fzf '--header-lines=10 -q 5 --reverse'}", :Enter1 unmodified line957 tmux.until do |lines|958 lines[1].include?('/90') &&959 lines[2] == ' 1' &&960 lines[3] == ' 2' &&961- lines[12] == '> 15'961+ lines[12] == '> 50'962 end963 tmux.send_keys :Up964 end965 tmux.send_keys :Enter966- assert_equal '15', readonce.chomp966+ assert_equal '50', readonce.chomp967 end968 969 def test_header_lines_overflow970 tmux.send_keys "seq 100 | #{fzf '--header-lines=200'}", :Enter498 unmodified lines