Esempio n. 1
0
    def test_add_command(self):
        commands = ["command1", "command2"]
        history, tctx_master = self.fill_history(commands)

        saved_commands = [buf.text for buf in history.saved_commands]
        assert saved_commands == [""] + commands

        # The history size is only 3. So, we forget the first
        # one command, when adding fourth command
        cbuf = commander.CommandBuffer(tctx_master, "command3")
        history.add_command(cbuf)
        saved_commands = [buf.text for buf in history.saved_commands]
        assert saved_commands == commands + ["command3"]

        # Commands with the same text are not repeated in the history one by one
        history.add_command(cbuf)
        saved_commands = [buf.text for buf in history.saved_commands]
        assert saved_commands == commands + ["command3"]

        # adding command in execution mode sets index at the beginning of the history
        # and replace the last command buffer if it is empty or has the same text
        cbuf = commander.CommandBuffer(tctx_master, "")
        history.add_command(cbuf)
        history.index = 0
        cbuf = commander.CommandBuffer(tctx_master, "command4")
        history.add_command(cbuf, True)
        assert history.index == history.last_index
        saved_commands = [buf.text for buf in history.saved_commands]
        assert saved_commands == ["command2", "command3", "command4"]
Esempio n. 2
0
 def fill_history(self, commands):
     with taddons.context() as tctx:
         history = commander.CommandHistory(tctx.master, size=3)
         for c in commands:
             cbuf = commander.CommandBuffer(tctx.master, c)
             history.add_command(cbuf)
     return history, tctx.master
Esempio n. 3
0
 def test_right(self):
     cursors = [1, 2, 3, 4, 4]
     with taddons.context() as tctx:
         cb = commander.CommandBuffer(tctx.master)
         cb.text, cb.cursor = "abcd", 0
         for c in cursors:
             cb.right()
             assert cb.cursor == c
Esempio n. 4
0
 def test_left(self):
     cursors = [3, 2, 1, 0, 0]
     with taddons.context() as tctx:
         cb = commander.CommandBuffer(tctx.master)
         cb.text, cb.cursor = "abcd", 4
         for c in cursors:
             cb.left()
             assert cb.cursor == c
Esempio n. 5
0
    def test_up_and_down(self):
        with taddons.context() as tctx:
            history = commander.CommandHistory(tctx.master, size=3)
            edit = commander.CommandEdit(tctx.master, '', history)

            buf = commander.CommandBuffer(tctx.master, 'cmd1')
            history.add_command(buf)
            buf = commander.CommandBuffer(tctx.master, 'cmd2')
            history.add_command(buf)

            edit.keypress(1, 'up')
            assert edit.get_edit_text() == 'cmd2'
            edit.keypress(1, 'up')
            assert edit.get_edit_text() == 'cmd1'
            edit.keypress(1, 'up')
            assert edit.get_edit_text() == 'cmd1'

            history = commander.CommandHistory(tctx.master, size=5)
            edit = commander.CommandEdit(tctx.master, '', history)
            edit.keypress(1, 'a')
            edit.keypress(1, 'b')
            edit.keypress(1, 'c')
            assert edit.get_edit_text() == 'abc'
            edit.keypress(1, 'up')
            assert edit.get_edit_text() == ''
            edit.keypress(1, 'down')
            assert edit.get_edit_text() == 'abc'
            edit.keypress(1, 'down')
            assert edit.get_edit_text() == 'abc'

            history = commander.CommandHistory(tctx.master, size=5)
            edit = commander.CommandEdit(tctx.master, '', history)
            buf = commander.CommandBuffer(tctx.master, 'cmd3')
            history.add_command(buf)
            edit.keypress(1, 'z')
            edit.keypress(1, 'up')
            assert edit.get_edit_text() == 'cmd3'
            edit.keypress(1, 'down')
            assert edit.get_edit_text() == 'z'
Esempio n. 6
0
 def test_insert(self):
     tests = [
         [("", 0), ("x", 1)],
         [("a", 0), ("xa", 1)],
         [("xa", 2), ("xax", 3)],
     ]
     with taddons.context() as tctx:
         for start, output in tests:
             cb = commander.CommandBuffer(tctx.master)
             cb.text, cb.cursor = start[0], start[1]
             cb.insert("x")
             assert cb.text == output[0]
             assert cb.cursor == output[1]
Esempio n. 7
0
 def test_backspace(self):
     tests = [
         [("", 0), ("", 0)],
         [("1", 0), ("1", 0)],
         [("1", 1), ("", 0)],
         [("123", 3), ("12", 2)],
         [("123", 2), ("13", 1)],
         [("123", 0), ("123", 0)],
     ]
     with taddons.context() as tctx:
         for start, output in tests:
             cb = commander.CommandBuffer(tctx.master)
             cb.text, cb.cursor = start[0], start[1]
             cb.backspace()
             assert cb.text == output[0]
             assert cb.cursor == output[1]
Esempio n. 8
0
    def test_cycle_completion(self):
        with taddons.context() as commander_tctx:
            cb = commander.CommandBuffer(commander_tctx.master)
            cb.text = "foo bar"
            cb.cursor = len(cb.text)
            cb.cycle_completion()

            ce = commander.CommandEdit(commander_tctx.master, "se")
            ce.keypress(1, 'tab')
            ce.update()
            ret = ce.cbuf.render()
            assert ret == [
                ('commander_command', 'set'),
                ('text', ' '),
                ('commander_hint', 'option '),
                ('commander_hint', 'value '),
            ]
Esempio n. 9
0
    def test_render(self):
        with taddons.context() as tctx:
            cb = commander.CommandBuffer(tctx.master)
            cb.text = "foo"
            assert cb.render()

            cb.text = "set view_filter '~bq test'"
            ret = cb.render()
            assert ret == [
                ('commander_command', 'set'),
                ('text', ' '),
                ('text', 'view_filter'),
                ('text', ' '),
                ('text', "'~bq test'"),
            ]

            cb.text = "set"
            ret = cb.render()
            assert ret == [
                ('commander_command', 'set'),
                ('text', ' '),
                ('commander_hint', 'option '),
                ('commander_hint', 'value '),
            ]
Esempio n. 10
0
 def test_flatten(self):
     with taddons.context() as tctx:
         cb = commander.CommandBuffer(tctx.master)
         assert cb.flatten("foo  bar") == "foo bar"
Esempio n. 11
0
 def test_render(self):
     with taddons.context() as tctx:
         cb = commander.CommandBuffer(tctx.master)
         cb.text = "foo"
         assert cb.render()
Esempio n. 12
0
 def test_cycle_completion(self):
     with taddons.context() as tctx:
         cb = commander.CommandBuffer(tctx.master)
         cb.text = "foo bar"
         cb.cursor = len(cb.text)
         cb.cycle_completion()