mirror of
https://github.com/junegunn/fzf.git
synced 2025-12-09 22:25:41 +08:00
> wc -l /tmp/list2
2594098 /tmp/list2
> time cat /tmp/list2 | fzf-0.10.1-darwin_amd64 -fqwerty > /dev/null
real 0m5.418s
user 0m10.990s
sys 0m1.302s
> time cat /tmp/list2 | fzf-head -fqwerty > /dev/null
real 0m4.862s
user 0m6.619s
sys 0m0.982s
57 lines
1.1 KiB
Go
57 lines
1.1 KiB
Go
package fzf
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/junegunn/fzf/src/util"
|
|
)
|
|
|
|
func TestReadFromCommand(t *testing.T) {
|
|
strs := []string{}
|
|
eb := util.NewEventBox()
|
|
reader := Reader{
|
|
pusher: func(s []rune) bool { strs = append(strs, string(s)); return true },
|
|
eventBox: eb}
|
|
|
|
// Check EventBox
|
|
if eb.Peek(EvtReadNew) {
|
|
t.Error("EvtReadNew 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.Peek(EvtReadNew) {
|
|
t.Error("EvtReadNew should be set yet")
|
|
}
|
|
|
|
// Wait should return immediately
|
|
eb.Wait(func(events *util.Events) {
|
|
if _, found := (*events)[EvtReadNew]; !found {
|
|
t.Errorf("%s", events)
|
|
}
|
|
events.Clear()
|
|
})
|
|
|
|
// EventBox is cleared
|
|
if eb.Peek(EvtReadNew) {
|
|
t.Error("EvtReadNew 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.Peek(EvtReadNew) {
|
|
t.Error("Command failed. EvtReadNew should be set")
|
|
}
|
|
}
|