peco.peco/reader_test.go
Daisuke Maki 933cc2fcea Remove InputReader
Upon realizing that I had written this but haven't used it in actual
peco code other than testing, I tried it: It didn't work. Well, at least
it didn't work out of the box.

I could sense a loooooong debugging session ahead, and decided it's not
worth it at this point in time. we can always re-instate it, as we have
the history of it in git
2015-03-17 15:37:50 +09:00

42 lines
691 B
Go

package peco
import (
"fmt"
"io/ioutil"
"os"
"strings"
"testing"
"time"
)
func TestReader(t *testing.T) {
ctx := NewCtx(nil)
buf := strings.NewReader(`
1. Foo
2. Bar
3. Baz
`)
rdr := ctx.NewBufferReader(ioutil.NopCloser(buf))
inputReady := false
time.AfterFunc(time.Second, func() {
fmt.Fprintf(os.Stderr, "afterfunc fired\n")
if !inputReady {
t.Errorf("inputReady not receieved even after 1 second")
close(rdr.inputReadyCh)
ctx.Stop()
}
})
go func() {
<-rdr.inputReadyCh
inputReady = true
}()
ctx.AddWaitGroup(1)
rdr.Loop()
if ctx.GetRawLineBufferSize() != 3 {
t.Errorf("Expected 3 lines from input, only got %d", ctx.GetRawLineBufferSize())
}
}