2015-08-23 23:57:54 +00:00
|
|
|
package gatedwriter
|
2015-08-16 20:54:49 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
2015-08-23 23:57:54 +00:00
|
|
|
func TestWriter_impl(t *testing.T) {
|
|
|
|
var _ io.Writer = new(Writer)
|
2015-08-16 20:54:49 +00:00
|
|
|
}
|
|
|
|
|
2015-08-23 23:57:54 +00:00
|
|
|
func TestWriter(t *testing.T) {
|
2015-08-16 20:54:49 +00:00
|
|
|
buf := new(bytes.Buffer)
|
2015-08-23 23:57:54 +00:00
|
|
|
w := &Writer{Writer: buf}
|
2015-08-16 20:54:49 +00:00
|
|
|
w.Write([]byte("foo\n"))
|
|
|
|
w.Write([]byte("bar\n"))
|
|
|
|
|
|
|
|
if buf.String() != "" {
|
|
|
|
t.Fatalf("bad: %s", buf.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
w.Flush()
|
|
|
|
|
|
|
|
if buf.String() != "foo\nbar\n" {
|
|
|
|
t.Fatalf("bad: %s", buf.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
w.Write([]byte("baz\n"))
|
|
|
|
|
|
|
|
if buf.String() != "foo\nbar\nbaz\n" {
|
|
|
|
t.Fatalf("bad: %s", buf.String())
|
|
|
|
}
|
|
|
|
}
|