diff options
Diffstat (limited to 'libgo/go/encoding/binary/varint_test.go')
-rw-r--r-- | libgo/go/encoding/binary/varint_test.go | 32 |
1 files changed, 8 insertions, 24 deletions
diff --git a/libgo/go/encoding/binary/varint_test.go b/libgo/go/encoding/binary/varint_test.go index dc550f2..9476bd5 100644 --- a/libgo/go/encoding/binary/varint_test.go +++ b/libgo/go/encoding/binary/varint_test.go @@ -25,9 +25,9 @@ func TestConstants(t *testing.T) { } func testVarint(t *testing.T, x int64) { - buf1 := make([]byte, MaxVarintLen64) - n := PutVarint(buf1[:], x) - y, m := Varint(buf1[0:n]) + buf := make([]byte, MaxVarintLen64) + n := PutVarint(buf, x) + y, m := Varint(buf[0:n]) if x != y { t.Errorf("Varint(%d): got %d", x, y) } @@ -35,15 +35,7 @@ func testVarint(t *testing.T, x int64) { t.Errorf("Varint(%d): got n = %d; want %d", x, m, n) } - var buf2 bytes.Buffer - err := WriteVarint(&buf2, x) - if err != nil { - t.Errorf("WriteVarint(%d): %s", x, err) - } - if n != buf2.Len() { - t.Errorf("WriteVarint(%d): got n = %d; want %d", x, buf2.Len(), n) - } - y, err = ReadVarint(&buf2) + y, err := ReadVarint(bytes.NewBuffer(buf)) if err != nil { t.Errorf("ReadVarint(%d): %s", x, err) } @@ -53,9 +45,9 @@ func testVarint(t *testing.T, x int64) { } func testUvarint(t *testing.T, x uint64) { - buf1 := make([]byte, MaxVarintLen64) - n := PutUvarint(buf1[:], x) - y, m := Uvarint(buf1[0:n]) + buf := make([]byte, MaxVarintLen64) + n := PutUvarint(buf, x) + y, m := Uvarint(buf[0:n]) if x != y { t.Errorf("Uvarint(%d): got %d", x, y) } @@ -63,15 +55,7 @@ func testUvarint(t *testing.T, x uint64) { t.Errorf("Uvarint(%d): got n = %d; want %d", x, m, n) } - var buf2 bytes.Buffer - err := WriteUvarint(&buf2, x) - if err != nil { - t.Errorf("WriteUvarint(%d): %s", x, err) - } - if n != buf2.Len() { - t.Errorf("WriteUvarint(%d): got n = %d; want %d", x, buf2.Len(), n) - } - y, err = ReadUvarint(&buf2) + y, err := ReadUvarint(bytes.NewBuffer(buf)) if err != nil { t.Errorf("ReadUvarint(%d): %s", x, err) } |