@@ -636,6 +636,30 @@ def test_global_namespace_completion(self):
636636 output = multiline_input (reader , namespace )
637637 self .assertEqual (output , "python" )
638638
639+ def test_updown_arrow_with_completion_menu (self ):
640+ """Up arrow in the middle of unfinished tab completion when the menu is displayed
641+ should work and trigger going back in history. Down arrow should subsequently
642+ get us back to the incomplete command."""
643+ code = "import os\n os.\t \t "
644+ namespace = {"os" : os }
645+
646+ events = itertools .chain (
647+ code_to_events (code ),
648+ [
649+ Event (evt = 'key' , data = 'up' , raw = bytearray (b'\x1b OA' )),
650+ Event (evt = "key" , data = "down" , raw = bytearray (b"\x1b OB" )),
651+ ],
652+ code_to_events ("\n " )
653+ )
654+ reader = self .prepare_reader (events , namespace = namespace )
655+ output = multiline_input (reader , namespace )
656+ # This is the first line, nothing to see here
657+ self .assertEqual (output , "import os" )
658+ # This is the second line. We pressed up and down arrows
659+ # so we should end up where we were when we initiated tab completion.
660+ output = multiline_input (reader , namespace )
661+ self .assertEqual (output , "os." )
662+
639663
640664@patch ("_pyrepl.curses.tigetstr" , lambda x : b"" )
641665class TestUnivEventQueue (TestCase ):
@@ -1030,6 +1054,5 @@ def test_up_arrow_after_ctrl_r(self):
10301054 reader , _ = handle_all_events (events )
10311055 self .assert_screen_equals (reader , "" )
10321056
1033-
10341057if __name__ == '__main__' :
10351058 unittest .main ()
0 commit comments