Skip to content
Myr

reader_test.go

This file

Path

src/reader_test.go

64 lines · 1.3 KiB · Go

Last changed by

Make Reader event notification asynchronousJunegunn Choibefore adoption487c8fe

History of this file

Take it

The walk stopped after 200 commits: lines older than a3244c4 point at it.

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 1–4why, one step back
1package fzf
23import (4 "testing"

Make Reader event notification asynchronousJunegunn Choibefore adoption487c8fe

line 5why, one step back
5 "time"

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 6–14why, one step back
6
7 "github.com/junegunn/fzf/src/util"8)910func TestReadFromCommand(t *testing.T) {11 strs := []string{}12 eb := util.NewEventBox()13 reader := Reader{14 pusher: func(s []byte) bool { strs = append(strs, string(s)); return true },

Make Reader event notification asynchronousJunegunn Choibefore adoption487c8fe

lines 15–16why, one step back
15 eventBox: eb,
16 event: int32(EvtReady)}

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

line 17why, one step back
17

Make Reader event notification asynchronousJunegunn Choibefore adoption487c8fe

lines 18–19why, one step back
18 reader.startEventPoller()
19

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 20–25why, one step back
20 // Check EventBox
21 if eb.Peek(EvtReadNew) {22 t.Error("EvtReadNew should not be set yet")23 }2425 // Normal command

Make Reader event notification asynchronousJunegunn Choibefore adoption487c8fe

line 26why, one step back
26 reader.fin(reader.readFromCommand(`echo abc && echo def`))

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 27–31why, one step back
27 if len(strs) != 2 || strs[0] != "abc" || strs[1] != "def" {
28 t.Errorf("%s", strs)29 }3031 // Check EventBox again

Make Reader event notification asynchronousJunegunn Choibefore adoption487c8fe

line 32why, one step back
32 eb.WaitFor(EvtReadFin)

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 33–43why, one step back
33
34 // Wait should return immediately35 eb.Wait(func(events *util.Events) {36 events.Clear()37 })3839 // EventBox is cleared40 if eb.Peek(EvtReadNew) {41 t.Error("EvtReadNew should not be set yet")42 }43

Make Reader event notification asynchronousJunegunn Choibefore adoption487c8fe

lines 44–49why, one step back
44 // Make sure that event poller is finished
45 time.Sleep(readerPollIntervalMax)4647 // Restart event poller48 reader.startEventPoller()49

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

line 50why, one step back
50 // Failing command

Make Reader event notification asynchronousJunegunn Choibefore adoption487c8fe

line 51why, one step back
51 reader.fin(reader.readFromCommand(`no-such-command`))

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 52–58why, one step back
52 strs = []string{}
53 if len(strs) > 0 {54 t.Errorf("%s", strs)55 }5657 // Check EventBox again58 if eb.Peek(EvtReadNew) {

Make Reader event notification asynchronousJunegunn Choibefore adoption487c8fe

lines 59–62why, one step back
59 t.Error("Command failed. EvtReadNew should not be set")
60 }61 if !eb.Peek(EvtReadFin) {62 t.Error("EvtReadFin should be set")

Delete every line below the cursorJunegunn Choibefore adoptiona3244c4

lines 63–64why, one step back
63 }
64}