depot/go/nix/nixwire/nixwire_test.go

32 lines
565 B
Go
Raw Permalink Normal View History

2022-10-09 22:48:18 +00:00
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))
}
}
}