Skip to content
Myr

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

5 files+37 added−23 removed

modified:src/core.go+9 added-7 removed
144 unmodified lines
145 }146147 // 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 lines
modified:src/pattern_test.go+11 added-11 removed
65 unmodified lines
6667func 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 lines
8283func 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$"))8788 match := func(str string, sidxExpected int, eidxExpected int) {89 chars := util.ToChars([]byte(str))90 res, pos := algo.EqualMatch(
14 unmodified lines
105106func 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"))120121 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 lines
128 }129}130131func 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}})135136 origBytes := []byte("junegunn.choi")
26 unmodified lines
163164func 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 lines
187188func 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 lines
modified:src/pattern.go+5 added-3 removed
49 unmodified lines
50 extended bool51 caseSensitive bool52 normalize bool53 forward bool54 withPos bool55 text []rune56 termSets []termSet57 sortable bool58 cacheable bool
26 unmodified lines
85}8687// BuildPattern builds Pattern object from the given arguments88func 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 {9091 var asString string92 if extended {93 asString = strings.TrimLeft(string(runes), " ")
51 unmodified lines
145 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 lines
303 matches := []Result{}304305 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 lines
modified:test/test_go.rb+8 added-2 removed
754 unmodified lines
755 end756757 def test_tiebreak_chunk758 writelines(tempname, [759 '1 foobarbaz baz',759 '1 foobarbaz ba',760 '2 foobar baz',761 '3 foo barbaz'762 ])763764 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)769770 assert_equal [771 '1 foobarbaz ba',772 '2 foobar baz',773 '3 foo barbaz'774 ], `#{FZF} -fba --tiebreak=chunk < #{tempname}`.lines(chomp: true)775 end776777 def test_invalid_cache778 tmux.send_keys "(echo d; echo D; echo x) | #{fzf('-q d')}", :Enter
1951 unmodified lines
modified:CHANGELOG.md+4 added
1CHANGELOG2=========340.32.15------6- Fixed incorrect ordering of `--tiebreak=chunk`780.32.09------10- Updated the scoring algorithm11 - Different bonus points to different categories of word boundaries
1268 unmodified lines