2015-01-10 17:20:54 +00:00
|
|
|
package fzf
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
func TestChunkCache(t *testing.T) {
|
|
|
|
cache := NewChunkCache()
|
2015-04-17 13:23:52 +00:00
|
|
|
chunk2 := make(Chunk, chunkSize)
|
2015-01-10 17:20:54 +00:00
|
|
|
chunk1p := &Chunk{}
|
|
|
|
chunk2p := &chunk2
|
2016-08-18 17:39:32 +00:00
|
|
|
items1 := []*Result{&Result{}}
|
|
|
|
items2 := []*Result{&Result{}, &Result{}}
|
2015-01-10 17:20:54 +00:00
|
|
|
cache.Add(chunk1p, "foo", items1)
|
|
|
|
cache.Add(chunk2p, "foo", items1)
|
|
|
|
cache.Add(chunk2p, "bar", items2)
|
|
|
|
|
|
|
|
{ // chunk1 is not full
|
2017-07-16 14:31:19 +00:00
|
|
|
cached := cache.Lookup(chunk1p, "foo")
|
|
|
|
if cached != nil {
|
|
|
|
t.Error("Cached disabled for non-empty chunks", cached)
|
2015-01-10 17:20:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
2017-07-16 14:31:19 +00:00
|
|
|
cached := cache.Lookup(chunk2p, "foo")
|
|
|
|
if cached == nil || len(cached) != 1 {
|
|
|
|
t.Error("Expected 1 item cached", cached)
|
2015-01-10 17:20:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
2017-07-16 14:31:19 +00:00
|
|
|
cached := cache.Lookup(chunk2p, "bar")
|
|
|
|
if cached == nil || len(cached) != 2 {
|
|
|
|
t.Error("Expected 2 items cached", cached)
|
2015-01-10 17:20:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
{
|
2017-07-16 14:31:19 +00:00
|
|
|
cached := cache.Lookup(chunk1p, "foobar")
|
|
|
|
if cached != nil {
|
|
|
|
t.Error("Expected 0 item cached", cached)
|
2015-01-10 17:20:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|