diff options
| author | Junegunn Choi <junegunn.c@gmail.com> | 2015-01-04 05:00:28 +0900 |
|---|---|---|
| committer | Junegunn Choi <junegunn.c@gmail.com> | 2015-01-04 05:00:28 +0900 |
| commit | 0dd024a09fc4dd37a596a07e7ff0043537895909 (patch) | |
| tree | 02f6bc4a614ed3dfe085c9d6c754385a88d58881 /src/eventbox_test.go | |
| parent | 0a6cb62169ebe1abb63aa5c70868df7c40441b1c (diff) | |
| download | fzf-0dd024a09fc4dd37a596a07e7ff0043537895909.tar.gz | |
Remove unnecessary delay on non/defered interactive mode
Diffstat (limited to 'src/eventbox_test.go')
| -rw-r--r-- | src/eventbox_test.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/eventbox_test.go b/src/eventbox_test.go new file mode 100644 index 00000000..fb0ceedf --- /dev/null +++ b/src/eventbox_test.go @@ -0,0 +1,51 @@ +package fzf + +import "testing" + +func TestEventBox(t *testing.T) { + eb := NewEventBox() + + // Wait should return immediately + ch := make(chan bool) + + go func() { + eb.Set(EVT_READ_NEW, 10) + ch <- true + <-ch + eb.Set(EVT_SEARCH_NEW, 10) + eb.Set(EVT_SEARCH_NEW, 15) + eb.Set(EVT_SEARCH_NEW, 20) + eb.Set(EVT_SEARCH_PROGRESS, 30) + ch <- true + <-ch + eb.Set(EVT_SEARCH_FIN, 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 += 1 + } + + if count != 3 { + t.Error("Invalid number of events", count) + } + if sum != 100 { + t.Error("Invalid sum", sum) + } +} |
