split src/devices/input into src/devices/input/{raw,wrap}

This commit is contained in:
bel
2023-03-24 19:51:38 -06:00
parent ab673a81f0
commit 38b00e55b0
16 changed files with 161 additions and 159 deletions

View 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'))
})
}