Example #1
0
    def testToOneWordLineWithLeadingWhitespace(self):
        set_text(self.view, '\n bar')
        r = self.R((0, 0), (0, 0))
        add_selection(self.view, r)

        pt = next_word_start(self.view, r.b, classes=CLASS_VI_INTERNAL_WORD_START)
        self.assertEqual(pt, 2)
Example #2
0
    def testMove2ToEol(self):
        set_text(self.view, 'foo bar\n')
        r = self.R((0, 0), (0, 0))
        add_selection(self.view, r)

        pt = word_starts(self.view, r.b, internal=True, count=2)
        self.assertEqual(pt, 7)
Example #3
0
    def testKeepsLeadingWhitespace(self):
        set_text(self.view, ''.join(('foo bar\n\t  foo bar\nfoo bar\n', )))
        add_selection(self.view, self.R((1, 0), (1, 10)))

        self.view.run_command('_vi_cc_action', {'mode': _MODE_INTERNAL_NORMAL})
        self.assertEqual(self.view.substr(self.R(0, self.view.size())),
                         'foo bar\n\t  \nfoo bar\n')
Example #4
0
    def testDeletesWholeLine(self):
        set_text(self.view, ''.join(('foo bar\nfoo bar\nfoo bar\n', )))
        add_selection(self.view, self.R((1, 0), (1, 7)))

        self.view.run_command('_vi_cc_action', {'mode': _MODE_INTERNAL_NORMAL})
        self.assertEqual(self.view.substr(self.R(0, self.view.size())),
                         'foo bar\n\nfoo bar\n')
Example #5
0
    def testMove1FromEmptyLineToLineWithLeadingWhiteSpace(self):
        set_text(self.view, '\n bar\n')
        r = self.R((0, 0), (0, 0))
        add_selection(self.view, r)

        pt = words(self.view, r.b, internal=True)
        self.assertEqual(pt, 1)
Example #6
0
    def testToWordStart(self):
        set_text(self.view, '::foo\n')
        r = self.R((0, 1), (0, 1))
        add_selection(self.view, r)

        pt = next_word_start(self.view, r.b)
        self.assertEqual(pt, 2)
Example #7
0
    def testToWhitespaceLine(self):
        set_text(self.view, ':\n  \n\n')
        r = self.R((0, 0), (0, 0))
        add_selection(self.view, r)

        pt = next_word_start(self.view, r.b)
        self.assertEqual(pt, 2)
Example #8
0
    def testMove2ToWhitespacelineFollowedByLeadingWhitespaceFromWordStart(self):
        set_text(self.view, 'foo\n  \n ccc\n')
        r = self.R((0, 0), (0, 0))
        add_selection(self.view, r)

        pt = word_starts(self.view, r.b, internal=True, count=2)
        self.assertEqual(pt, 12)
Example #9
0
    def testToOneCharWord(self):
        set_text(self.view, '  a foo bar\n')
        r = self.R((0, 0), (0, 0))
        add_selection(self.view, r)

        pt = next_word_start(self.view, r.b)
        self.assertEqual(pt, 2)
Example #10
0
    def testMove2ToOneWordLineFromWord(self):
        set_text(self.view, 'foo\nbar\nccc\n')
        r = self.R((0, 1), (0, 1))
        add_selection(self.view, r)

        pt = word_starts(self.view, r.b, internal=True, count=2)
        self.assertEqual(pt, 7)
Example #11
0
    def testToOneCharWord(self):
        set_text(self.view, 'foo a bar\n')
        r = self.R((0, 1), (0, 1))
        add_selection(self.view, r)

        pt = next_word_end(self.view, r.b)
        self.assertEqual(pt, 3)
Example #12
0
    def testToOneCharLineWithLeadingWhitespace(self):
        set_text(self.view, 'foo\n a\n\n')
        r = self.R((0, 1), (0, 1))
        add_selection(self.view, r)

        pt = next_word_end(self.view, r.b)
        self.assertEqual(pt, 3)
