bufr/reader_test.go

37 lines
666 B
Go

package bufr
import (
"fmt"
"strings"
"testing"
)
func TestPos(t *testing.T) {
r := New(strings.NewReader("hello world\nsecond line"))
unread := false
for rn, err := r.Rune(); err == nil; rn, err = r.Rune() {
pos := r.Pos()
fmt.Println(string(rn), pos.Index, pos.Line, pos.Column)
if !unread && rn == '\n' {
for i := 0; i < 5; i++ {
r.UnreadRune()
}
unread = true
}
}
}
func TestEOF(t *testing.T) {
r := New(strings.NewReader("hello world\nasddsa"))
var line string
var err error
for line, err = r.StringUntil(IsNewLine); err == nil; line, err = r.StringUntil(IsNewLine) {
fmt.Println(line, err)
}
fmt.Println(line, err)
}