From e293cd4d088ec1fc4b6a7b14a19825138a20c597 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sun, 11 Jan 2015 02:20:54 +0900 Subject: [PATCH] Add test cases for ChunkCache --- src/cache_test.go | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/cache_test.go diff --git a/src/cache_test.go b/src/cache_test.go new file mode 100644 index 0000000..2a8b048 --- /dev/null +++ b/src/cache_test.go @@ -0,0 +1,40 @@ +package fzf + +import "testing" + +func TestChunkCache(t *testing.T) { + cache := NewChunkCache() + chunk2 := make(Chunk, CHUNK_SIZE) + chunk1p := &Chunk{} + chunk2p := &chunk2 + items1 := []*Item{&Item{}} + items2 := []*Item{&Item{}, &Item{}} + cache.Add(chunk1p, "foo", items1) + cache.Add(chunk2p, "foo", items1) + cache.Add(chunk2p, "bar", items2) + + { // chunk1 is not full + cached, found := cache.Find(chunk1p, "foo") + if found { + t.Error("Cached disabled for non-empty chunks", found, cached) + } + } + { + cached, found := cache.Find(chunk2p, "foo") + if !found || len(cached) != 1 { + t.Error("Expected 1 item cached", found, cached) + } + } + { + cached, found := cache.Find(chunk2p, "bar") + if !found || len(cached) != 2 { + t.Error("Expected 2 items cached", found, cached) + } + } + { + cached, found := cache.Find(chunk1p, "foobar") + if found { + t.Error("Expected 0 item cached", found, cached) + } + } +}