Example #13
0
    def testToEof(self):
        set_text(self.view, 'foo')
        r = self.R((0, 1), (0, 1))
        add_selection(self.view, r)

        pt = next_word_end(self.view, r.b)
        self.assertEqual(pt, 3)
Example #14
0
    def testToPunctuationStart(self):
        set_text(self.view, '  (foo)\n')
        r = self.R((0, 0), (0, 0))
        add_selection(self.view, r)

        pt = next_word_end(self.view, r.b)
        self.assertEqual(pt, 3)
Example #15
0
    def testToWhitespaceLine(self):
        set_text(self.view, 'foo\n  \n\n')
        r = self.R((0, 1), (0, 1))
        add_selection(self.view, r)

        pt = next_word_end(self.view, r.b)
        self.assertEqual(pt, 3)
Example #16
0
    def testToOneCharLine(self):
        set_text(self.view, 'foo\na\n\n')
        r = self.R((0, 0), (0, 0))
        add_selection(self.view, r)

        pt = next_word_end(self.view, r.b)
        self.assertEqual(pt, 3)
Example #17
0
    def testToOneWordLineWithLeadingWhitespace(self):
        set_text(self.view, 'foo\n bar\nbaz')
        r = self.R((0, 0), (0, 0))
        add_selection(self.view, r)

        pt = next_word_end(self.view, r.b)
        self.assertEqual(pt, 3)
Example #18
0
    def testToWordStart(self):
        set_text(self.view, ':foo\n')
        r = self.R((0, 0), (0, 0))
        add_selection(self.view, r)

        pt = next_word_end(self.view, r.b)
        self.assertEqual(pt, 1)
Example #19
0
    def testMove2ToWhitespaceline(self):
        set_text(self.view, 'foo\n  \nccc\n')
        r = self.R((0, 1), (0, 1))
        add_selection(self.view, r)

        pt = word_starts(self.view, r.b, internal=True, count=2)
        self.assertEqual(pt, 10)
Example #20
0
    def testMove3AndSwallowLastNewlineChar(self):
        set_text(self.view, '\nfoo\n bar\n')
        r = self.R((0, 0), (0, 0))
        add_selection(self.view, r)

        pt = word_starts(self.view, r.b, internal=True, count=3)
        self.assertEqual(pt, 10)
Example #21
0
    def testToOneCharLine(self):
        set_text(self.view, '  \na\n\n')
        r = self.R((0, 0), (0, 0))
        add_selection(self.view, r)

        pt = next_word_end(self.view, r.b)
        self.assertEqual(pt, 4)
Example #22
0
    def testMove1ToEol(self):
        set_text(self.view, 'x\n')
        r = self.R((0, 0), (0, 0))
        add_selection(self.view, r)

        pt = word_ends(self.view, r.b, internal=True, count=1)
        self.assertEqual(pt, 0)
Example #23
0
    def testToOneWordLineWithLeadingWhitespace(self):
        set_text(self.view, '::\n bar\n')
        r = self.R((0, 1), (0, 1))
        add_selection(self.view, r)

        pt = next_word_start(self.view, r.b)
        self.assertEqual(pt, 3)
Example #24
0
    def testToEmptyLine(self):
        set_text(self.view, '\n\n\n')
        r = self.R((0, 0), (0, 0))
        add_selection(self.view, r)

        pt = next_word_start(self.view, r.b)
        self.assertEqual(pt, 1)
Example #25
0
    def testToOneWordLine(self):
        set_text(self.view, '   \nfoo\nbar')
        r = self.R((0, 0), (0, 0))
        add_selection(self.view, r)

        pt = next_word_start(self.view, r.b)
        self.assertEqual(pt, 4)
Example #26
0
    def testToOneWordLineWithLeadingWhitespace(self):
        set_text(self.view, '\n bar')
        r = self.R((0, 0), (0, 0))
        add_selection(self.view, r)

        pt = next_word_start(self.view, r.b, internal=True)
        self.assertEqual(pt, 2)
Example #27
0
    def testToWhitespaceLine(self):
        set_text(self.view, '\n  ')
        r = self.R((0, 0), (0, 0))
        add_selection(self.view, r)

        pt = next_word_start(self.view, r.b, classes=CLASS_VI_INTERNAL_WORD_START)
        self.assertEqual(pt, 3)
Example #28
0
    def testToWhitespaceLine(self):
        set_text(self.view, '\n  ')
        r = self.R((0, 0), (0, 0))
        add_selection(self.view, r)

        pt = next_word_start(self.view, r.b, internal=True)
        self.assertEqual(pt, 3)
Example #29
0
    def testMove2ToLineWithLeadingWhiteSpace(self):
        set_text(self.view, '\n bar')
        r = self.R((0, 0), (0, 0))
        add_selection(self.view, r)

        pt = word_starts(self.view, r.b, count=2, internal=True)
        self.assertEqual(pt, 6)
Example #30
0
    def testToOneCharLine(self):
        set_text(self.view, '::\na\n\n')
        r = self.R((0, 1), (0, 1))
        add_selection(self.view, r)

        pt = next_word_start(self.view, r.b)
        self.assertEqual(pt, 3)
Example #31
0
    def testToPunctuationStart(self):
        set_text(self.view, ':: (foo)\n')
        r = self.R((0, 1), (0, 1))
        add_selection(self.view, r)

        pt = next_word_start(self.view, r.b)
        self.assertEqual(pt, 3)
Example #32
0
    def testMove10(self):
        set_text(self.view, ''.join(('foo bar\n',) * 5))
        r = self.R((0, 0), (0, 0))
        add_selection(self.view, r)

        pt = word_starts(self.view, r.b, count=9)
        self.assertEqual(pt, 36)
Example #33
0
    def testToEofWithNewline(self):
        set_text(self.view, 'foo\n')
        r = self.R((0, 0), (0, 0))
        add_selection(self.view, r)

        pt = next_word_end(self.view, r.b)
        self.assertEqual(pt, 3)
Example #34
0
    def testMove1ToWhitespaceLine(self):
        set_text(self.view, '\n  \n')
        r = self.R((0, 0), (0, 0))
        add_selection(self.view, r)

        pt = word_starts(self.view, r.b, count=1, internal=True)
        self.assertEqual(pt, 1)
Example #35
0
    def testMove2ToLineWithLeadingWhiteSpaceFromWordStart(self):
        set_text(self.view, 'foo\n\nbar\n')
        r = self.R((0, 0), (0, 0))
        add_selection(self.view, r)

        pt = word_starts(self.view, r.b, internal=True, count=2)
        self.assertEqual(pt, 5)
Example #36
0
    def testMove2ToOneWordLine(self):
        set_text(self.view, '\nfoo\n')
        r = self.R((0, 0), (0, 0))
        add_selection(self.view, r)

        pt = word_starts(self.view, r.b, internal=True, count=2)
        self.assertEqual(pt, 5)
Example #37
0
    def testToOneCharLineWithLeadingWhitespace(self):
        set_text(self.view, '  \n a\n\n')
        r = self.R((0, 0), (0, 0))
        add_selection(self.view, r)

        pt = next_word_start(self.view, r.b)
        self.assertEqual(pt, 3)
Example #38
0
    def testMove1(self):
        set_text(self.view, 'foo bar\n')
        r = self.R((0, 0), (0, 0))
        add_selection(self.view, r)

        pt = word_starts(self.view, r.b)
        self.assertEqual(pt, 4)
Example #39
0
    def testToEofWithNewline(self):
        set_text(self.view, '::\n')
        r = self.R((0, 1), (0, 1))
        add_selection(self.view, r)

        pt = next_word_start(self.view, r.b)
        self.assertEqual(pt, 3)
Example #40
0
    def testMove2(self):
        set_text(self.view, 'foo bar fizz\n')
        r = self.R((0, 0), (0, 0))
        add_selection(self.view, r)

        pt = word_starts(self.view, r.b, count=2)
        self.assertEqual(pt, 8)
