-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlive_test.go
64 lines (49 loc) · 1.12 KB
/
live_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package balafon_test
import (
"bytes"
"testing"
"github.com/mgnsk/balafon"
"github.com/mgnsk/balafon/internal/constants"
. "github.com/onsi/gomega"
"gitlab.com/gomidi/midi/v2"
"gitlab.com/gomidi/midi/v2/drivers"
)
type out struct {
drivers.Port
buf *bytes.Buffer
}
func (o *out) Send(b []byte) error {
if o.buf != nil {
o.buf.Write(b)
}
return nil
}
type reader struct{}
func (*reader) Read(p []byte) (int, error) {
p[0] = 'a'
return 1, nil
}
func TestLiveShell(t *testing.T) {
g := NewWithT(t)
it := balafon.New()
g.Expect(it.EvalString(":assign a 60")).To(Succeed())
buf := &bytes.Buffer{}
s := balafon.NewLiveShell(&reader{}, it, &out{buf: buf})
g.Expect(s.HandleNext()).To(Succeed())
msg := midi.Message(buf.Bytes())
g.Expect(msg).To(Equal(midi.NoteOn(0, 60, constants.DefaultVelocity)))
}
func BenchmarkLiveShell(b *testing.B) {
it := balafon.New()
if err := it.EvalString(":assign a 60"); err != nil {
b.Fatal(err)
}
s := balafon.NewLiveShell(&reader{}, it, &out{})
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
if err := s.HandleNext(); err != nil {
b.Fatal(err)
}
}
}