@@ -300,7 +300,16 @@ def test_cw(self):
300300 self .repl .s = "this.is.\t a.test"
301301 self .assertEqual (self .repl .cw (), 'a.test' )
302302
303- def test_tab (self ):
303+
304+ class TestCliReplTab (unittest .TestCase ):
305+
306+ def setUp (self ):
307+
308+ def setup_matches (tab = False ):
309+ self .repl .matches = ["foobar" , "foofoobar" ]
310+ self .repl .matches_iter = repl .MatchesIterator ()
311+ self .repl .matches_iter .update ('f' , self .repl .matches )
312+
304313 self .repl = FakeCliRepl ()
305314
306315 # Stub out CLIRepl attributes
@@ -309,17 +318,11 @@ def test_tab(self):
309318 self .repl .print_line = Mock ()
310319 self .repl .show_list = Mock ()
311320
312- # Stub out the Complete logic
313- def setup_complete (first = True ):
314- def setup_matches (tab = False ):
315- self .repl .matches = ["foobar" , "foofoobar" ]
316- self .repl .matches_iter = repl .MatchesIterator ()
317- self .repl .matches_iter .update ('f' , self .repl .matches )
318-
319- self .repl .complete = Mock ()
320- self .repl .complete .return_value = True
321- self .repl .complete .side_effect = setup_matches
322- self .repl .matches_iter = first and None or setup_matches ()
321+ # Stub out complete
322+ self .repl .complete = Mock ()
323+ self .repl .complete .return_value = True
324+ self .repl .complete .side_effect = setup_matches
325+ self .repl .matches_iter = None
323326
324327 # Stub out the config logic
325328 self .repl .config = Mock ()
@@ -328,54 +331,61 @@ def setup_matches(tab=False):
328331 self .repl .config .list_win_visible = True
329332 self .repl .config .autocomplete_mode = 1
330333
331- # Tests
332-
333- # test normal tab
334- self .repl .s = ""
335- setup_complete ()
336- self .repl .tab ()
337- self .assertEqual (self .repl .s , " " )
338-
339- # test expand
340- self .repl .s = "f"
341- setup_complete ()
342- self .repl .tab ()
343- self .assertEqual (self .repl .s , "foo" )
344334
345- # test first forward
346- self .repl .s = "foo"
347- setup_complete ()
348- self .repl .tab ()
349- self .assertEqual (self .repl .s , "foobar" )
350-
351- # test first back
352- self .repl .s = "foo"
353- setup_complete ()
354- self .repl .tab (back = True )
355- self .assertEqual (self .repl .s , "foofoobar" )
356-
357- # test nth forward
358- self .repl .s = "f"
359- setup_complete ()
360- self .repl .tab ()
361- self .repl .tab ()
362- self .assertEqual (self .repl .s , "foobar" )
363-
364- # test nth back
365- self .repl .s = "f"
366- setup_complete ()
367- self .repl .tab ()
368- self .repl .tab (back = True )
369- self .assertEqual (self .repl .s , "foofoobar" )
370-
371- # test non-appending tab-complete
372- self .repl .s = "bar"
373- self .repl .config .autocomplete_mode = 2
374- self .repl .tab ()
375- self .assertEqual (self .repl .s , "foobar" )
376-
377- self .repl .tab ()
378- self .assertEqual (self .repl .s , "foofoobar" )
335+ def test_tab (self ):
336+ def test_normal_tab (self ):
337+ self .repl .s = ""
338+ setup_complete ()
339+ self .repl .tab ()
340+ self .assertEqual (self .repl .s , " " )
341+
342+ def test_expand (self ):
343+ self .repl .s = "f"
344+ setup_complete ()
345+ self .repl .tab ()
346+ self .assertEqual (self .repl .s , "foo" )
347+
348+ def test_first_forward (self ):
349+ self .repl .s = "foo"
350+ setup_complete ()
351+ self .repl .tab ()
352+ self .assertEqual (self .repl .s , "foobar" )
353+
354+ def test_first_back (self ):
355+ self .repl .s = "foo"
356+ setup_complete ()
357+ self .repl .tab (back = True )
358+ self .assertEqual (self .repl .s , "foofoobar" )
359+
360+ def test_nth_forward (self ):
361+ self .repl .s = "f"
362+ setup_complete ()
363+ self .repl .tab ()
364+ self .repl .tab ()
365+ self .assertEqual (self .repl .s , "foobar" )
366+
367+ def test_nth_back (self ):
368+ self .repl .s = "f"
369+ setup_complete ()
370+ self .repl .tab ()
371+ self .repl .tab (back = True )
372+ self .assertEqual (self .repl .s , "foofoobar" )
373+
374+ def test_non_contiguous_tab_complete (self ):
375+ self .repl .s = "br"
376+ self .repl .config .autocomplete_mode = 2
377+ setup_complete ()
378+ self .repl .tab ()
379+ self .assertEqual (self .repl .s , "foobar" )
380+
381+ def test_non_appending_tab_complete (self ):
382+ self .repl .s = "bar"
383+ self .repl .config .autocomplete_mode = 2
384+ setup_complete ()
385+ self .repl .tab ()
386+ self .assertEqual (self .repl .s , "foobar" )
387+ self .repl .tab ()
388+ self .assertEqual (self .repl .s , "foofoobar" )
379389
380390if __name__ == '__main__' :
381391 unittest .main ()
0 commit comments