summaryrefslogtreecommitdiffstats
path: root/src/chunklist_test.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2015-01-02 04:49:30 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2015-01-04 00:37:29 +0900
commitf3177305d5572b26f135fc045481358b4eb1bf69 (patch)
treed59fd9587e44e998581a131875bf45e243df6c6e /src/chunklist_test.go
parent7ba93d9f8351be64b37c65ae04d594ee261d5d26 (diff)
Rewrite fzf in Go
Diffstat (limited to 'src/chunklist_test.go')
-rw-r--r--src/chunklist_test.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/chunklist_test.go b/src/chunklist_test.go
new file mode 100644
index 00000000..a7daa47e
--- /dev/null
+++ b/src/chunklist_test.go
@@ -0,0 +1,66 @@
+package fzf
+
+import (
+ "fmt"
+ "testing"
+)
+
+func TestChunkList(t *testing.T) {
+ cl := NewChunkList(func(s *string, i int) *Item {
+ return &Item{text: s, index: i * 2}
+ })
+
+ // Snapshot
+ snapshot := cl.Snapshot()
+ if len(snapshot) > 0 {
+ t.Error("Snapshot should be empty now")
+ }
+
+ // Add some data
+ cl.Push("hello")
+ cl.Push("world")
+
+ // Previously created snapshot should remain the same
+ if len(snapshot) > 0 {
+ t.Error("Snapshot should not have changed")
+ }
+
+ // But the new snapshot should contain the added items
+ snapshot = cl.Snapshot()
+ if len(snapshot) != 1 {
+ t.Error("Snapshot should not be empty now")
+ }
+
+ // Check the content of the ChunkList
+ chunk1 := snapshot[0]
+ if len(*chunk1) != 2 {
+ t.Error("Snapshot should contain only two items")
+ }
+ if *(*chunk1)[0].text != "hello" || (*chunk1)[0].index != 0 ||
+ *(*chunk1)[1].text != "world" || (*chunk1)[1].index != 2 {
+ t.Error("Invalid data")
+ }
+ if chunk1.IsFull() {
+ t.Error("Chunk should not have been marked full yet")
+ }
+
+ // Add more data
+ for i := 0; i < CHUNK_SIZE*2; i++ {
+ cl.Push(fmt.Sprintf("item %d", i))
+ }
+
+ // Previous snapshot should remain the same
+ if len(snapshot) != 1 {
+ t.Error("Snapshot should stay the same")
+ }
+
+ // New snapshot
+ snapshot = cl.Snapshot()
+ if len(snapshot) != 3 || !snapshot[0].IsFull() ||
+ !snapshot[1].IsFull() || snapshot[2].IsFull() {
+ t.Error("Expected two full chunks and one more chunk")
+ }
+ if len(*snapshot[2]) != 2 {
+ t.Error("Unexpected number of items")
+ }
+}