2022-05-23 12:59:35 +02:00
|
|
|
package bufr
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestPos(t *testing.T) {
|
2023-01-21 00:18:38 +01:00
|
|
|
r := New(strings.NewReader("hello world\nsecond line"))
|
2022-05-23 12:59:35 +02:00
|
|
|
|
|
|
|
unread := false
|
|
|
|
for rn, err := r.Rune(); err == nil; rn, err = r.Rune() {
|
2023-06-30 18:08:34 +02:00
|
|
|
pos := r.Pos()
|
|
|
|
fmt.Println(string(rn), pos.Index, pos.Line, pos.Column)
|
2022-05-23 12:59:35 +02:00
|
|
|
|
|
|
|
if !unread && rn == '\n' {
|
|
|
|
for i := 0; i < 5; i++ {
|
|
|
|
r.UnreadRune()
|
|
|
|
}
|
|
|
|
unread = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-05-23 14:04:39 +02:00
|
|
|
|
|
|
|
func TestEOF(t *testing.T) {
|
2023-01-21 00:18:38 +01:00
|
|
|
r := New(strings.NewReader("hello world\nasddsa"))
|
2022-05-23 14:04:39 +02:00
|
|
|
|
2023-01-20 23:59:36 +01:00
|
|
|
var line string
|
|
|
|
var err error
|
|
|
|
for line, err = r.StringUntil(IsNewLine); err == nil; line, err = r.StringUntil(IsNewLine) {
|
2022-05-23 14:04:39 +02:00
|
|
|
fmt.Println(line, err)
|
|
|
|
}
|
|
|
|
|
2023-01-20 23:59:36 +01:00
|
|
|
fmt.Println(line, err)
|
2022-05-23 14:04:39 +02:00
|
|
|
}
|