mirror of
https://github.com/walles/moar.git
synced 2024-11-11 00:27:04 +03:00
Add test for reading long lines
Change-Id: Ib24518c681f1ffc93192a985cd573fa37006d1f8
This commit is contained in:
parent
d5a0b7df63
commit
9a2ab6df98
@ -3,6 +3,7 @@ package m
|
||||
import (
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"runtime"
|
||||
@ -142,6 +143,33 @@ func TestGetLines(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetLongLine(t *testing.T) {
|
||||
file := "../sample-files/very-long-line.txt"
|
||||
reader, err := NewReaderFromFilename(file)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
if err := reader._Wait(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
lines := reader.GetLines(1, 5)
|
||||
assert.Equal(t, lines.firstLineOneBased, 1)
|
||||
assert.Equal(t, len(lines.lines), 1)
|
||||
|
||||
stat, err := os.Stat(file)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fileSize := stat.Size()
|
||||
|
||||
line := lines.lines[0]
|
||||
assert.Equal(t, len(line), fileSize)
|
||||
|
||||
assert.Assert(t, strings.HasPrefix(line, "1 2 3 4"))
|
||||
assert.Assert(t, strings.HasSuffix(line, "0123456789"))
|
||||
}
|
||||
|
||||
func _GetReaderWithLineCount(totalLines int) *Reader {
|
||||
reader := NewReaderFromStream(strings.NewReader(strings.Repeat("x\n", totalLines)), nil)
|
||||
if err := reader._Wait(); err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user