31 lines
565 B
Go
31 lines
565 B
Go
package nixwire
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
)
|
|
|
|
func TestRoundtrip(t *testing.T) {
|
|
var buf bytes.Buffer
|
|
|
|
r := Deserializer{&buf}
|
|
w := Serializer{&buf}
|
|
|
|
for n := 0; n < 128; n++ {
|
|
str := make([]byte, n)
|
|
for i := 0; i < len(str); i++ {
|
|
str[i] = 'a'
|
|
}
|
|
|
|
if _, err := w.WriteString(string(str)); err != nil {
|
|
t.Fatalf("WriteString(%d): %v", n, err)
|
|
}
|
|
got, err := r.ReadString()
|
|
if err != nil {
|
|
t.Fatalf("ReadString(%d): %v", n, err)
|
|
}
|
|
if got != string(str) {
|
|
t.Errorf("ReadString != WriteString (%q != %q)", got, string(str))
|
|
}
|
|
}
|
|
}
|