Fix incorrect ordering of `--tiebreak=chunk`
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Junegunn Choi · committed by Junegunn Choi · parent f7e7259 · Browse files · 5 files·+37 added−23 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+37 added−23 removed
- tests:+8 added−2 removed
- other:+29 added−21 removed
Provenance
- Commit
38259d0- Tree
ecd1230- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
f7e7259
5 files changed+37 added−23 removed
modified:src/core.go+9 added-7 removed
144 unmodified lines145 }146 147 // Matcher148 forward := true149- for _, cri := range opts.Criteria[1:] {150- if cri == byEnd {149+ withPos := false150+ for idx := len(opts.Criteria) - 1; idx > 0; idx-- {151+ switch opts.Criteria[idx] {152+ case byChunk:153+ withPos = true154+ case byEnd:155 forward = false152- break156+ case byBegin:157+ forward = true158 }154- if cri == byBegin {155- break156- }159 }160 patternBuilder := func(runes []rune) *Pattern {161 return BuildPattern(160- opts.Fuzzy, opts.FuzzyAlgo, opts.Extended, opts.Case, opts.Normalize, forward,162+ opts.Fuzzy, opts.FuzzyAlgo, opts.Extended, opts.Case, opts.Normalize, forward, withPos,163 opts.Filter == nil, opts.Nth, opts.Delimiter, runes)164 }165 matcher := NewMatcher(patternBuilder, sort, opts.Tac, eventBox)166 191 unmodified linesmodified:src/pattern_test.go+11 added-11 removed
65 unmodified lines66 67 func TestExact(t *testing.T) {68 defer clearPatternCache()69 clearPatternCache()70- pattern := BuildPattern(true, algo.FuzzyMatchV2, true, CaseSmart, false, true, true,70+ pattern := BuildPattern(true, algo.FuzzyMatchV2, true, CaseSmart, false, true, false, true,71 []Range{}, Delimiter{}, []rune("'abc"))72 chars := util.ToChars([]byte("aabbcc abc"))73 res, pos := algo.ExactMatchNaive(74 pattern.caseSensitive, pattern.normalize, pattern.forward, &chars, pattern.termSets[0][0].text, true, nil)7 unmodified lines82 83 func TestEqual(t *testing.T) {84 defer clearPatternCache()85 clearPatternCache()86- pattern := BuildPattern(true, algo.FuzzyMatchV2, true, CaseSmart, false, true, true, []Range{}, Delimiter{}, []rune("^AbC$"))86+ pattern := BuildPattern(true, algo.FuzzyMatchV2, true, CaseSmart, false, true, false, true, []Range{}, Delimiter{}, []rune("^AbC$"))87 88 match := func(str string, sidxExpected int, eidxExpected int) {89 chars := util.ToChars([]byte(str))90 res, pos := algo.EqualMatch(14 unmodified lines105 106 func TestCaseSensitivity(t *testing.T) {107 defer clearPatternCache()108 clearPatternCache()109- pat1 := BuildPattern(true, algo.FuzzyMatchV2, false, CaseSmart, false, true, true, []Range{}, Delimiter{}, []rune("abc"))109+ pat1 := BuildPattern(true, algo.FuzzyMatchV2, false, CaseSmart, false, true, false, true, []Range{}, Delimiter{}, []rune("abc"))110 clearPatternCache()111- pat2 := BuildPattern(true, algo.FuzzyMatchV2, false, CaseSmart, false, true, true, []Range{}, Delimiter{}, []rune("Abc"))111+ pat2 := BuildPattern(true, algo.FuzzyMatchV2, false, CaseSmart, false, true, false, true, []Range{}, Delimiter{}, []rune("Abc"))112 clearPatternCache()113- pat3 := BuildPattern(true, algo.FuzzyMatchV2, false, CaseIgnore, false, true, true, []Range{}, Delimiter{}, []rune("abc"))113+ pat3 := BuildPattern(true, algo.FuzzyMatchV2, false, CaseIgnore, false, true, false, true, []Range{}, Delimiter{}, []rune("abc"))114 clearPatternCache()115- pat4 := BuildPattern(true, algo.FuzzyMatchV2, false, CaseIgnore, false, true, true, []Range{}, Delimiter{}, []rune("Abc"))115+ pat4 := BuildPattern(true, algo.FuzzyMatchV2, false, CaseIgnore, false, true, false, true, []Range{}, Delimiter{}, []rune("Abc"))116 clearPatternCache()117- pat5 := BuildPattern(true, algo.FuzzyMatchV2, false, CaseRespect, false, true, true, []Range{}, Delimiter{}, []rune("abc"))117+ pat5 := BuildPattern(true, algo.FuzzyMatchV2, false, CaseRespect, false, true, false, true, []Range{}, Delimiter{}, []rune("abc"))118 clearPatternCache()119- pat6 := BuildPattern(true, algo.FuzzyMatchV2, false, CaseRespect, false, true, true, []Range{}, Delimiter{}, []rune("Abc"))119+ pat6 := BuildPattern(true, algo.FuzzyMatchV2, false, CaseRespect, false, true, false, true, []Range{}, Delimiter{}, []rune("Abc"))120 121 if string(pat1.text) != "abc" || pat1.caseSensitive != false ||122 string(pat2.text) != "Abc" || pat2.caseSensitive != true ||123 string(pat3.text) != "abc" || pat3.caseSensitive != false ||4 unmodified lines128 }129 }130 131 func TestOrigTextAndTransformed(t *testing.T) {132- pattern := BuildPattern(true, algo.FuzzyMatchV2, true, CaseSmart, false, true, true, []Range{}, Delimiter{}, []rune("jg"))132+ pattern := BuildPattern(true, algo.FuzzyMatchV2, true, CaseSmart, false, true, false, true, []Range{}, Delimiter{}, []rune("jg"))133 tokens := Tokenize("junegunn", Delimiter{})134 trans := Transform(tokens, []Range{{1, 1}})135 136 origBytes := []byte("junegunn.choi")26 unmodified lines163 164 func TestCacheKey(t *testing.T) {165 test := func(extended bool, patStr string, expected string, cacheable bool) {166 clearPatternCache()167- pat := BuildPattern(true, algo.FuzzyMatchV2, extended, CaseSmart, false, true, true, []Range{}, Delimiter{}, []rune(patStr))167+ pat := BuildPattern(true, algo.FuzzyMatchV2, extended, CaseSmart, false, true, false, true, []Range{}, Delimiter{}, []rune(patStr))168 if pat.CacheKey() != expected {169 t.Errorf("Expected: %s, actual: %s", expected, pat.CacheKey())170 }171 if pat.cacheable != cacheable {15 unmodified lines187 188 func TestCacheable(t *testing.T) {189 test := func(fuzzy bool, str string, expected string, cacheable bool) {190 clearPatternCache()191- pat := BuildPattern(fuzzy, algo.FuzzyMatchV2, true, CaseSmart, true, true, true, []Range{}, Delimiter{}, []rune(str))191+ pat := BuildPattern(fuzzy, algo.FuzzyMatchV2, true, CaseSmart, true, true, false, true, []Range{}, Delimiter{}, []rune(str))192 if pat.CacheKey() != expected {193 t.Errorf("Expected: %s, actual: %s", expected, pat.CacheKey())194 }195 if cacheable != pat.cacheable {14 unmodified linesmodified:src/pattern.go+5 added-3 removed
49 unmodified lines50 extended bool51 caseSensitive bool52 normalize bool53 forward bool54+ withPos bool55 text []rune56 termSets []termSet57 sortable bool58 cacheable bool26 unmodified lines85 }86 87 // BuildPattern builds Pattern object from the given arguments88 func BuildPattern(fuzzy bool, fuzzyAlgo algo.Algo, extended bool, caseMode Case, normalize bool, forward bool,88- cacheable bool, nth []Range, delimiter Delimiter, runes []rune) *Pattern {89+ withPos bool, cacheable bool, nth []Range, delimiter Delimiter, runes []rune) *Pattern {90 91 var asString string92 if extended {93 asString = strings.TrimLeft(string(runes), " ")51 unmodified lines145 extended: extended,146 caseSensitive: caseSensitive,147 normalize: normalize,148 forward: forward,149+ withPos: withPos,150 text: []rune(asString),151 termSets: termSets,152 sortable: sortable,153 cacheable: cacheable,149 unmodified lines303 matches := []Result{}304 305 if space == nil {306 for idx := 0; idx < chunk.count; idx++ {305- if match, _, _ := p.MatchItem(&chunk.items[idx], false, slab); match != nil {307+ if match, _, _ := p.MatchItem(&chunk.items[idx], p.withPos, slab); match != nil {308 matches = append(matches, *match)309 }310 }311 } else {312 for _, result := range space {311- if match, _, _ := p.MatchItem(result.item, false, slab); match != nil {313+ if match, _, _ := p.MatchItem(result.item, p.withPos, slab); match != nil {314 matches = append(matches, *match)315 }316 }317 }110 unmodified linesmodified:test/test_go.rb+8 added-2 removed
754 unmodified lines755 end756 757 def test_tiebreak_chunk758 writelines(tempname, [759- '1 foobarbaz baz',759+ '1 foobarbaz ba',760 '2 foobar baz',761 '3 foo barbaz'762 ])763 764 assert_equal [765 '3 foo barbaz',766 '2 foobar baz',767- '1 foobarbaz baz'767+ '1 foobarbaz ba'768 ], `#{FZF} -fo --tiebreak=chunk < #{tempname}`.lines(chomp: true)769+770+ assert_equal [771+ '1 foobarbaz ba',772+ '2 foobar baz',773+ '3 foo barbaz'774+ ], `#{FZF} -fba --tiebreak=chunk < #{tempname}`.lines(chomp: true)775 end776 777 def test_invalid_cache778 tmux.send_keys "(echo d; echo D; echo x) | #{fzf('-q d')}", :Enter1951 unmodified linesmodified:CHANGELOG.md+4 added
1 CHANGELOG2 =========3 4+0.32.15+------6+- Fixed incorrect ordering of `--tiebreak=chunk`7+8 0.32.09 ------10 - Updated the scoring algorithm11 - Different bonus points to different categories of word boundaries1268 unmodified lines