1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-07-13 01:30:53 +02:00

introduce ViewLines functions

This commit is contained in:
Jesse Duffield
2022-12-25 11:38:00 +11:00
parent b623ecf898
commit 5d2584a188
14 changed files with 217 additions and 61 deletions

View File

@ -151,6 +151,13 @@ func (self *Assert) SelectedLine(matcher *matcher) {
)
}
func (self *Assert) SelectedLineIdx(expected int) {
self.assertWithRetries(func() (bool, string) {
actual := self.gui.CurrentContext().GetView().SelectedLineIdx()
return expected == actual, fmt.Sprintf("Expected selected line index to be %d, got %d", expected, actual)
})
}
func (self *Assert) InPrompt() {
self.assertWithRetries(func() (bool, string) {
currentView := self.gui.CurrentContext().GetView()
@ -209,6 +216,47 @@ func (self *Assert) ViewContent(viewName string, matcher *matcher) {
)
}
// asserts that the given view has lines matching the given matchers.
func (self *Assert) ViewLines(viewName string, matchers ...*matcher) {
self.assertWithRetries(func() (bool, string) {
lines := self.gui.View(viewName).BufferLines()
return len(lines) == len(matchers), fmt.Sprintf("unexpected number of lines in view. Expected %d, got %d", len(matchers), len(lines))
})
for i, matcher := range matchers {
self.matchString(matcher, fmt.Sprintf("Unexpected content in view '%s'.", viewName),
func() string {
return self.gui.View(viewName).BufferLines()[i]
},
)
}
}
func (self *Assert) CurrentViewLines(matchers ...*matcher) {
self.ViewLines(self.gui.CurrentContext().GetView().Name(), matchers...)
}
// asserts that the given view has lines matching the given matchers. So if three matchers
// are passed, we only check the first three lines of the view.
func (self *Assert) ViewTopLines(viewName string, matchers ...*matcher) {
self.assertWithRetries(func() (bool, string) {
lines := self.gui.View(viewName).BufferLines()
return len(lines) >= len(matchers), fmt.Sprintf("unexpected number of lines in view. Expected at least %d, got %d", len(matchers), len(lines))
})
for i, matcher := range matchers {
self.matchString(matcher, fmt.Sprintf("Unexpected content in view '%s'.", viewName),
func() string {
return self.gui.View(viewName).BufferLines()[i]
},
)
}
}
func (self *Assert) CurrentViewTopLines(matchers ...*matcher) {
self.ViewTopLines(self.gui.CurrentContext().GetView().Name(), matchers...)
}
func (self *Assert) CurrentViewContent(matcher *matcher) {
self.matchString(matcher, "Unexpected content in current view.",
func() string {