mirror of https://bitbucket.org/ausocean/av.git
syntax and style changes
This commit is contained in:
parent
d48a11794b
commit
be389fca6e
|
@ -52,17 +52,16 @@ func (l *ByteLexer) Lex(dst io.Writer, src io.Reader, t time.Duration) error {
|
||||||
if t < 0 {
|
if t < 0 {
|
||||||
return fmt.Errorf("invalid delay: %v", t)
|
return fmt.Errorf("invalid delay: %v", t)
|
||||||
}
|
}
|
||||||
var tick <-chan time.Time
|
var ticker *time.Ticker
|
||||||
if t > 0 {
|
if t > 0 {
|
||||||
ticker := time.NewTicker(t)
|
ticker = time.NewTicker(t)
|
||||||
defer ticker.Stop()
|
defer ticker.Stop()
|
||||||
tick = ticker.C
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buf := make([]byte, bufSize)
|
buf := make([]byte, bufSize)
|
||||||
for {
|
for {
|
||||||
if t != 0 {
|
if t != 0 {
|
||||||
<-tick
|
<-ticker.C
|
||||||
}
|
}
|
||||||
off, err := src.Read(buf)
|
off, err := src.Read(buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -33,18 +33,18 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var lexTests = []struct {
|
var lexTests = []struct {
|
||||||
data []byte
|
data []byte
|
||||||
t time.Duration
|
t time.Duration
|
||||||
n int
|
n int
|
||||||
fail bool // Whether or not this test should fail.
|
isValid bool // Whether or not this test should fail.
|
||||||
}{
|
}{
|
||||||
{[]byte{0x10, 0x00, 0xf3, 0x45, 0xfe, 0xd2, 0xaa, 0x4e}, time.Millisecond, 4, false},
|
{[]byte{0x10, 0x00, 0xf3, 0x45, 0xfe, 0xd2, 0xaa, 0x4e}, time.Millisecond, 4, true},
|
||||||
{[]byte{0x10, 0x00, 0xf3, 0x45, 0xfe, 0xd2, 0xaa, 0x4e}, time.Millisecond, 3, false},
|
{[]byte{0x10, 0x00, 0xf3, 0x45, 0xfe, 0xd2, 0xaa, 0x4e}, time.Millisecond, 3, true},
|
||||||
{[]byte{0x10, 0x00, 0xf3, 0x45, 0xfe, 0xd2, 0xaa, 0x4e}, time.Duration(0), 2, false},
|
{[]byte{0x10, 0x00, 0xf3, 0x45, 0xfe, 0xd2, 0xaa, 0x4e}, 0, 2, true},
|
||||||
{[]byte{0x10, 0x00, 0xf3, 0x45, 0xfe, 0xd2, 0xaa, 0x4e}, time.Duration(0), 1, false},
|
{[]byte{0x10, 0x00, 0xf3, 0x45, 0xfe, 0xd2, 0xaa, 0x4e}, 0, 1, true},
|
||||||
{[]byte{0x10, 0x00, 0xf3, 0x45, 0xfe, 0xd2, 0xaa, 0x4e}, time.Nanosecond, 0, true},
|
{[]byte{0x10, 0x00, 0xf3, 0x45, 0xfe, 0xd2, 0xaa, 0x4e}, time.Nanosecond, 0, false},
|
||||||
{[]byte{0x10, 0x00, 0xf3, 0x45, 0xfe, 0xd2, 0xaa, 0x4e}, time.Millisecond, -1, true},
|
{[]byte{0x10, 0x00, 0xf3, 0x45, 0xfe, 0xd2, 0xaa, 0x4e}, time.Millisecond, -1, false},
|
||||||
{[]byte{0x10, 0x00, 0xf3, 0x45, 0xfe, 0xd2, 0xaa, 0x4e}, time.Millisecond, 15, false},
|
{[]byte{0x10, 0x00, 0xf3, 0x45, 0xfe, 0xd2, 0xaa, 0x4e}, time.Millisecond, 15, true},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestByteLexer(t *testing.T) {
|
func TestByteLexer(t *testing.T) {
|
||||||
|
@ -54,8 +54,8 @@ func TestByteLexer(t *testing.T) {
|
||||||
l := NewByteLexer(&tt.n)
|
l := NewByteLexer(&tt.n)
|
||||||
err := l.Lex(dst, bytes.NewReader(tt.data), tt.t)
|
err := l.Lex(dst, bytes.NewReader(tt.data), tt.t)
|
||||||
if err != nil && err != io.EOF {
|
if err != nil && err != io.EOF {
|
||||||
if !tt.fail {
|
if tt.isValid {
|
||||||
t.Errorf("unexpected error: %v", err.Error())
|
t.Errorf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
} else if !bytes.Equal(dst.Bytes(), tt.data) {
|
} else if !bytes.Equal(dst.Bytes(), tt.data) {
|
||||||
t.Errorf("data before and after lex are not equal: want %v, got %v", tt.data, dst.Bytes())
|
t.Errorf("data before and after lex are not equal: want %v, got %v", tt.data, dst.Bytes())
|
||||||
|
|
|
@ -54,7 +54,7 @@ const (
|
||||||
// "paused" means the input routine is sleeping until unpaused or stopped.
|
// "paused" means the input routine is sleeping until unpaused or stopped.
|
||||||
// "stopped" means the input routine is stopped and the ALSA device is closed.
|
// "stopped" means the input routine is stopped and the ALSA device is closed.
|
||||||
const (
|
const (
|
||||||
running = iota
|
running = iota + 1
|
||||||
paused
|
paused
|
||||||
stopped
|
stopped
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue