Example #1
0
 def setUp(self):
     sublime.set_clipboard('')
     registers._REGISTER_DATA = {}
     TestsState.view.settings().erase('vintage')
     TestsState.view.settings().erase('vintageous_use_sys_clipboard')
     self.regs = VintageState(TestsState.view).registers
     self.regs.view = mock.Mock()
Example #2
0
    def testDebug(self, mocked_state):
        x = mock.Mock()
        x.settings.view = {'vintageous_verbose': True}
        mocked_state.return_value = x

        with mock.patch.object(builtins, 'print') as p:
            self.vi_run.debug(['one', 'two'])
            p.assert_called_once_with('Vintageous:', ['one', 'two'])
Example #3
0
 def testCanRestoreOriginalCarets(self):
     vi_cmd_data = {'restore_original_carets': True}
     self.vi_run.old_sels = [100]
     sel = mock.Mock()
     self.vi_run.view.sel.return_value = sel
     self.vi_run.restore_original_carets_if_needed(vi_cmd_data)
     sel.clear.assert_called_once_with()
     sel.add.assert_called_with(100)
Example #4
0
 def testCanDetectAlignXpos(self, mocked_state):
     x = mock.Mock()
     x.xpos = 100
     mocked_state.return_value = x
     vi_cmd_data = {'selection_modifier': [], 'align_with_xpos': True}
     with mock.patch.object(self.vi_run.view, 'run_command') as rc:
         self.vi_run.do_modify_selections(vi_cmd_data)
         rc.assert_called_with('_align_b_with_xpos', {'xpos': 100})
Example #5
0
    def testDontAddJumpToListIfNotRequested(self):
        vi_cmd_data = {'is_jump': False}

        with mock.patch.object(self.vi_run.view, 'window') as rc:
            x = mock.Mock()
            rc.return_value = x

            self.vi_run.add_to_jump_list(vi_cmd_data)
            self.assertEqual(rc.call_count, 0)
            self.assertEqual(x.run_command.call_count, 0)
Example #6
0
    def testAddJumpToList(self):
        vi_cmd_data = {'is_jump': True}

        with mock.patch.object(self.vi_run.view, 'window') as rc:
            x = mock.Mock()
            rc.return_value = x

            self.vi_run.add_to_jump_list(vi_cmd_data)
            self.assertEqual(rc.call_count, 1)
            x.run_command.assert_called_once_with('vi_add_to_jump_list')
Example #7
0
 def testCallsYank(self, mocked_regs):
     mocked_regs.yank = mock.Mock()
     vi_cmd_data = {
         'action': {
             'command': 'foo',
             'args': {}
         },
         '_repeat_action': False,
         'is_window_command': False,
     }
     self.vi_run.do_action(vi_cmd_data)
     mocked_regs.yank.assert_called_once_with(vi_cmd_data)
Example #8
0
 def testRunsCommandOnceIfMustNotRepeatAction(self, mocked_regs):
     mocked_regs.yank = mock.Mock()
     vi_cmd_data = {
         'action': {
             'command': 'foo',
             'args': {}
         },
         '_repeat_action': False,
         'is_window_command': False,
     }
     self.vi_run.do_action(vi_cmd_data)
     self.vi_run.view.run_command.assert_called_once_with('foo', {})
Example #9
0
 def setUp(self):
     state = mock.Mock()
     state.count = 100
     state.user_provided_count = 200
     state.register = 300
     state.mode = 400
     state.user_input = 500
     state.last_buffer_search = 600
     state.last_character_search = 700
     state.xpos = 800
     self.state = state
     self.cmd_data = CmdData(self.state)
Example #10
0
 def testRunsCommandExpectedTimes(self, mocked_regs):
     mocked_regs.yank = mock.Mock()
     vi_cmd_data = {
         'action': {
             'command': 'foo',
             'args': {}
         },
         '_repeat_action': True,
         'count': 10,
         'is_window_command': False,
     }
     self.vi_run.do_action(vi_cmd_data)
     self.assertEqual(self.vi_run.view.run_command.call_count, 10)
Example #11
0
 def setUp(self):
     state = mock.Mock()
     state.count = 100
     state.user_provided_count = 200
     state.register = 300
     state.mode = 400
     state.user_input = 500
     state.last_buffer_search = 600
     state.last_character_search = 700
     state.xpos = 800
     self.state = state
     self.state.settings.vi = {
         'user_motion_input': 'foo',
         'user_action_input': 'bar'
     }
     self.cmd_data = CmdData(self.state)
Example #12
0
    def testAbortsActionIfMotionFailedInModeVisual(self, mocked_state):
        vi_cmd_data = {
            'creates_jump_at_current_position': False,
            'is_jump': False,
            'action': 'foo',
            'mode': MODE_VISUAL,
            'cancel_action_if_motion_fails': True,
            'motion': 'bar',
            'motion_required': None,
            'must_update_xpos': False,
            'scroll_into_view': False,
            'next_mode': 10,
            'follow_up_mode': 100,
        }

        self.vi_run.view.sel.return_value = [sublime.Region(0, 2)]

        thing = mock.Mock()
        thing.next_mode = 0
        mocked_state.return_value = thing

        self.vi_run.view.sel.return_value = [500]

        with mock.patch.object(self.vi_run, 'save_caret_pos') as savec, \
             mock.patch.object(self.vi_run, 'do_whole_motion') as dowhm, \
             mock.patch.object(self.vi_run, 'debug') as debug, \
             mock.patch.object(self.vi_run, 'do_post_action') as doposac, \
             mock.patch.object(self.vi_run, 'do_modify_selections') as domodsel, \
             mock.patch.object(self.vi_run, 'restore_original_carets_if_needed') as restorc, \
             mock.patch.object(self.vi_run, 'add_to_jump_list') as addtjl, \
             mock.patch.object(self.vi_run, 'do_action') as doac, \
             mock.patch('Vintageous.run.utils') as ut:

            self.vi_run.run(None, **vi_cmd_data)
            self.assertEqual(savec.call_count, 1)
            self.assertEqual(dowhm.call_count, 1)
            self.assertEqual(debug.call_count, 1)
            self.assertEqual(doposac.call_count, 1)
            self.assertEqual(domodsel.call_count, 1)
            self.assertEqual(restorc.call_count, 2)

            self.assertEqual(thing.next_mode, 10)
            self.assertEqual(thing.next_mode_command, 100)

            self.assertEqual(addtjl.call_count, 0)
            doac.assertEqual(doac.call_count, 0)
            self.assertEqual(ut.blink.call_count, 1)
Example #13
0
    def testCanDoLoneAction(self, mocked_state):
        vi_cmd_data = {
            'creates_jump_at_current_position': False,
            'is_jump': False,
            'action': 'foo',
            'mode': None,
            'motion': None,
            'motion_required': None,
            'must_update_xpos': False,
            'scroll_into_view': False,
            'next_mode': 10,
            'follow_up_mode': 100,
        }

        self.vi_run.view.sel.return_value = []

        thing = mock.Mock()
        thing.next_mode = 0
        mocked_state.return_value = thing

        self.vi_run.view.sel.return_value = [500]

        with mock.patch.object(self.vi_run, 'save_caret_pos') as savec, \
             mock.patch.object(self.vi_run, 'do_whole_motion') as dowhm, \
             mock.patch.object(self.vi_run, 'debug') as debug, \
             mock.patch.object(self.vi_run, 'do_post_action') as doposac, \
             mock.patch.object(self.vi_run, 'do_modify_selections') as domodsel, \
             mock.patch.object(self.vi_run, 'restore_original_carets_if_needed') as restorc, \
             mock.patch.object(self.vi_run, 'add_to_jump_list') as addtjl, \
             mock.patch.object(self.vi_run, 'do_action') as doac:

            self.vi_run.run(None, **vi_cmd_data)
            self.assertEqual(savec.call_count, 1)
            self.assertEqual(dowhm.call_count, 0)
            self.assertEqual(debug.call_count, 1)
            self.assertEqual(doposac.call_count, 1)
            self.assertEqual(domodsel.call_count, 1)
            self.assertEqual(restorc.call_count, 1)

            self.assertEqual(thing.next_mode, 10)
            self.assertEqual(thing.next_mode_command, 100)

            self.assertEqual(addtjl.call_count, 0)
            doac.assert_called_with(vi_cmd_data)
