-
Notifications
You must be signed in to change notification settings - Fork 16
/
ctrl_test.go
53 lines (40 loc) · 1.03 KB
/
ctrl_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
package beep_test
import (
"testing"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/gopxl/beep/v2"
"github.com/gopxl/beep/v2/internal/testtools"
)
func TestCtrl_CanBePausedAndUnpaused(t *testing.T) {
s, data := testtools.RandomDataStreamer(20)
ctrl := beep.Ctrl{
Streamer: s,
Paused: false,
}
got := testtools.CollectNum(10, &ctrl)
assert.Equal(t, data[:10], got)
ctrl.Paused = true
got = testtools.CollectNum(10, &ctrl)
assert.Equal(t, make([][2]float64, 10), got)
ctrl.Paused = false
got = testtools.CollectNum(10, &ctrl)
assert.Equal(t, data[10:20], got)
}
func TestCtrl_DoesNotStreamFromNilStreamer(t *testing.T) {
ctrl := beep.Ctrl{
Streamer: nil,
Paused: false,
}
buf := make([][2]float64, 10)
n, ok := ctrl.Stream(buf)
assert.Equal(t, 0, n)
assert.False(t, ok)
}
func TestCtrl_PropagatesErrors(t *testing.T) {
ctrl := beep.Ctrl{}
assert.NoError(t, ctrl.Err())
err := errors.New("oh no")
ctrl.Streamer = testtools.NewErrorStreamer(err)
assert.Equal(t, err, ctrl.Err())
}