diff options
author | Junegunn Choi <junegunn.c@gmail.com> | 2017-06-02 13:25:35 +0900 |
---|---|---|
committer | Junegunn Choi <junegunn.c@gmail.com> | 2017-06-02 13:25:35 +0900 |
commit | 2e3dc75425d23b4d9e8e05a901395914cf8d3120 (patch) | |
tree | baccbb0305c7337b95207945c55d5e33f726c55b /src/result_test.go | |
parent | 5d6eb5bfd64c6d5d773c71159d819b651dd5f7f1 (diff) |
Fix inconsistent tiebreak scores when --nth is used
Make sure to consistently calculate tiebreak scores based on the
original line.
This change may not be preferable if you filter aligned tabular input on
a subset of columns using --nth. However, if we calculate length
tiebreak only on the matched components instead of the entire line, the
result can be very confusing when multiple --nth components are
specified, so let's keep it simple and consistent.
Close #926
Diffstat (limited to 'src/result_test.go')
-rw-r--r-- | src/result_test.go | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/result_test.go b/src/result_test.go index 0e91fc87..ad510c25 100644 --- a/src/result_test.go +++ b/src/result_test.go @@ -52,7 +52,7 @@ func TestResultRank(t *testing.T) { sortCriteria = []criterion{byScore, byLength} strs := [][]rune{[]rune("foo"), []rune("foobar"), []rune("bar"), []rune("baz")} - item1 := buildResult(&Item{text: util.RunesToChars(strs[0]), index: 1}, []Offset{}, 2, 3) + item1 := buildResult(&Item{text: util.RunesToChars(strs[0]), index: 1, trimLength: -1}, []Offset{}, 2) if item1.rank.points[0] != math.MaxUint16-2 || // Bonus item1.rank.points[1] != 3 || // Length item1.rank.points[2] != 0 || // Unused @@ -61,7 +61,7 @@ func TestResultRank(t *testing.T) { t.Error(item1.rank) } // Only differ in index - item2 := buildResult(&Item{text: util.RunesToChars(strs[0])}, []Offset{}, 2, 3) + item2 := buildResult(&Item{text: util.RunesToChars(strs[0])}, []Offset{}, 2) items := []*Result{item1, item2} sort.Sort(ByRelevance(items)) @@ -77,10 +77,10 @@ func TestResultRank(t *testing.T) { } // Sort by relevance - item3 := buildResult(&Item{index: 2}, []Offset{Offset{1, 3}, Offset{5, 7}}, 3, 0) - item4 := buildResult(&Item{index: 2}, []Offset{Offset{1, 2}, Offset{6, 7}}, 4, 0) - item5 := buildResult(&Item{index: 2}, []Offset{Offset{1, 3}, Offset{5, 7}}, 5, 0) - item6 := buildResult(&Item{index: 2}, []Offset{Offset{1, 2}, Offset{6, 7}}, 6, 0) + item3 := buildResult(&Item{index: 2}, []Offset{Offset{1, 3}, Offset{5, 7}}, 3) + item4 := buildResult(&Item{index: 2}, []Offset{Offset{1, 2}, Offset{6, 7}}, 4) + item5 := buildResult(&Item{index: 2}, []Offset{Offset{1, 3}, Offset{5, 7}}, 5) + item6 := buildResult(&Item{index: 2}, []Offset{Offset{1, 2}, Offset{6, 7}}, 6) items = []*Result{item1, item2, item3, item4, item5, item6} sort.Sort(ByRelevance(items)) if !(items[0] == item6 && items[1] == item5 && |