1
1
mirror of https://github.com/walles/moar.git synced 2024-12-03 16:35:32 +03:00

Use the same waiting code in all places

This commit is contained in:
Johan Walles 2024-01-12 08:40:08 +01:00
parent 9f3f62d6ee
commit 2e1dd0ec82
4 changed files with 11 additions and 33 deletions

View File

@ -267,9 +267,7 @@ func TestFindFirstHitSimple(t *testing.T) {
pager := NewPager(reader) pager := NewPager(reader)
pager.screen = twin.NewFakeScreen(40, 10) pager.screen = twin.NewFakeScreen(40, 10)
// Wait for reader to finish reading assert.NilError(t, pager.reader._wait())
for !reader.done.Load() {
}
pager.searchPattern = toPattern("AB") pager.searchPattern = toPattern("AB")
@ -283,9 +281,7 @@ func TestFindFirstHitAnsi(t *testing.T) {
pager := NewPager(reader) pager := NewPager(reader)
pager.screen = twin.NewFakeScreen(40, 10) pager.screen = twin.NewFakeScreen(40, 10)
// Wait for reader to finish reading assert.NilError(t, pager.reader._wait())
for !reader.done.Load() {
}
pager.searchPattern = toPattern("AB") pager.searchPattern = toPattern("AB")
@ -299,9 +295,7 @@ func TestFindFirstHitNoMatch(t *testing.T) {
pager := NewPager(reader) pager := NewPager(reader)
pager.screen = twin.NewFakeScreen(40, 10) pager.screen = twin.NewFakeScreen(40, 10)
// Wait for reader to finish reading assert.NilError(t, pager.reader._wait())
for !reader.done.Load() {
}
pager.searchPattern = toPattern("this pattern should not be found") pager.searchPattern = toPattern("this pattern should not be found")
@ -314,9 +308,7 @@ func TestFindFirstHitNoMatchBackwards(t *testing.T) {
pager := NewPager(reader) pager := NewPager(reader)
pager.screen = twin.NewFakeScreen(40, 10) pager.screen = twin.NewFakeScreen(40, 10)
// Wait for reader to finish reading assert.NilError(t, pager.reader._wait())
for !reader.done.Load() {
}
pager.searchPattern = toPattern("this pattern should not be found") pager.searchPattern = toPattern("this pattern should not be found")
theEnd := *linenumbers.LineNumberFromLength(reader.GetLineCount()) theEnd := *linenumbers.LineNumberFromLength(reader.GetLineCount())
@ -347,9 +339,7 @@ func TestScrollToBottomWrapNextToLastLine(t *testing.T) {
pager.ShowLineNumbers = false pager.ShowLineNumbers = false
pager.screen = screen pager.screen = screen
// Wait for reader to finish reading assert.NilError(t, pager.reader._wait())
for !reader.done.Load() {
}
// This is what we're testing really // This is what we're testing really
pager.scrollToEnd() pager.scrollToEnd()
@ -511,8 +501,7 @@ func TestPageSamples(t *testing.T) {
}() }()
myReader := NewReaderFromStream(fileName, file, chroma.Style{}, nil, nil) myReader := NewReaderFromStream(fileName, file, chroma.Style{}, nil, nil)
for !myReader.done.Load() { assert.NilError(t, myReader._wait())
}
pager := NewPager(myReader) pager := NewPager(myReader)
pager.WrapLongLines = false pager.WrapLongLines = false

View File

@ -15,9 +15,7 @@ func TestNotFoundFindPrevious(t *testing.T) {
pager := NewPager(reader) pager := NewPager(reader)
pager.screen = twin.NewFakeScreen(40, 2) pager.screen = twin.NewFakeScreen(40, 2)
// Wait for reader to finish reading assert.NilError(t, reader._wait())
for !reader.done.Load() {
}
// Look for a hit on the second line // Look for a hit on the second line
pager.searchPattern = toPattern("bepa") pager.searchPattern = toPattern("bepa")
@ -36,9 +34,7 @@ func TestWrapSearchBackwards(t *testing.T) {
pager := NewPager(reader) pager := NewPager(reader)
pager.screen = twin.NewFakeScreen(40, 3) pager.screen = twin.NewFakeScreen(40, 3)
// Wait for reader to finish reading assert.NilError(t, reader._wait())
for !reader.done.Load() {
}
// Looking for this should take us to the last line // Looking for this should take us to the last line
pager.searchPattern = toPattern("gold") pager.searchPattern = toPattern("gold")

View File

@ -368,10 +368,7 @@ func BenchmarkReaderDone(b *testing.B) {
readMe, err := NewReaderFromFilename(filename, *styles.Get("native"), formatters.TTY16m, nil) readMe, err := NewReaderFromFilename(filename, *styles.Get("native"), formatters.TTY16m, nil)
assert.NilError(b, err) assert.NilError(b, err)
// Wait for the reader to finish assert.NilError(b, readMe._wait())
//revive:disable-next-line:empty-block
for !readMe.done.Load() {
}
assert.NilError(b, readMe.err) assert.NilError(b, readMe.err)
} }
} }
@ -406,9 +403,7 @@ func BenchmarkReadLargeFile(b *testing.B) {
readMe, err := NewReaderFromFilename(largeFileName, *styles.Get("native"), formatters.TTY16m, nil) readMe, err := NewReaderFromFilename(largeFileName, *styles.Get("native"), formatters.TTY16m, nil)
assert.NilError(b, err) assert.NilError(b, err)
// Wait for the reader to finish assert.NilError(b, readMe._wait())
for !readMe.done.Load() {
}
assert.NilError(b, readMe.err) assert.NilError(b, readMe.err)
} }
} }

View File

@ -152,9 +152,7 @@ func TestWrapping(t *testing.T) {
pager.WrapLongLines = true pager.WrapLongLines = true
pager.ShowLineNumbers = false pager.ShowLineNumbers = false
// Wait for reader to finish reading assert.NilError(t, reader._wait())
for !reader.done.Load() {
}
// This is what we're testing really // This is what we're testing really
pager.scrollToEnd() pager.scrollToEnd()