2016-12-09 07:17:34 -05:00
|
|
|
package buf_test
|
2016-05-11 13:54:20 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"crypto/rand"
|
|
|
|
"testing"
|
|
|
|
|
2016-12-09 07:17:34 -05:00
|
|
|
. "v2ray.com/core/common/buf"
|
2016-08-20 14:55:45 -04:00
|
|
|
"v2ray.com/core/testing/assert"
|
2016-05-11 13:54:20 -04:00
|
|
|
)
|
|
|
|
|
2016-12-09 07:17:34 -05:00
|
|
|
func TestWriter(t *testing.T) {
|
2016-05-24 15:55:46 -04:00
|
|
|
assert := assert.On(t)
|
2016-05-11 13:54:20 -04:00
|
|
|
|
2016-12-09 07:17:34 -05:00
|
|
|
lb := New()
|
2016-12-21 09:37:16 -05:00
|
|
|
assert.Error(lb.AppendSupplier(ReadFrom(rand.Reader))).IsNil()
|
2016-05-11 13:54:20 -04:00
|
|
|
|
2016-12-06 05:03:42 -05:00
|
|
|
expectedBytes := append([]byte(nil), lb.Bytes()...)
|
2016-05-11 13:54:20 -04:00
|
|
|
|
2016-12-06 05:03:42 -05:00
|
|
|
writeBuffer := bytes.NewBuffer(make([]byte, 0, 1024*1024))
|
|
|
|
|
2017-02-15 16:51:01 -05:00
|
|
|
writer := NewWriter(NewBufferedWriter(writeBuffer))
|
2016-05-11 13:54:20 -04:00
|
|
|
err := writer.Write(lb)
|
|
|
|
assert.Error(err).IsNil()
|
2016-12-06 05:03:42 -05:00
|
|
|
assert.Bytes(expectedBytes).Equals(writeBuffer.Bytes())
|
2016-05-11 13:54:20 -04:00
|
|
|
}
|