Exemple #1
0
 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)
Exemple #2
0
    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
Exemple #3
0
 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)
Exemple #4
0
 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)
Exemple #5
0
 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))
Exemple #6
0
 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)
Exemple #7
0
    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)
Exemple #8
0
 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)
Exemple #9
0
    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 = []
        self.assertEqual(q.forward_search_history("a"), "aaaa")
        self.assertEqual(q.forward_search_history("a"), "aaba")
        self.assertEqual(q.forward_search_history("ak"), "akca")
        self.assertEqual(q.forward_search_history("akl"), "akca")
        self.assertEqual(q.forward_search_history("ak"), "akca")
        self.assertEqual(q.forward_search_history("ako"), "ako")


class Test_empty_history_search_incr_fwd_backwd(unittest.TestCase):
    def setUp(self):
        self.q = q = LineHistory()

    def test_backward_1(self):
        q = self.q
        self.assertEqual(q.reverse_search_history("b"), "")

    def test_forward_1(self):
        q = self.q
        self.assertEqual(q.forward_search_history("a"), "")


#----------------------------------------------------------------------
# utility functions

#----------------------------------------------------------------------

if __name__ == '__main__':
    unittest.main()

    l = lineobj.ReadLineTextBuffer("First Second Third")
Exemple #11
0
 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)
Exemple #12
0
 def __init__ (self):
     self.l_buffer=lineobj.ReadLineTextBuffer("")
     self._history=history.LineHistory()
Exemple #13
0
 def add_history(self, text):
     self._history.add_history(lineobj.ReadLineTextBuffer(text))