From be389fca6e004133576b37198324292e08f48a9f Mon Sep 17 00:00:00 2001 From: Trek H Date: Thu, 11 Jul 2019 14:54:06 +0930 Subject: [PATCH] syntax and style changes --- codec/codecutil/lex.go | 7 +++---- codec/codecutil/lex_test.go | 26 +++++++++++++------------- input/audio/audio.go | 2 +- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/codec/codecutil/lex.go b/codec/codecutil/lex.go index e727e07d..3414ff45 100644 --- a/codec/codecutil/lex.go +++ b/codec/codecutil/lex.go @@ -52,17 +52,16 @@ func (l *ByteLexer) Lex(dst io.Writer, src io.Reader, t time.Duration) error { if t < 0 { return fmt.Errorf("invalid delay: %v", t) } - var tick <-chan time.Time + var ticker *time.Ticker if t > 0 { - ticker := time.NewTicker(t) + ticker = time.NewTicker(t) defer ticker.Stop() - tick = ticker.C } buf := make([]byte, bufSize) for { if t != 0 { - <-tick + <-ticker.C } off, err := src.Read(buf) if err != nil { diff --git a/codec/codecutil/lex_test.go b/codec/codecutil/lex_test.go index 63162abd..70fd3d39 100644 --- a/codec/codecutil/lex_test.go +++ b/codec/codecutil/lex_test.go @@ -33,18 +33,18 @@ import ( ) var lexTests = []struct { - data []byte - t time.Duration - n int - fail bool // Whether or not this test should fail. + data []byte + t time.Duration + n int + 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, 3, false}, - {[]byte{0x10, 0x00, 0xf3, 0x45, 0xfe, 0xd2, 0xaa, 0x4e}, time.Duration(0), 2, false}, - {[]byte{0x10, 0x00, 0xf3, 0x45, 0xfe, 0xd2, 0xaa, 0x4e}, time.Duration(0), 1, false}, - {[]byte{0x10, 0x00, 0xf3, 0x45, 0xfe, 0xd2, 0xaa, 0x4e}, time.Nanosecond, 0, true}, - {[]byte{0x10, 0x00, 0xf3, 0x45, 0xfe, 0xd2, 0xaa, 0x4e}, time.Millisecond, -1, true}, - {[]byte{0x10, 0x00, 0xf3, 0x45, 0xfe, 0xd2, 0xaa, 0x4e}, time.Millisecond, 15, 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, true}, + {[]byte{0x10, 0x00, 0xf3, 0x45, 0xfe, 0xd2, 0xaa, 0x4e}, 0, 2, true}, + {[]byte{0x10, 0x00, 0xf3, 0x45, 0xfe, 0xd2, 0xaa, 0x4e}, 0, 1, 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, false}, + {[]byte{0x10, 0x00, 0xf3, 0x45, 0xfe, 0xd2, 0xaa, 0x4e}, time.Millisecond, 15, true}, } func TestByteLexer(t *testing.T) { @@ -54,8 +54,8 @@ func TestByteLexer(t *testing.T) { l := NewByteLexer(&tt.n) err := l.Lex(dst, bytes.NewReader(tt.data), tt.t) if err != nil && err != io.EOF { - if !tt.fail { - t.Errorf("unexpected error: %v", err.Error()) + if tt.isValid { + t.Errorf("unexpected error: %v", err) } } 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()) diff --git a/input/audio/audio.go b/input/audio/audio.go index 9c80237b..54edb00c 100644 --- a/input/audio/audio.go +++ b/input/audio/audio.go @@ -54,7 +54,7 @@ const ( // "paused" means the input routine is sleeping until unpaused or stopped. // "stopped" means the input routine is stopped and the ALSA device is closed. const ( - running = iota + running = iota + 1 paused stopped )