summaryrefslogtreecommitdiff
path: root/src/util/eventbox_test.go
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2015-01-12 12:56:17 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2015-01-12 12:56:17 +0900
commitcd847affb79ea6438c9721635724efc6f58e2215 (patch)
treed1e631e3dca8832ee4c495924789f6697c3629cf /src/util/eventbox_test.go
parent7a2bc2cada971c7a390d09b0afda34780ff56fb6 (diff)
downloadfzf-cd847affb79ea6438c9721635724efc6f58e2215.tar.gz
Reorganize source code
Diffstat (limited to 'src/util/eventbox_test.go')
-rw-r--r--src/util/eventbox_test.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/util/eventbox_test.go b/src/util/eventbox_test.go
new file mode 100644
index 00000000..5a9dc302
--- /dev/null
+++ b/src/util/eventbox_test.go
@@ -0,0 +1,61 @@
+package util
+
+import "testing"
+
+// fzf events
+const (
+ EvtReadNew EventType = iota
+ EvtReadFin
+ EvtSearchNew
+ EvtSearchProgress
+ EvtSearchFin
+ EvtClose
+)
+
+func TestEventBox(t *testing.T) {
+ eb := NewEventBox()
+
+ // Wait should return immediately
+ ch := make(chan bool)
+
+ go func() {
+ eb.Set(EvtReadNew, 10)
+ ch <- true
+ <-ch
+ eb.Set(EvtSearchNew, 10)
+ eb.Set(EvtSearchNew, 15)
+ eb.Set(EvtSearchNew, 20)
+ eb.Set(EvtSearchProgress, 30)
+ ch <- true
+ <-ch
+ eb.Set(EvtSearchFin, 40)
+ ch <- true
+ <-ch
+ }()
+
+ count := 0
+ sum := 0
+ looping := true
+ for looping {
+ <-ch
+ eb.Wait(func(events *Events) {
+ for _, value := range *events {
+ switch val := value.(type) {
+ case int:
+ sum += val
+ looping = sum < 100
+ }
+ }
+ events.Clear()
+ })
+ ch <- true
+ count++
+ }
+
+ if count != 3 {
+ t.Error("Invalid number of events", count)
+ }
+ if sum != 100 {
+ t.Error("Invalid sum", sum)
+ }
+}