diff options
| author | Junegunn Choi <junegunn.c@gmail.com> | 2015-01-02 04:49:30 +0900 |
|---|---|---|
| committer | Junegunn Choi <junegunn.c@gmail.com> | 2015-01-04 00:37:29 +0900 |
| commit | f3177305d5572b26f135fc045481358b4eb1bf69 (patch) | |
| tree | d59fd9587e44e998581a131875bf45e243df6c6e /src/reader_test.go | |
| parent | 7ba93d9f8351be64b37c65ae04d594ee261d5d26 (diff) | |
| download | fzf-f3177305d5572b26f135fc045481358b4eb1bf69.tar.gz | |
Rewrite fzf in Go
Diffstat (limited to 'src/reader_test.go')
| -rw-r--r-- | src/reader_test.go | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/reader_test.go b/src/reader_test.go new file mode 100644 index 00000000..f51ccab0 --- /dev/null +++ b/src/reader_test.go @@ -0,0 +1,52 @@ +package fzf + +import "testing" + +func TestReadFromCommand(t *testing.T) { + strs := []string{} + eb := NewEventBox() + reader := Reader{ + pusher: func(s string) { strs = append(strs, s) }, + eventBox: eb} + + // Check EventBox + if eb.Peak(EVT_READ_NEW) { + t.Error("EVT_READ_NEW should not be set yet") + } + + // Normal command + reader.readFromCommand(`echo abc && echo def`) + if len(strs) != 2 || strs[0] != "abc" || strs[1] != "def" { + t.Errorf("%s", strs) + } + + // Check EventBox again + if !eb.Peak(EVT_READ_NEW) { + t.Error("EVT_READ_NEW should be set yet") + } + + // Wait should return immediately + eb.Wait(func(events *Events) { + if _, found := (*events)[EVT_READ_NEW]; !found { + t.Errorf("%s", events) + } + events.Clear() + }) + + // EventBox is cleared + if eb.Peak(EVT_READ_NEW) { + t.Error("EVT_READ_NEW should not be set yet") + } + + // Failing command + reader.readFromCommand(`no-such-command`) + strs = []string{} + if len(strs) > 0 { + t.Errorf("%s", strs) + } + + // Check EventBox again + if eb.Peak(EVT_READ_NEW) { + t.Error("Command failed. EVT_READ_NEW should be set") + } +} |
