split src/devices/input into src/devices/input/{raw,wrap}
This commit is contained in:
45
src/device/input/wrap/refresh_test.go
Normal file
45
src/device/input/wrap/refresh_test.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package wrap
|
||||
|
||||
import (
|
||||
"mayhem-party/src/device/input/raw"
|
||||
"os"
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestRefresh(t *testing.T) {
|
||||
b := byte('a')
|
||||
generator := func() Wrap {
|
||||
b += byte(1)
|
||||
return explicit{src: raw.NewRandom(func() byte { return b })}
|
||||
}
|
||||
ch := make(chan os.Signal, 1)
|
||||
defer close(ch)
|
||||
refresh := NewRefresh(generator, ch)
|
||||
defer refresh.Close()
|
||||
|
||||
assertIts := func(t *testing.T, b byte) {
|
||||
for i := 0; i < 10; i++ {
|
||||
some := false
|
||||
for j, button := range refresh.Read() {
|
||||
some = true
|
||||
if button.Char != b {
|
||||
t.Error(i, j, b, button)
|
||||
}
|
||||
}
|
||||
if !some {
|
||||
t.Error("empty read")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
t.Run("called once on init", func(t *testing.T) {
|
||||
assertIts(t, byte('b'))
|
||||
})
|
||||
ch <- syscall.SIGUSR1
|
||||
time.Sleep(time.Millisecond * 450)
|
||||
t.Run("called once on signal", func(t *testing.T) {
|
||||
assertIts(t, byte('c'))
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user