Example #14
0
    def testSignalsErrorIfLoneMotionFails(self, mocked_state):
        vi_cmd_data = {
            'creates_jump_at_current_position': False,
            'is_jump': False,
            'action': None,
            'mode': MODE_NORMAL,
            'must_update_xpos': False,
            'scroll_into_view': False,
            'next_mode': 10,
            'follow_up_mode': 100,
        }

        self.vi_run.view.sel.return_value = []

        thing = mock.Mock()
        thing.next_mode = 0
        mocked_state.return_value = thing

        self.vi_run.view.sel.return_value = [500]

        with mock.patch.object(self.vi_run, 'save_caret_pos') as savec, \
             mock.patch.object(self.vi_run, 'do_whole_motion') as dowhm, \
             mock.patch.object(self.vi_run, 'debug') as debug, \
             mock.patch.object(self.vi_run, 'do_post_action') as doposac, \
             mock.patch.object(self.vi_run, 'do_modify_selections') as domodsel, \
             mock.patch.object(self.vi_run, 'restore_original_carets_if_needed') as restorc, \
             mock.patch.object(self.vi_run, 'add_to_jump_list') as addtjl, \
             mock.patch('Vintageous.run.utils') as ut:

            self.vi_run.run(None, **vi_cmd_data)
            self.assertEqual(savec.call_count, 1)
            self.assertEqual(dowhm.call_count, 1)
            self.assertEqual(debug.call_count, 1)
            self.assertEqual(doposac.call_count, 1)
            self.assertEqual(domodsel.call_count, 1)
            self.assertEqual(restorc.call_count, 1)

            self.assertEqual(thing.next_mode, 10)
            self.assertEqual(thing.next_mode_command, 100)

            self.assertEqual(addtjl.call_count, 0)
            self.assertEqual(ut.blink.call_count, 1)
Example #15
0
    def testFinallySectionWhenMustScrollIntoView(self, mocked_state):
        vi_cmd_data = {
            '_repeat_action': True,
            'creates_jump_at_current_position': False,
            'is_jump': False,
            'action': None,
            'mode': None,
            'must_update_xpos': False,
            'scroll_into_view': True,
            'scroll_command': None,
            'next_mode': 10,
            'follow_up_mode': 100,
        }

        self.vi_run.view.sel.return_value = []

        thing = mock.Mock()
        thing.next_mode = 0
        mocked_state.return_value = thing

        self.vi_run.view.sel.return_value = [500]

        with mock.patch.object(self.vi_run, 'save_caret_pos') as savec, \
             mock.patch.object(self.vi_run, 'do_whole_motion') as dowhm, \
             mock.patch.object(self.vi_run, 'debug') as debug, \
             mock.patch.object(self.vi_run, 'do_post_action') as doposac, \
             mock.patch.object(self.vi_run, 'do_modify_selections') as domodsel, \
             mock.patch.object(self.vi_run, 'restore_original_carets_if_needed') as restorc:

            self.vi_run.run(None, **vi_cmd_data)
            self.assertEqual(savec.call_count, 1)
            self.assertEqual(dowhm.call_count, 1)
            self.assertEqual(debug.call_count, 1)
            self.assertEqual(doposac.call_count, 1)
            self.assertEqual(domodsel.call_count, 1)
            self.assertEqual(restorc.call_count, 1)

            self.assertEqual(thing.next_mode, 10)
            self.assertEqual(thing.next_mode_command, 100)

            self.vi_run.view.show.assert_called_with(500)
Example #16
0
 def setUp(self):
     self.vi_run = ViRunCommand(mock.Mock())