Add tests for finding command output

This commit is contained in:
pagedown 2022-01-16 04:10:16 +08:00
parent f0d2d01a36
commit 30b81d98f1
No known key found for this signature in database
GPG Key ID: E921CF18AC8FF6EB

View File

@ -974,14 +974,19 @@ class TestScreen(BaseTest):
self.assertTrue(s.scroll_to_prompt()) self.assertTrue(s.scroll_to_prompt())
self.ae(str(s.visual_line(0)), '$ 1') self.ae(str(s.visual_line(0)), '$ 1')
def lco():
a = []
s.cmd_output(0, a.append)
return ''.join(a)
def fco(): def fco():
a = [] a = []
s.cmd_output(1, a.append) s.cmd_output(1, a.append)
return ''.join(a) return ''.join(a)
def lco(): def lvco():
a = [] a = []
s.cmd_output(0, a.append) s.cmd_output(2, a.append)
return ''.join(a) return ''.join(a)
s = self.create_screen() s = self.create_screen()
@ -998,3 +1003,53 @@ class TestScreen(BaseTest):
mark_prompt(), s.draw('$ 1') mark_prompt(), s.draw('$ 1')
self.ae(fco(), 'abcd\n12') self.ae(fco(), 'abcd\n12')
self.ae(lco(), 'abcd\n12') self.ae(lco(), 'abcd\n12')
def draw_prompt(x):
mark_prompt(), s.draw(f'$ {x}'), s.carriage_return(), s.index()
def draw_output(n, x='', m=True):
if m:
mark_output()
for i in range(n):
s.draw(f'{i}{x}'), s.index(), s.carriage_return()
s = self.create_screen(cols=5, lines=5, scrollback=15)
draw_output(1, 'start', False)
draw_prompt('0'), draw_output(3)
draw_prompt('1')
draw_prompt('2'), draw_output(2, 'x')
# last cmd output
# test: find upwards
self.ae(s.scrolled_by, 0)
self.ae(lco(), '0x\n1x')
# get output after scroll up
s.scroll_to_prompt()
self.ae(s.scrolled_by, 4)
self.ae(str(s.visual_line(0)), '$ 0')
self.ae(lco(), '0x\n1x')
# first cmd output on screen
# test: find around
self.ae(fco(), '0\n1\n2')
s.scroll(2, False)
self.ae(s.scrolled_by, 2)
self.ae(str(s.visual_line(0)), '1')
self.ae(fco(), '0x\n1x')
# test: find downwards
s.scroll(2, False)
self.ae(str(s.visual_line(0)), '$ 1')
self.ae(fco(), '0x\n1x')
# resize
# get last cmd output with continued output mark
draw_prompt('3'), draw_output(1, 'long_line'), draw_output(2, 'l')
s.resize(4, 5)
s.scroll_to_prompt(-4)
self.ae(str(s.visual_line(0)), '$ 0')
self.ae(lco(), '0l\n1l')
# last visited cmd output
self.ae(lvco(), '0\n1\n2')
s.scroll_to_prompt(1)
self.ae(lvco(), '0x\n1x')