mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
gh-121499: Fix multi-line history rendering in the REPL (#121531)
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
This commit is contained in:
parent
e745996b2d
commit
4b9e10d0ea
5 changed files with 62 additions and 0 deletions
|
@ -21,6 +21,7 @@ from .support import (
|
|||
more_lines,
|
||||
multiline_input,
|
||||
code_to_events,
|
||||
clean_screen
|
||||
)
|
||||
from _pyrepl.console import Event
|
||||
from _pyrepl.readline import ReadlineAlikeReader, ReadlineConfig
|
||||
|
@ -483,6 +484,7 @@ class TestPyReplOutput(TestCase):
|
|||
console = FakeConsole(events)
|
||||
config = ReadlineConfig(readline_completer=None)
|
||||
reader = ReadlineAlikeReader(console=console, config=config)
|
||||
reader.can_colorize = False
|
||||
return reader
|
||||
|
||||
def test_basic(self):
|
||||
|
@ -490,6 +492,7 @@ class TestPyReplOutput(TestCase):
|
|||
|
||||
output = multiline_input(reader)
|
||||
self.assertEqual(output, "1+1")
|
||||
self.assertEqual(clean_screen(reader.screen), "1+1")
|
||||
|
||||
def test_multiline_edit(self):
|
||||
events = itertools.chain(
|
||||
|
@ -519,8 +522,10 @@ class TestPyReplOutput(TestCase):
|
|||
|
||||
output = multiline_input(reader)
|
||||
self.assertEqual(output, "def f():\n ...\n ")
|
||||
self.assertEqual(clean_screen(reader.screen), "def f():\n ...")
|
||||
output = multiline_input(reader)
|
||||
self.assertEqual(output, "def g():\n pass\n ")
|
||||
self.assertEqual(clean_screen(reader.screen), "def g():\n pass")
|
||||
|
||||
def test_history_navigation_with_up_arrow(self):
|
||||
events = itertools.chain(
|
||||
|
@ -539,12 +544,40 @@ class TestPyReplOutput(TestCase):
|
|||
|
||||
output = multiline_input(reader)
|
||||
self.assertEqual(output, "1+1")
|
||||
self.assertEqual(clean_screen(reader.screen), "1+1")
|
||||
output = multiline_input(reader)
|
||||
self.assertEqual(output, "2+2")
|
||||
self.assertEqual(clean_screen(reader.screen), "2+2")
|
||||
output = multiline_input(reader)
|
||||
self.assertEqual(output, "2+2")
|
||||
self.assertEqual(clean_screen(reader.screen), "2+2")
|
||||
output = multiline_input(reader)
|
||||
self.assertEqual(output, "1+1")
|
||||
self.assertEqual(clean_screen(reader.screen), "1+1")
|
||||
|
||||
def test_history_with_multiline_entries(self):
|
||||
code = "def foo():\nx = 1\ny = 2\nz = 3\n\ndef bar():\nreturn 42\n\n"
|
||||
events = list(itertools.chain(
|
||||
code_to_events(code),
|
||||
[
|
||||
Event(evt="key", data="up", raw=bytearray(b"\x1bOA")),
|
||||
Event(evt="key", data="up", raw=bytearray(b"\x1bOA")),
|
||||
Event(evt="key", data="up", raw=bytearray(b"\x1bOA")),
|
||||
Event(evt="key", data="\n", raw=bytearray(b"\n")),
|
||||
Event(evt="key", data="\n", raw=bytearray(b"\n")),
|
||||
]
|
||||
))
|
||||
|
||||
reader = self.prepare_reader(events)
|
||||
output = multiline_input(reader)
|
||||
output = multiline_input(reader)
|
||||
output = multiline_input(reader)
|
||||
self.assertEqual(
|
||||
clean_screen(reader.screen),
|
||||
'def foo():\n x = 1\n y = 2\n z = 3'
|
||||
)
|
||||
self.assertEqual(output, "def foo():\n x = 1\n y = 2\n z = 3\n ")
|
||||
|
||||
|
||||
def test_history_navigation_with_down_arrow(self):
|
||||
events = itertools.chain(
|
||||
|
@ -562,6 +595,7 @@ class TestPyReplOutput(TestCase):
|
|||
|
||||
output = multiline_input(reader)
|
||||
self.assertEqual(output, "1+1")
|
||||
self.assertEqual(clean_screen(reader.screen), "1+1")
|
||||
|
||||
def test_history_search(self):
|
||||
events = itertools.chain(
|
||||
|
@ -578,18 +612,23 @@ class TestPyReplOutput(TestCase):
|
|||
|
||||
output = multiline_input(reader)
|
||||
self.assertEqual(output, "1+1")
|
||||
self.assertEqual(clean_screen(reader.screen), "1+1")
|
||||
output = multiline_input(reader)
|
||||
self.assertEqual(output, "2+2")
|
||||
self.assertEqual(clean_screen(reader.screen), "2+2")
|
||||
output = multiline_input(reader)
|
||||
self.assertEqual(output, "3+3")
|
||||
self.assertEqual(clean_screen(reader.screen), "3+3")
|
||||
output = multiline_input(reader)
|
||||
self.assertEqual(output, "1+1")
|
||||
self.assertEqual(clean_screen(reader.screen), "1+1")
|
||||
|
||||
def test_control_character(self):
|
||||
events = code_to_events("c\x1d\n")
|
||||
reader = self.prepare_reader(events)
|
||||
output = multiline_input(reader)
|
||||
self.assertEqual(output, "c\x1d")
|
||||
self.assertEqual(clean_screen(reader.screen), "c")
|
||||
|
||||
|
||||
class TestPyReplCompleter(TestCase):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue