m/fzf
1
0
mirror of https://github.com/junegunn/fzf.git synced 2025-11-15 14:53:47 -05:00

Fix race conditions

- Wait for completions of goroutines when cancelling a search
- Remove shared access to rank field of Item
This commit is contained in:
Junegunn Choi
2015-01-11 23:49:12 +09:00
parent 1db68a3976
commit 9dbf6b02d2
7 changed files with 49 additions and 23 deletions

View File

@@ -31,13 +31,13 @@ func TestRankComparison(t *testing.T) {
// Match length, string length, index
func TestItemRank(t *testing.T) {
strs := []string{"foo", "foobar", "bar", "baz"}
item1 := Item{text: &strs[0], rank: Rank{0, 0, 1}, offsets: []Offset{}}
rank1 := item1.Rank()
item1 := Item{text: &strs[0], index: 1, offsets: []Offset{}}
rank1 := item1.Rank(true)
if rank1.matchlen != 0 || rank1.strlen != 3 || rank1.index != 1 {
t.Error(item1.Rank())
t.Error(item1.Rank(true))
}
// Only differ in index
item2 := Item{text: &strs[0], rank: Rank{0, 0, 0}, offsets: []Offset{}}
item2 := Item{text: &strs[0], index: 0, offsets: []Offset{}}
items := []*Item{&item1, &item2}
sort.Sort(ByRelevance(items))