def test_leaper2(self): w = prompt.Leaper(None, prompt='multiline prompt\n: ', completer=interactive.Completer([])) self.assertEqual([(0, [({'bold'}, 'multiline prompt\n')]), (17, [ ({'bold'}, ': '), ({'cursor', 'visible'}, ''), ((), ''), ])], [(int(mark), chunk.tagsets()) for (mark, chunk) in w.view(0)])
def test_leaper(self): matches = ['aaa', 'aab', 'abc'] w = prompt.Leaper(None, completer=interactive.Completer(matches)) w.insert('a') self.assertEqual([(0, [({'bold'}, '> '), ((), 'a'), ({'cursor', 'visible'}, ''), ((), ' {'), ({'bold'}, 'aaa'), ((), '|aab|abc}\n')])], [(int(mark), chunk.tagsets()) for (mark, chunk) in w.view(0)]) w.roll_forward() self.assertEqual([(0, [({'bold'}, '> '), ((), 'a'), ({'cursor', 'visible'}, ''), ((), ' {'), ({'bold'}, 'aab'), ((), '|abc|aaa}\n')])], [(int(mark), chunk.tagsets()) for (mark, chunk) in w.view(0)]) w.roll_backward() self.assertEqual([(0, [({'bold'}, '> '), ((), 'a'), ({'cursor', 'visible'}, ''), ((), ' {'), ({'bold'}, 'aaa'), ((), '|aab|abc}\n')])], [(int(mark), chunk.tagsets()) for (mark, chunk) in w.view(0)]) w.insert('bc') self.assertEqual([(0, [({'bold'}, '> '), ((), 'abc'), ({'cursor', 'visible'}, ''), ((), ' {'), ({'bold'}, 'abc'), ((), '}\n')])], [(int(mark), chunk.tagsets()) for (mark, chunk) in w.view(0)]) w.roll_forward() self.assertEqual([(0, [({'bold'}, '> '), ((), 'abc'), ({'cursor', 'visible'}, ''), ((), ' {'), ({'bold'}, 'abc'), ((), '}\n')])], [(int(mark), chunk.tagsets()) for (mark, chunk) in w.view(0)]) w.roll_backward() self.assertEqual([(0, [({'bold'}, '> '), ((), 'abc'), ({'cursor', 'visible'}, ''), ((), ' {'), ({'bold'}, 'abc'), ((), '}\n')])], [(int(mark), chunk.tagsets()) for (mark, chunk) in w.view(0)]) w.delete_backward(2) w.insert('\n') self.assertEqual([(0, [ ({'bold'}, '> '), ((), 'a {}\n'), ]), (4, [({'cursor', 'visible'}, ''), ((), ' {}\n')])], [(int(mark), chunk.tagsets()) for (mark, chunk) in w.view(0)]) w.delete_backward() w.state_normal() self.assertEqual([(0, [ ({'bold'}, '> '), ((), 'a'), ({'cursor', 'visible'}, ''), ])], [(int(mark), chunk.tagsets()) for (mark, chunk) in w.view(0)]) self.assertEqual('a', w.input()) w.clear_input() self.assertEqual('', w.input()) w.insert('ab') w.complete_command(key='\t') self.assertEqual(w.input(), 'aab') w.clear_input() self.assertEqual('', w.input()) w.complete_command(key='\t') self.assertEqual('\t', w.input()) w.clear_input() self.assertEqual('', w.input()) w.insert('b') self.assertEqual('b', w.input()) w.this_command = 'insert_stuff' w.state = 'preload' w.before_command() self.assertEqual('', w.input()) self.assertEqual([(i, s, s) for (i, s) in enumerate(matches)], w.matches()) w.insert('blob') self.assertEqual('blob', w.input()) self.assertEqual(w.state, 'preload') w.delete_backward() self.assertEqual('', w.input()) w.insert('blob') self.assertEqual('blob', w.input()) w.state = 'normal' w.delete_backward() self.assertEqual('blo', w.input())