2013-09-20 13:21:59 -04:00
|
|
|
package shell
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"io"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestUnixReader_impl(t *testing.T) {
|
|
|
|
var raw interface{}
|
|
|
|
raw = new(UnixReader)
|
|
|
|
if _, ok := raw.(io.Reader); !ok {
|
|
|
|
t.Fatal("should be reader")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestUnixReader(t *testing.T) {
|
|
|
|
input := "one\r\ntwo\nthree\r\n"
|
|
|
|
expected := "one\ntwo\nthree\n"
|
|
|
|
|
|
|
|
r := &UnixReader{
|
|
|
|
Reader: bytes.NewReader([]byte(input)),
|
|
|
|
}
|
|
|
|
|
|
|
|
result := new(bytes.Buffer)
|
|
|
|
if _, err := io.Copy(result, r); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if result.String() != expected {
|
|
|
|
t.Fatalf("bad: %#v", result.String())
|
|
|
|
}
|
|
|
|
}
|
2013-09-30 14:39:24 -04:00
|
|
|
|
|
|
|
func TestUnixReader_unixOnly(t *testing.T) {
|
2013-10-01 05:06:01 -04:00
|
|
|
input := "one\n\ntwo\nthree\n"
|
|
|
|
expected := "one\n\ntwo\nthree\n"
|
2013-09-30 14:39:24 -04:00
|
|
|
|
|
|
|
r := &UnixReader{
|
|
|
|
Reader: bytes.NewReader([]byte(input)),
|
|
|
|
}
|
|
|
|
|
|
|
|
result := new(bytes.Buffer)
|
|
|
|
if _, err := io.Copy(result, r); err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if result.String() != expected {
|
|
|
|
t.Fatalf("bad: %#v", result.String())
|
|
|
|
}
|
|
|
|
}
|