def test_shortprompt(self): result = None def cb(s): nonlocal result result = s w = prompt.ShortPrompt(None, content='foobaz', completer=interactive.Completer( ['foobar', 'foobaz', 'fooquux']), callback=cb) self.assertEqual(w.input(), 'foobaz') w.delete_backward() self.assertEqual(w.input(), '') w.after_command() self.assertEqual(w.state, 'complete') self.assertEqual(w.inverse_input, False) w.insert('fooq') w.complete_and_finish() self.assertEqual(result, 'fooquux') w.insert('uoz') w.complete_and_finish() self.assertEqual(result, 'fooquoz')
def test(self): c = interactive.Completer(['aaa', 'bab', 'aab']) self.assertEqual( [(0, 'aaa', 'aaa'), (1, 'aab', 'aab')], c.matches('aa')) c.roll(1) self.assertEqual( [(0, 'aab', 'aab'), (2, 'aaa', 'aaa')], c.matches('aa')) c.roll_to('aaa') self.assertEqual( [(0, 'aaa', 'aaa'), (1, 'aab', 'aab')], c.matches('aa')) self.assertEqual('aaa', c.expand('a')) self.assertEqual('ccc', c.expand('ccc'))
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_composer(self): result = None def cb(s): nonlocal result result = s fe = mocks.FE() mockirc = mocks.Backend() mockirc.name = 'irccloud' fe.context.backends._backends.append(mockirc) w = prompt.Composer(fe, content='mock; foobar', completer=interactive.Completer([ 'mock; foobar', 'mock; foobaz', 'mock; fooquux' ]), callback=cb) w.beginning_of_line(interactive=True) w.kill_to_end_of_line(None) self.assertEqual(w.input(), '') w.after_command() w.insert('irccloud; foo bar') w.after_command() w.insert_newline() w.after_command() self.assertEqual(w.fill_column, 0) w.insert_newline() w.after_command() self.assertEqual(w.fill_column, 0) w.beginning_of_buffer(interactive=True) w.after_command() w.kill_to_end_of_line(count=None) w.after_command() w.insert('m; foobar') w.after_command() w.end_of_buffer() w.after_command() self.assertEqual(w.fill_column, w.default_fill_column) w.insert('blob') w.destroy() del w w = prompt.Composer(fe, content='mock; foobaz', completer=interactive.Completer([ 'mock; foobar', 'mock; foobaz', 'mock; fooquux' ]), callback=cb) self.assertEqual([(0, [ ({'bold'}, '> '), ((), 'mock; foobaz'), ({'cursor', 'visible'}, ''), ])], [(int(mark), chunk.tagsets()) for (mark, chunk) in w.view(0)]) w.previous_history_full() self.assertEqual([ (0, [({'bold'}, '> '), ((), 'm; foobar\n')]), (12, [((), '\n')]), (13, [ ((), 'blob'), ({'cursor', 'visible'}, ''), ]), ], [(int(mark), chunk.tagsets()) for (mark, chunk) in w.view(0)]) w.next_history_full() self.assertEqual([(0, [ ({'bold'}, '> '), ((), 'mock; foobaz'), ({'cursor', 'visible'}, ''), ])], [(int(mark), chunk.tagsets()) for (mark, chunk) in w.view(0)]) w.beginning_of_buffer(interactive=True) p0 = w.cursor.point w.end_of_line() self.assertEqual(w.buf[p0:w.cursor.point], 'mock; foobaz') w.cursor.point = p0 w.previous_history() w.end_of_line() self.assertEqual(w.buf[p0:w.cursor.point], 'm; foobar') w.previous_history() self.assertEqual(w.buf[p0:w.cursor.point], 'm; foobar') w.cursor.point = p0 w.next_history() w.end_of_line() self.assertEqual(w.buf[p0:w.cursor.point], 'mock; foobaz') w.previous_history_full() w.line_next() w.next_history() self.assertEqual([ (0, [ ({'bold'}, '> '), ((), 'm; foobar\n'), ]), (12, [({'cursor', 'visible'}, '')]), ], [(int(mark), chunk.tagsets()) for (mark, chunk) in w.view(0)]) w.destroy() del w w = prompt.Composer(fe, completer=interactive.Completer([ 'mock; foobar', 'mock; foobaz', 'mock; fooquux' ]), callback=cb) self.assertEqual([(0, [ ({'bold'}, '> '), ({'cursor', 'visible'}, ''), ((), ' {'), ({'bold'}, 'mock; foobar'), ((), '|mock; foobaz|mock; fooquux}\n'), ])], [(int(mark), chunk.tagsets()) for (mark, chunk) in w.view(0)]) w.previous_history() self.assertEqual([ (0, [ ({'bold'}, '> '), ((), 'm; foobar'), ({'cursor', 'visible'}, ''), ((), ' {}\n'), ]), (12, [((), '')]), ], [(int(mark), chunk.tagsets()) for (mark, chunk) in w.view(0)]) w.destroy() del w w = prompt.Composer(fe, completer=interactive.Completer([ 'mock; foobar', 'mock; foobaz', 'mock; fooquux' ]), callback=cb) self.assertEqual([(0, [ ({'bold'}, '> '), ({'cursor', 'visible'}, ''), ((), ' {'), ({'bold'}, 'mock; foobar'), ((), '|mock; foobaz|mock; fooquux}\n'), ])], [(int(mark), chunk.tagsets()) for (mark, chunk) in w.view(0)]) do(w.roll_or_search_forward()) self.assertEqual([(0, [ ({'bold'}, '> '), ({'cursor', 'visible'}, ''), ((), ' {'), ({'bold'}, 'mock; foobaz'), ((), '|mock; fooquux|mock; foobar}\n'), ])], [(int(mark), chunk.tagsets()) for (mark, chunk) in w.view(0)]) do(w.roll_or_search_backward('bar')) self.assertEqual([(0, [ ({'bold'}, '> '), ({'cursor', 'visible'}, ''), ((), ' {'), ({'bold'}, 'mock; foobar'), ((), '|mock; foobaz|mock; fooquux}\n'), ])], [(int(mark), chunk.tagsets()) for (mark, chunk) in w.view(0)]) w.insert('foobar') w.insert_newline() w.insert('abc\ndef\nghi\n') do(w.roll_or_search_backward('abc')) self.assertEqual(w.buf[w.cursor.point:w.cursor.point + 3], 'abc') do(w.roll_or_search_forward('ghi')) self.assertEqual(w.buf[w.cursor.point:w.cursor.point + 3], 'ghi')
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())