From e557734c832731a87fcb3fc327926b0c926a2013 Mon Sep 17 00:00:00 2001 From: saxon Date: Tue, 22 Jan 2019 10:45:36 +1030 Subject: [PATCH] av/stream/flac: added writeseeker tests --- stream/flac/flac_test.go | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/stream/flac/flac_test.go b/stream/flac/flac_test.go index d69c0494..9537d682 100644 --- a/stream/flac/flac_test.go +++ b/stream/flac/flac_test.go @@ -27,6 +27,7 @@ LICENSE package flac import ( + "io" "io/ioutil" "os" "testing" @@ -37,6 +38,49 @@ const ( outFile = "testOut.wav" ) +func TestWriteSeekerWrite(t *testing.T) { + writerSeeker := &writeSeeker{} + var ws io.WriteSeeker = writerSeeker + + ws.Write([]byte("hello")) + if string(writerSeeker.buf) != "hello" { + t.Fail() + } + + ws.Write([]byte(" world")) + if string(writerSeeker.buf) != "hello world" { + t.Fail() + } + +} + +func TestWriteSeekerSeek(t *testing.T) { + writerSeeker := &writeSeeker{} + var ws io.WriteSeeker = writerSeeker + + ws.Write([]byte("hello")) + if string(writerSeeker.buf) != "hello" { + t.Fail() + } + + ws.Write([]byte(" world")) + if string(writerSeeker.buf) != "hello world" { + t.Fail() + } + + ws.Seek(-2, io.SeekEnd) + ws.Write([]byte("k!")) + if string(writerSeeker.buf) != "hello work!" { + t.Fail() + } + + ws.Seek(6, io.SeekStart) + ws.Write([]byte("gopher")) + if string(writerSeeker.buf) != "hello gopher" { + t.Fail() + } +} + func TestDecodeFlac(t *testing.T) { b, err := ioutil.ReadFile(testFile) if err != nil {