def test_StartOfLine(self): t = self.t l = lineobj.ReadLineTextBuffer(t, point=len(t)) for i in range(len(t)): l.point = i l.point = lineobj.StartOfLine self.assertEqual(0, l.point)
def test_NextChar(self): t = self.t l = lineobj.ReadLineTextBuffer(t) for i in range(len(t)): self.assertEqual(i, l.point) l.point = lineobj.NextChar # advance past end of buffer l.point = lineobj.NextChar self.assertEqual(len(t), l.point)
def test_PrevChar(self): t = self.t l = lineobj.ReadLineTextBuffer(t, point=len(t)) for i in range(len(t)): self.assertEqual(len(t) - i, l.point) l.point = lineobj.PrevChar # advance past beginning of buffer l.point = lineobj.PrevChar self.assertEqual(0, l.point)
def test_Point(self): cmd = lineobj.Point tests = [ # "First Second Third" (cmd, "First Second Third", 0), (cmd, "First Second Third", 12), (cmd, "First Second Third", 18), ] for cmd, text, p in tests: l = lineobj.ReadLineTextBuffer(text, p) self.assertEqual(p, cmd(l))
def test_PrevChar(self): cmd = lineobj.PrevChar tests = [ # "First" (cmd, "First", " #", " # "), (cmd, "First", " # ", "# "), (cmd, "First", "# ", "# "), ] for cmd, text, init_point, expected_point in tests: l = lineobj.ReadLineTextBuffer(text, get_point_pos(init_point)) l.point = cmd self.assertEqual(get_point_pos(expected_point), l.point)
def test_WordStart_2(self): cmd = lineobj.WordStart tests = [ # "First Second Third" (cmd, "First Second Third", " # "), (cmd, "First Second Third", " # "), (cmd, "First Second Third", " #"), ] for cmd, text, init_point in tests: l = lineobj.ReadLineTextBuffer(text, get_point_pos(init_point)) self.assertRaises(lineobj.NotAWordError, cmd, l)
def test_EndOfLine(self): cmd = lineobj.EndOfLine tests = [ # "First Second Third" (cmd, "First Second Third", "# ", " #"), (cmd, "First Second Third", " # ", " #"), (cmd, "First Second Third", " #", " #"), ] for cmd, text, init_point, expected_point in tests: l = lineobj.ReadLineTextBuffer(text, get_point_pos(init_point)) l.point = cmd self.assertEqual(get_point_pos(expected_point), l.point)
def __init__(self, rlobj): self.argument = 0 self.rlobj = rlobj self.exit_dispatch = {} self.key_dispatch = {} self.argument = 1 self.prevargument = None self.l_buffer = lineobj.ReadLineTextBuffer("") self._history = history.LineHistory() self.completer_delims = " \t\n\"\\'`@$><=;|&{(" self.show_all_if_ambiguous = 'on' self.mark_directories = 'on' self.complete_filesystem = 'off' self.completer = None self.begidx = 0 self.endidx = 0 self.tabstop = 4 self.startup_hook = None self.pre_input_hook = None self.first_prompt = True self.cursor_size = 25 self.prompt = ">>> " # Paste settings # assumes data on clipboard is path if shorter than 300 characters and doesn't contain \t or \n # and replace \ with / for easier use in ipython self.enable_ipython_paste_for_paths = True # automatically convert tabseparated data to list of lists or array # constructors self.enable_ipython_paste_list_of_lists = True self.enable_win32_clipboard = True self.paste_line_buffer = [] self._sub_modes = []
def _readline_from_keyboard_poll(self): pastebuffer = self.mode.paste_line_buffer if len(pastebuffer) > 0: # paste first line in multiline paste buffer self.l_buffer = lineobj.ReadLineTextBuffer(pastebuffer[0]) self._update_line() self.mode.paste_line_buffer = pastebuffer[1:] return True c = self.console def nop(e): pass try: event = c.getkeypress() except KeyboardInterrupt: event = self.handle_ctrl_c() try: result = self.mode.process_keyevent(event.keyinfo) except EOFError: logger.stop_logging() raise self._update_line() return result
def add_history(self, text): self._history.add_history(lineobj.ReadLineTextBuffer(text))
def __init__(self): self.l_buffer = lineobj.ReadLineTextBuffer("") self._history = history.LineHistory()
def test_copy2(self): l = lineobj.ReadLineTextBuffer("first second", point=5) q = l.copy() self.assertEqual(q.get_line_text(), l.get_line_text()) self.assertEqual(q.point, l.point) self.assertEqual(q.mark, l.mark)
(cmd, "First Second Third", 0), (cmd, "First Second Third", 12), (cmd, "First Second Third", 18), ] for cmd, text, p in tests: l = lineobj.ReadLineTextBuffer(text, p) self.assertEqual(p, cmd(l)) # ---------------------------------------------------------------------- # utility functions def get_point_pos(pstr): return pstr.index("#") def get_mark_pos(mstr): try: return mstr.index("#") except ValueError: return -1 # ---------------------------------------------------------------------- if __name__ == '__main__': unittest.main() l = lineobj.ReadLineTextBuffer("First Second Third")