Skip to content

Commit 0d31cd3

Browse files
committed
gh-145398: Add tests for bracketed-paste event and isearch paste
- test_eventqueue: assert \x1b[200~ is translated to "bracketed paste". - test_pyrepl: feed the "bracketed paste" event and cover isearch mode.
1 parent d78c451 commit 0d31cd3

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

Lib/test/test_pyrepl/test_eventqueue.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ def test_push_with_keymap_in_keymap_and_escape(self, mock_keymap):
9595
self.assertEqual(eq.events[1].evt, "key")
9696
self.assertEqual(eq.events[1].data, "b")
9797

98+
def test_push_bracketed_paste(self):
99+
eq = self.make_eventqueue()
100+
for byte in b"\x1b[200~":
101+
eq.push(byte)
102+
event = eq.get()
103+
self.assertIsNotNone(event)
104+
self.assertEqual(event.evt, "key")
105+
self.assertEqual(event.data, "bracketed paste")
106+
self.assertEqual(event.raw, b"\x1b[200~")
107+
98108
def test_push_special_key(self):
99109
eq = self.make_eventqueue()
100110
eq.keymap = {}

Lib/test/test_pyrepl/test_pyrepl.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,11 +1952,11 @@ def test_bracketed_paste(self):
19521952
)
19531953
# fmt: on
19541954

1955-
paste_start = "\x1b[200~"
1955+
paste_start = [Event(evt="key", data="bracketed paste", raw=bytearray(b"\x1b[200~"))]
19561956
paste_end = "\x1b[201~"
19571957

19581958
events = itertools.chain(
1959-
code_to_events(paste_start),
1959+
paste_start,
19601960
code_to_events(input_code),
19611961
code_to_events(paste_end),
19621962
code_to_events("\n"),
@@ -1968,11 +1968,11 @@ def test_bracketed_paste(self):
19681968
def test_bracketed_paste_single_line(self):
19691969
input_code = "oneline"
19701970

1971-
paste_start = "\x1b[200~"
1971+
paste_start = [Event(evt="key", data="bracketed paste", raw=bytearray(b"\x1b[200~"))]
19721972
paste_end = "\x1b[201~"
19731973

19741974
events = itertools.chain(
1975-
code_to_events(paste_start),
1975+
paste_start,
19761976
code_to_events(input_code),
19771977
code_to_events(paste_end),
19781978
code_to_events("\n"),
@@ -1982,7 +1982,11 @@ def test_bracketed_paste_single_line(self):
19821982
self.assertEqual(output, input_code)
19831983

19841984
def test_bracketed_paste_in_isearch(self):
1985-
paste_start = "\x1b[200~"
1985+
# The bracketed-paste *start* marker is translated into a synthetic
1986+
# ``bracketed paste`` event by the real event queue; the fake console
1987+
# used here does not run that translation, so we feed the
1988+
# ``bracketed paste`` event directly.
1989+
paste_start = [Event(evt="key", data="bracketed paste", raw=bytearray(b"\x1b[200~"))]
19861990
paste_end = "\x1b[201~"
19871991

19881992
events = itertools.chain(
@@ -1992,7 +1996,7 @@ def test_bracketed_paste_in_isearch(self):
19921996
[
19931997
Event(evt="key", data="\x12", raw=bytearray(b"\x12")),
19941998
],
1995-
code_to_events(paste_start),
1999+
paste_start,
19962000
code_to_events("hello"),
19972001
code_to_events(paste_end),
19982002
[
@@ -2003,7 +2007,7 @@ def test_bracketed_paste_in_isearch(self):
20032007
Event(evt="key", data="\x12", raw=bytearray(b"\x12")),
20042008
],
20052009
# Search for 'world', which should not be found
2006-
code_to_events(paste_start),
2010+
paste_start,
20072011
code_to_events("world"),
20082012
code_to_events(paste_end),
20092013
[

0 commit comments

Comments
 (0)