Example #41
0
    def testToEof(self):
        set_text(self.view, '   ')
        r = self.R((0, 0), (0, 0))
        add_selection(self.view, r)

        pt = next_word_start(self.view, r.b)
        self.assertEqual(pt, 3)
Example #42
0
    def testMove2ToWhitespacelineFollowedByLeadingWhitespaceFromWordStart(
            self):
        set_text(self.view, 'foo\n  \n ccc\n')
        r = self.R((0, 0), (0, 0))
        add_selection(self.view, r)

        pt = word_starts(self.view, r.b, internal=True, count=2)
        self.assertEqual(pt, 12)
Example #43
0
    def testCanMoveInInternalNormalModeWithCount(self):
        set_text(self.view, 'foo bar baz')
        add_selection(self.view, a=0, b=0)

        self.view.run_command('_vi_l', {
            'mode': _MODE_INTERNAL_NORMAL,
            'count': 10
        })
        self.assertEqual(self.R(0, 10), first_sel(self.view))
Example #44
0
    def testCanMoveInInternalNormalModeWithCount(self):
        set_text(self.view, 'abc\nabc\nabc\nabc\n')
        add_selection(self.view, a=0, b=0)

        self.view.run_command('_vi_dollar', {
            'mode': _MODE_INTERNAL_NORMAL,
            'count': 3
        })
        self.assertEqual(self.R(0, 12), first_sel(self.view))
Example #45
0
    def testSelectsWholeLine(self):
        set_text(self.view, ''.join(('foo bar\nfoo bar\nfoo bar\n', )))
        add_selection(self.view, self.R((1, 2), (1, 2)))

        self.view.run_command('_vi_cc_motion', {
            'mode': _MODE_INTERNAL_NORMAL,
            'count': 1
        })
        self.assertEqual(self.R((1, 0), (1, 7)), first_sel(self.view))
Example #46
0
    def testStopsAtRightEndInInternalNormalMode(self):
        set_text(self.view, 'abc')
        add_selection(self.view, a=0, b=0)

        self.view.run_command('_vi_l', {
            'mode': _MODE_INTERNAL_NORMAL,
            'count': 10000
        })
        self.assertEqual(self.R(0, 3), first_sel(self.view))
Example #47
0
    def testCanRepositionCaret(self):
        set_text(self.view, 'abc\nxxx\nabc\nabc')
        add_selection(self.view, self.R((1, 0), (1, 0)))

        self.view.run_command('ex_move', {'address': '3'})

        actual = list(self.view.sel())
        expected = [self.R((2, 0), (2, 0))]
        self.assertEqual(expected, actual)
Example #48
0
    def testCanMoveToSameLine(self):
        set_text(self.view, 'abc\nxxx\nabc\nabc')
        add_selection(self.view, self.R((1, 0), (1, 0)))

        self.view.run_command('ex_move', {'address': '2'})

        actual = self.view.substr(self.R(0, self.view.size()))
        expected = 'abc\nxxx\nabc\nabc'
        self.assertEqual(expected, actual)
    def testCanMoveInModeVisualLine(self):
        set_text(self.view, 'abc\nabc\n')
        add_selection(self.view, a=0, b=4)

        self.view.run_command('_vi_big_g', {
            'mode': MODE_VISUAL_LINE,
            'count': 1
        })
        self.assertEqual(self.R(0, 8), first_sel(self.view))
Example #50
0
    def testCanDeleteDefaultLineRange(self):
        set_text(self.view, 'abc\nxxx\nabc\nabc')
        add_selection(self.view, self.R((1, 0), (1, 0)))

        self.view.run_command('ex_delete')

        actual = self.view.substr(self.R(0, self.view.size()))
        expected = 'abc\nabc\nabc'
        self.assertEqual(expected, actual)
