37 lines
676 B
Go
37 lines
676 B
Go
package bufr
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestPos(t *testing.T) {
|
|
r := NewReader(strings.NewReader("hello world\nsecond line"))
|
|
|
|
unread := false
|
|
for rn, err := r.Rune(); err == nil; rn, err = r.Rune() {
|
|
index, line, col := r.Pos()
|
|
fmt.Println(string(rn), index, line, col)
|
|
|
|
if !unread && rn == '\n' {
|
|
for i := 0; i < 5; i++ {
|
|
r.UnreadRune()
|
|
}
|
|
unread = true
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestEOF(t *testing.T) {
|
|
r := NewReader(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)
|
|
}
|