Remove special nilItem

This commit is contained in:
Junegunn Choi
2017-08-15 01:10:41 +09:00
parent 2069bbc8b5
commit 0d171ba1d8
9 changed files with 49 additions and 51 deletions

View File

@@ -11,10 +11,10 @@ func TestChunkList(t *testing.T) {
// FIXME global
sortCriteria = []criterion{byScore, byLength}
cl := NewChunkList(func(s []byte, i int) Item {
chars := util.ToChars(s)
chars.Index = int32(i * 2)
return Item{text: chars}
cl := NewChunkList(func(item *Item, s []byte, i int) bool {
item.text = util.ToChars(s)
item.text.Index = int32(i * 2)
return true
})
// Snapshot
@@ -40,11 +40,13 @@ func TestChunkList(t *testing.T) {
// Check the content of the ChunkList
chunk1 := snapshot[0]
if len(*chunk1) != 2 {
if chunk1.count != 2 {
t.Error("Snapshot should contain only two items")
}
if (*chunk1)[0].text.ToString() != "hello" || (*chunk1)[0].Index() != 0 ||
(*chunk1)[1].text.ToString() != "world" || (*chunk1)[1].Index() != 2 {
if chunk1.items[0].text.ToString() != "hello" ||
chunk1.items[0].Index() != 0 ||
chunk1.items[1].text.ToString() != "world" ||
chunk1.items[1].Index() != 2 {
t.Error("Invalid data")
}
if chunk1.IsFull() {
@@ -67,14 +69,14 @@ func TestChunkList(t *testing.T) {
!snapshot[1].IsFull() || snapshot[2].IsFull() || count != chunkSize*2+2 {
t.Error("Expected two full chunks and one more chunk")
}
if len(*snapshot[2]) != 2 {
if snapshot[2].count != 2 {
t.Error("Unexpected number of items")
}
cl.Push([]byte("hello"))
cl.Push([]byte("world"))
lastChunkCount := len(*snapshot[len(snapshot)-1])
lastChunkCount := snapshot[len(snapshot)-1].count
if lastChunkCount != 2 {
t.Error("Unexpected number of items:", lastChunkCount)
}