Skip to content
Myr

Fix compatibility issues with OR operator and inverse terms

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 e7e86b6 · Browse files · 4 files+22 added−9 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+22 added−9 removed

  • tests:+6 added−0 removed
  • other:+16 added−9 removed

4 files+22 added−9 removed

modified:src/item_test.go+5 added-4 removed
1package fzf23import (4 "math"5 "sort"6 "testing"78 "github.com/junegunn/fzf/src/curses"
33 unmodified lines
42func TestItemRank(t *testing.T) {43 strs := [][]rune{[]rune("foo"), []rune("foobar"), []rune("bar"), []rune("baz")}44 item1 := Item{text: strs[0], index: 1, offsets: []Offset{}}45 rank1 := item1.Rank(true)45 if rank1.matchlen != 0 || rank1.tiebreak != 3 || rank1.index != 1 {46 if rank1.matchlen != math.MaxUint16 || rank1.tiebreak != 3 || rank1.index != 1 {47 t.Error(item1.Rank(true))48 }49 // Only differ in index50 item2 := Item{text: strs[0], index: 0, offsets: []Offset{}}
17 unmodified lines
68 item5 := Item{text: strs[2], rank: Rank{0, 0, 2}, offsets: []Offset{Offset{1, 3}, Offset{5, 7}}}69 item6 := Item{text: strs[2], rank: Rank{0, 0, 2}, offsets: []Offset{Offset{1, 2}, Offset{6, 7}}}70 items = []*Item{&item1, &item2, &item3, &item4, &item5, &item6}71 sort.Sort(ByRelevance(items))71 if items[0] != &item2 || items[1] != &item1 ||72 items[2] != &item6 || items[3] != &item4 ||73 items[4] != &item5 || items[5] != &item3 {72 if items[0] != &item6 || items[1] != &item4 ||73 items[2] != &item5 || items[3] != &item3 ||74 items[4] != &item2 || items[5] != &item1 {75 t.Error(items)76 }77}78
27 unmodified lines
modified:src/item.go+3 added
61 unmodified lines
62 }63 matchlen += end - begin64 }65 }66 if matchlen == 0 {67 matchlen = math.MaxUint1668 }69 var tiebreak uint1670 switch rankTiebreak {71 case byLength:72 // It is guaranteed that .transformed in not null in normal execution
199 unmodified lines
modified:src/pattern.go+8 added-5 removed
321 unmodified lines
322323func (p *Pattern) extendedMatch(item *Item) []Offset {324 input := p.prepareInput(item)325 offsets := []Offset{}326Loop:326 for _, termSet := range p.termSets {327 var offset *Offset328 for _, term := range termSet {329 pfun := p.procFun[term.typ]330 if sidx, eidx, tlen := p.iter(pfun, input, term.caseSensitive, p.forward, term.text); sidx >= 0 {331 if term.inv {332 break Loop332 continue333 }334 offsets = append(offsets, Offset{int32(sidx), int32(eidx), int32(tlen)})334 offset = &Offset{int32(sidx), int32(eidx), int32(tlen)}335 break336 } else if term.inv {337 offsets = append(offsets, Offset{0, 0, 0})338 break337 offset = &Offset{0, 0, 0}338 continue339 }340 }341 if offset != nil {342 offsets = append(offsets, *offset)343 }344 }345 return offsets346}347
26 unmodified lines
modified:test/test_go.rb+6 added
931 unmodified lines
932 assert_equal 2, `seq 123 | #{FZF} -f 13 -e`.lines.length933 assert_equal 4, `seq 123 | #{FZF} -f 13 +e`.lines.length934 end935936 def test_or_operator937 assert_equal %w[1 5 10], `seq 10 | #{FZF} -f "1 | 5"`.lines.map(&:chomp)938 assert_equal %w[1 10 2 3 4 5 6 7 8 9],939 `seq 10 | #{FZF} -f '1 | !1'`.lines.map(&:chomp)940 end941942private943 def writelines path, lines944 File.unlink path while File.exists? path945 File.open(path, 'w') { |f| f << lines.join($/) }
253 unmodified lines