Example #51
0
    def testCanMoveInVisualLineModeWithCount(self):
        set_text(self.view, 'abc\nabc\nabc\nabc\n')
        add_selection(self.view, a=0, b=4)

        self.view.run_command('_vi_dollar', {
            'mode': MODE_VISUAL_LINE,
            'count': 3
        })
        self.assertEqual(self.R(0, 12), first_sel(self.view))
    def testCanMoveInModeInternalNormal(self):
        set_text(self.view, 'abc\nabc\n')
        add_selection(self.view, a=0, b=0)

        self.view.run_command('_vi_big_g', {
            'mode': _MODE_INTERNAL_NORMAL,
            'count': 1
        })
        self.assertEqual(self.R(0, 8), first_sel(self.view))
Example #53
0
    def testCanMoveInVisualLineModeWithReversedSelection(self):
        set_text(self.view, 'abc\nabc\nabc\nabc\n')
        add_selection(self.view, a=4, b=0)

        self.view.run_command('_vi_dollar', {
            'mode': MODE_VISUAL_LINE,
            'count': 1
        })
        self.assertEqual(self.R(4, 1), first_sel(self.view))
Example #54
0
    def testMoveTooFar(self):
        set_text(self.view, 'foo\nbar\nbaz')
        add_selection(self.view, a=1, b=1)

        self.view.run_command('_vi_j', {'mode': MODE_NORMAL, 'count': 10000, 'xpos': 1})

        target = self.view.text_point(2, 1)
        expected = self.R(target, target)

        self.assertEqual(expected, first_sel(self.view))
Example #55
0
    def testMoveOne(self):
        set_text(self.view, 'abc\nabc\nabc')
        add_selection(self.view, a=1, b=2)

        self.view.run_command('_vi_j', {'mode': MODE_VISUAL, 'count': 1, 'xpos': 1})

        target = self.view.text_point(1, 2)
        expected = self.R(1, target)

        self.assertEqual(expected, first_sel(self.view))
Example #56
0
    def testMoveFromEmptyLineToEmptyLine(self):
        set_text(self.view, '\n\nbar')
        add_selection(self.view, a=0, b=0)

        self.view.run_command('_vi_j', {'mode': MODE_NORMAL, 'count': 1, 'xpos': 0})

        target = self.view.text_point(1, 0)
        expected = self.R(target, target)

        self.assertEqual(expected, first_sel(self.view))
Example #57
0
    def testMoveOntoLongerLine(self):
        set_text(self.view, 'foo\nfoo bar\nfoo bar')
        add_selection(self.view, a=1, b=1)

        self.view.run_command('_vi_j', {'mode': MODE_NORMAL, 'count': 1, 'xpos': 1})

        target = self.view.text_point(1, 1)
        expected = self.R(target, target)

        self.assertEqual(expected, first_sel(self.view))
Example #58
0
    def testMoveMany(self):
        set_text(self.view, ''.join(('abc\n',) * 60))
        add_selection(self.view, a=1, b=1)

        self.view.run_command('_vi_j', {'mode': MODE_NORMAL, 'count': 50, 'xpos': 1})

        target = self.view.text_point(50, 1)
        expected = self.R(target, target)

        self.assertEqual(expected, first_sel(self.view))
Example #59
0
    def testMoveReversedDownFromSameLine(self):
        set_text(self.view, 'abc\nabc\nabc')
        add_selection(self.view, a=6, b=5)

        self.view.run_command('_vi_j', {'mode': MODE_VISUAL, 'count': 1, 'xpos': 1})

        target = self.view.text_point(2, 2)
        expected = self.R(5, target)

        self.assertEqual(expected, first_sel(self.view))
Example #60
0
    def testMoveReversedNoCrossOver(self):
        set_text(self.view, 'abc\nabc\nabc')
        add_selection(self.view, a=10, b=1)

        self.view.run_command('_vi_j', {'mode': MODE_VISUAL, 'count': 1, 'xpos': 1})

        target = self.view.text_point(1, 1)
        expected = self.R(10, target)

        self.assertEqual(expected, first_sel(self.view))