mirror of
https://github.com/miniflux/v2.git
synced 2025-07-27 17:28:38 +00:00
First commit
This commit is contained in:
commit
8ffb773f43
2121 changed files with 1118910 additions and 0 deletions
49
vendor/github.com/tdewolff/parse/buffer/reader_test.go
generated
vendored
Normal file
49
vendor/github.com/tdewolff/parse/buffer/reader_test.go
generated
vendored
Normal file
|
@ -0,0 +1,49 @@
|
|||
package buffer // import "github.com/tdewolff/parse/buffer"
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"github.com/tdewolff/test"
|
||||
)
|
||||
|
||||
func TestReader(t *testing.T) {
|
||||
s := []byte("abcde")
|
||||
r := NewReader(s)
|
||||
test.Bytes(t, r.Bytes(), s, "reader must return bytes stored")
|
||||
|
||||
buf := make([]byte, 3)
|
||||
n, err := r.Read(buf)
|
||||
test.T(t, err, nil, "error")
|
||||
test.That(t, n == 3, "first read must read 3 characters")
|
||||
test.Bytes(t, buf, []byte("abc"), "first read must match 'abc'")
|
||||
|
||||
n, err = r.Read(buf)
|
||||
test.T(t, err, nil, "error")
|
||||
test.That(t, n == 2, "second read must read 2 characters")
|
||||
test.Bytes(t, buf[:n], []byte("de"), "second read must match 'de'")
|
||||
|
||||
n, err = r.Read(buf)
|
||||
test.T(t, err, io.EOF, "error")
|
||||
test.That(t, n == 0, "third read must read 0 characters")
|
||||
|
||||
n, err = r.Read(nil)
|
||||
test.T(t, err, nil, "error")
|
||||
test.That(t, n == 0, "read to nil buffer must return 0 characters read")
|
||||
|
||||
r.Reset()
|
||||
n, err = r.Read(buf)
|
||||
test.T(t, err, nil, "error")
|
||||
test.That(t, n == 3, "read after reset must read 3 characters")
|
||||
test.Bytes(t, buf, []byte("abc"), "read after reset must match 'abc'")
|
||||
}
|
||||
|
||||
func ExampleNewReader() {
|
||||
r := NewReader([]byte("Lorem ipsum"))
|
||||
w := &bytes.Buffer{}
|
||||
io.Copy(w, r)
|
||||
fmt.Println(w.String())
|
||||
// Output: Lorem ipsum
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue