summaryrefslogtreecommitdiffstats
path: root/src/result_test.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2017-07-16 23:31:19 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2017-07-16 23:34:32 +0900
commit9e85cba0d06025983a1a747bfc06c9955388d9c0 (patch)
tree8fe8dc1fd62ad3ecfbfd02e440fac6cfedcd313c /src/result_test.go
parent4b59ced08f1d417530a25af8fe13aa5d40579220 (diff)
Reduce memory footprint of Item struct
Diffstat (limited to 'src/result_test.go')
-rw-r--r--src/result_test.go24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/result_test.go b/src/result_test.go
index ad510c25..8c746911 100644
--- a/src/result_test.go
+++ b/src/result_test.go
@@ -11,6 +11,11 @@ import (
"github.com/junegunn/fzf/src/util"
)
+func withIndex(i *Item, index int) *Item {
+ (*i).text.Index = int32(index)
+ return i
+}
+
func TestOffsetSort(t *testing.T) {
offsets := []Offset{
Offset{3, 5}, Offset{2, 7},
@@ -52,12 +57,13 @@ 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, trimLength: -1}, []Offset{}, 2)
+ item1 := buildResult(
+ withIndex(&Item{text: util.RunesToChars(strs[0])}, 1), []Offset{}, 2)
if item1.rank.points[0] != math.MaxUint16-2 || // Bonus
item1.rank.points[1] != 3 || // Length
item1.rank.points[2] != 0 || // Unused
item1.rank.points[3] != 0 || // Unused
- item1.item.index != 1 {
+ item1.item.Index() != 1 {
t.Error(item1.rank)
}
// Only differ in index
@@ -73,14 +79,18 @@ func TestResultRank(t *testing.T) {
sort.Sort(ByRelevance(items))
if items[0] != item2 || items[1] != item2 ||
items[2] != item1 || items[3] != item1 {
- t.Error(items, item1, item1.item.index, item2, item2.item.index)
+ t.Error(items, item1, item1.item.Index(), item2, item2.item.Index())
}
// Sort by relevance
- 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)
+ item3 := buildResult(
+ withIndex(&Item{}, 2), []Offset{Offset{1, 3}, Offset{5, 7}}, 3)
+ item4 := buildResult(
+ withIndex(&Item{}, 2), []Offset{Offset{1, 2}, Offset{6, 7}}, 4)
+ item5 := buildResult(
+ withIndex(&Item{}, 2), []Offset{Offset{1, 3}, Offset{5, 7}}, 5)
+ item6 := buildResult(
+ withIndex(&Item{}, 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 &&