<commit_before>import unittest

from Vintageous.vi.constants import _MODE_INTERNAL_NORMAL
from Vintageous.vi.constants import MODE_NORMAL
from Vintageous.vi.constants import MODE_VISUAL
from Vintageous.vi.constants import MODE_VISUAL_LINE

from Vintageous.tests import set_text
from Vintageous.tests import add_sel
from Vintageous.tests import get_sel
from Vintageous.tests import first_sel
from Vintageous.tests import BufferTest


class Test_vi_ctrl_x_InNormalMode(BufferTest):
    def testAbortsIfNoDigitsInAnyLine(self):
        set_text(self.view, ''.join(('foo bar\nfoo bar\nfoo bar\n',)))
        add_sel(self.view, self.R((0, 0), (0, 0)))
        add_sel(self.view, self.R((1, 0), (1, 0)))
        add_sel(self.view, self.R((2, 0), (2, 0)))

        self.view.run_command('_vi_ctrl_x', {'mode': _MODE_INTERNAL_NORMAL, 'count': 1})
        self.assertEqual(self.view.substr(self.R(0, self.view.size())), 'foo bar\nfoo bar\nfoo bar\n')

    def testDecreaseDigitsUnderSelection(self):
        set_text(self.view, ''.join(('foo 100\nfoo 200\nfoo 300\n',)))
        add_sel(self.view, self.R((0, 4), (0, 4)))
        add_sel(self.view, self.R((1, 4), (1, 4)))
        add_sel(self.view, self.R((2, 4), (2, 4)))

        self.view.run_command('_vi_ctrl_x', {'mode': _MODE_INTERNAL_NORMAL, 'count': 1})
        self.assertEqual(self.view.substr(self.R(0, self.view.size())), 'foo 99\nfoo 199\nfoo 299\n')

    def testDecreasePrefixedDigitsUnderSelection(self):
        set_text(self.view, ''.join(('foo 10\nfoo 10\nfoo 10\n',)))
        add_sel(self.view, self.R((0, 4), (0, 4)))
        add_sel(self.view, self.R((1, 4), (1, 4)))
        add_sel(self.view, self.R((2, 4), (2, 4)))

        self.view.run_command('_vi_ctrl_x', {'mode': _MODE_INTERNAL_NORMAL, 'count': 11})
        self.assertEqual(self.view.substr(self.R(0, self.view.size())), 'foo -1\nfoo -1\nfoo -1\n')

    def testDecreaseSuffixeddDigitsUnderSelection(self):
        set_text(self.view, ''.join(('foo 10px\nfoo 10px\nfoo 10px\n',)))
        add_sel(self.view, self.R((0, 4), (0, 4)))
        add_sel(self.view, self.R((1, 4), (1, 4)))
        add_sel(self.view, self.R((2, 4), (2, 4)))

        self.view.run_command('_vi_ctrl_x', {'mode': _MODE_INTERNAL_NORMAL, 'count': 11})
        self.assertEqual(self.view.substr(self.R(0, self.view.size())), 'foo -1px\nfoo -1px\nfoo -1px\n')

    def testDecreaseDigitsAfterSelection(self):
        set_text(self.view, ''.join(('foo 100\nfoo 200\nfoo 300\n',)))
        add_sel(self.view, self.R((0, 0), (0, 0)))
        add_sel(self.view, self.R((1, 0), (1, 0)))
        add_sel(self.view, self.R((2, 0), (2, 0)))

        self.view.run_command('_vi_ctrl_x', {'mode': _MODE_INTERNAL_NORMAL, 'count': 1})
        self.assertEqual(self.view.substr(self.R(0, self.view.size())), 'foo 99\nfoo 199\nfoo 299\n')

    def testDecreaseDigitsAfterSelectionByCount(self):
        set_text(self.view, ''.join(('foo 100\nfoo 200\nfoo 300\n',)))
        add_sel(self.view, self.R((0, 4), (0, 4)))
        add_sel(self.view, self.R((1, 4), (1, 4)))
        add_sel(self.view, self.R((2, 4), (2, 4)))

        self.view.run_command('_vi_ctrl_x', {'mode': _MODE_INTERNAL_NORMAL, 'count': 10})
        self.assertEqual(self.view.substr(self.R(0, self.view.size())), 'foo 90\nfoo 190\nfoo 290\n')

    def testAbortIfOnlySomeSelectionsHaveDigits(self):
        set_text(self.view, ''.join(('foo 100\nfoo bar\nfoo 300\n',)))
        add_sel(self.view, self.R((0, 4), (0, 4)))
        add_sel(self.view, self.R((1, 4), (1, 4)))
        add_sel(self.view, self.R((2, 4), (2, 4)))

        self.view.run_command('_vi_ctrl_x', {'mode': _MODE_INTERNAL_NORMAL, 'count': 1})
        self.assertEqual(self.view.substr(self.R(0, self.view.size())), 'foo 100\nfoo bar\nfoo 300\n')

    def testAbortIfOnlySomeSelectionsHaveDigitsAfterThem(self):
        set_text(self.view, ''.join(('foo 100\nfoo bar\nfoo 300\n',)))
        add_sel(self.view, self.R((0, 0), (0, 0)))
        add_sel(self.view, self.R((1, 0), (1, 0)))
        add_sel(self.view, self.R((2, 0), (2, 0)))

        self.view.run_command('_vi_ctrl_x', {'mode': _MODE_INTERNAL_NORMAL, 'count': 1})
        self.assertEqual(self.view.substr(self.R(0, self.view.size())), 'foo 100\nfoo bar\nfoo 300\n')<commit_msg>add tests for ctrl-a<commit_after>import unittest

from Vintageous.vi.constants import _MODE_INTERNAL_NORMAL
from Vintageous.vi.constants import MODE_NORMAL
from Vintageous.vi.constants import MODE_VISUAL
from Vintageous.vi.constants import MODE_VISUAL_LINE

from Vintageous.tests import set_text
from Vintageous.tests import add_sel
from Vintageous.tests import get_sel
from Vintageous.tests import first_sel
from Vintageous.tests import BufferTest


class Test_vi_ctrl_x_InNormalMode(BufferTest):
    def testAbortsIfNoDigitsInAnyLine(self):
        set_text(self.view, ''.join(('foo bar\nfoo bar\nfoo bar\n',)))
        add_sel(self.view, self.R((0, 0), (0, 0)))
        add_sel(self.view, self.R((1, 0), (1, 0)))
        add_sel(self.view, self.R((2, 0), (2, 0)))

        self.view.run_command('_vi_ctrl_x', {'mode': _MODE_INTERNAL_NORMAL, 'count': 1})
        self.assertEqual(self.view.substr(self.R(0, self.view.size())), 'foo bar\nfoo bar\nfoo bar\n')

    def testDecreaseDigitsUnderSelection(self):
        set_text(self.view, ''.join(('foo 100\nfoo 200\nfoo 300\n',)))
        add_sel(self.view, self.R((0, 4), (0, 4)))
        add_sel(self.view, self.R((1, 4), (1, 4)))
        add_sel(self.view, self.R((2, 4), (2, 4)))

        self.view.run_command('_vi_ctrl_x', {'mode': _MODE_INTERNAL_NORMAL, 'count': 1})
        self.assertEqual(self.view.substr(self.R(0, self.view.size())), 'foo 99\nfoo 199\nfoo 299\n')

    def testDecreasePrefixedDigitsUnderSelection(self):
        set_text(self.view, ''.join(('foo 10\nfoo 10\nfoo 10\n',)))
        add_sel(self.view, self.R((0, 4), (0, 4)))
        add_sel(self.view, self.R((1, 4), (1, 4)))
        add_sel(self.view, self.R((2, 4), (2, 4)))

        self.view.run_command('_vi_ctrl_x', {'mode': _MODE_INTERNAL_NORMAL, 'count': 11})
        self.assertEqual(self.view.substr(self.R(0, self.view.size())), 'foo -1\nfoo -1\nfoo -1\n')

    def testDecreaseSuffixeddDigitsUnderSelection(self):
        set_text(self.view, ''.join(('foo 10px\nfoo 10px\nfoo 10px\n',)))
        add_sel(self.view, self.R((0, 4), (0, 4)))
        add_sel(self.view, self.R((1, 4), (1, 4)))
        add_sel(self.view, self.R((2, 4), (2, 4)))

        self.view.run_command('_vi_ctrl_x', {'mode': _MODE_INTERNAL_NORMAL, 'count': 11})
        self.assertEqual(self.view.substr(self.R(0, self.view.size())), 'foo -1px\nfoo -1px\nfoo -1px\n')

    def testDecreaseDigitsAfterSelection(self):
        set_text(self.view, ''.join(('foo 100\nfoo 200\nfoo 300\n',)))
        add_sel(self.view, self.R((0, 0), (0, 0)))
        add_sel(self.view, self.R((1, 0), (1, 0)))
        add_sel(self.view, self.R((2, 0), (2, 0)))

        self.view.run_command('_vi_ctrl_x', {'mode': _MODE_INTERNAL_NORMAL, 'count': 1})
        self.assertEqual(self.view.substr(self.R(0, self.view.size())), 'foo 99\nfoo 199\nfoo 299\n')

    def testDecreaseDigitsAfterSelectionByCount(self):
        set_text(self.view, ''.join(('foo 100\nfoo 200\nfoo 300\n',)))
        add_sel(self.view, self.R((0, 4), (0, 4)))
        add_sel(self.view, self.R((1, 4), (1, 4)))
        add_sel(self.view, self.R((2, 4), (2, 4)))

        self.view.run_command('_vi_ctrl_x', {'mode': _MODE_INTERNAL_NORMAL, 'count': 10})
        self.assertEqual(self.view.substr(self.R(0, self.view.size())), 'foo 90\nfoo 190\nfoo 290\n')

    def testAbortIfOnlySomeSelectionsHaveDigits(self):
        set_text(self.view, ''.join(('foo 100\nfoo bar\nfoo 300\n',)))
        add_sel(self.view, self.R((0, 4), (0, 4)))
        add_sel(self.view, self.R((1, 4), (1, 4)))
        add_sel(self.view, self.R((2, 4), (2, 4)))

        self.view.run_command('_vi_ctrl_x', {'mode': _MODE_INTERNAL_NORMAL, 'count': 1})
        self.assertEqual(self.view.substr(self.R(0, self.view.size())), 'foo 100\nfoo bar\nfoo 300\n')

    def testAbortIfOnlySomeSelectionsHaveDigitsAfterThem(self):
        set_text(self.view, ''.join(('foo 100\nfoo bar\nfoo 300\n',)))
        add_sel(self.view, self.R((0, 0), (0, 0)))
        add_sel(self.view, self.R((1, 0), (1, 0)))
        add_sel(self.view, self.R((2, 0), (2, 0)))

        self.view.run_command('_vi_ctrl_x', {'mode': _MODE_INTERNAL_NORMAL, 'count': 1})
        self.assertEqual(self.view.substr(self.R(0, self.view.size())), 'foo 100\nfoo bar\nfoo 300\n')


class Test_vi_ctrl_a_InNormalMode(BufferTest):
    def testAbortsIfNoDigitsInAnyLine(self):
        set_text(self.view, ''.join(('foo bar\nfoo bar\nfoo bar\n',)))
        add_sel(self.view, self.R((0, 0), (0, 0)))
        add_sel(self.view, self.R((1, 0), (1, 0)))
        add_sel(self.view, self.R((2, 0), (2, 0)))

        self.view.run_command('_vi_ctrl_a', {'mode': _MODE_INTERNAL_NORMAL, 'count': 1})
        self.assertEqual(self.view.substr(self.R(0, self.view.size())), 'foo bar\nfoo bar\nfoo bar\n')

    def testDecreaseDigitsUnderSelection(self):
        set_text(self.view, ''.join(('foo 100\nfoo 200\nfoo 300\n',)))
        add_sel(self.view, self.R((0, 4), (0, 4)))
        add_sel(self.view, self.R((1, 4), (1, 4)))
        add_sel(self.view, self.R((2, 4), (2, 4)))

        self.view.run_command('_vi_ctrl_a', {'mode': _MODE_INTERNAL_NORMAL, 'count': 1})
        self.assertEqual(self.view.substr(self.R(0, self.view.size())), 'foo 101\nfoo 101\nfoo 301\n')

    def testDecreasePrefixedDigitsUnderSelection(self):
        set_text(self.view, ''.join(('foo -10\nfoo -10\nfoo -10\n',)))
        add_sel(self.view, self.R((0, 4), (0, 4)))
        add_sel(self.view, self.R((1, 4), (1, 4)))
        add_sel(self.view, self.R((2, 4), (2, 4)))

        self.view.run_command('_vi_ctrl_a', {'mode': _MODE_INTERNAL_NORMAL, 'count': 11})
        self.assertEqual(self.view.substr(self.R(0, self.view.size())), 'foo 1\nfoo 1\nfoo 1\n')

    def testDecreaseSuffixeddDigitsUnderSelection(self):
        set_text(self.view, ''.join(('foo -10px\nfoo -10px\nfoo -10px\n',)))
        add_sel(self.view, self.R((0, 4), (0, 4)))
        add_sel(self.view, self.R((1, 4), (1, 4)))
        add_sel(self.view, self.R((2, 4), (2, 4)))

        self.view.run_command('_vi_ctrl_a', {'mode': _MODE_INTERNAL_NORMAL, 'count': 11})
        self.assertEqual(self.view.substr(self.R(0, self.view.size())), 'foo 1px\nfoo 1px\nfoo 1px\n')

    def testDecreaseDigitsAfterSelection(self):
        set_text(self.view, ''.join(('foo 100\nfoo 200\nfoo 300\n',)))
        add_sel(self.view, self.R((0, 0), (0, 0)))
        add_sel(self.view, self.R((1, 0), (1, 0)))
        add_sel(self.view, self.R((2, 0), (2, 0)))

        self.view.run_command('_vi_ctrl_a', {'mode': _MODE_INTERNAL_NORMAL, 'count': 1})
        self.assertEqual(self.view.substr(self.R(0, self.view.size())), 'foo 101\nfoo 201\nfoo 301\n')

    def testDecreaseDigitsAfterSelectionByCount(self):
        set_text(self.view, ''.join(('foo 100\nfoo 200\nfoo 300\n',)))
        add_sel(self.view, self.R((0, 4), (0, 4)))
        add_sel(self.view, self.R((1, 4), (1, 4)))
        add_sel(self.view, self.R((2, 4), (2, 4)))

        self.view.run_command('_vi_ctrl_a', {'mode': _MODE_INTERNAL_NORMAL, 'count': 10})
        self.assertEqual(self.view.substr(self.R(0, self.view.size())), 'foo 110\nfoo 210\nfoo 310\n')

    def testAbortIfOnlySomeSelectionsHaveDigits(self):
        set_text(self.view, ''.join(('foo 100\nfoo bar\nfoo 300\n',)))
        add_sel(self.view, self.R((0, 4), (0, 4)))
        add_sel(self.view, self.R((1, 4), (1, 4)))
        add_sel(self.view, self.R((2, 4), (2, 4)))

        self.view.run_command('_vi_ctrl_a', {'mode': _MODE_INTERNAL_NORMAL, 'count': 1})
        self.assertEqual(self.view.substr(self.R(0, self.view.size())), 'foo 100\nfoo bar\nfoo 300\n')

    def testAbortIfOnlySomeSelectionsHaveDigitsAfterThem(self):
        set_text(self.view, ''.join(('foo 100\nfoo bar\nfoo 300\n',)))
        add_sel(self.view, self.R((0, 0), (0, 0)))
        add_sel(self.view, self.R((1, 0), (1, 0)))
        add_sel(self.view, self.R((2, 0), (2, 0)))

        self.view.run_command('_vi_ctrl_a', {'mode': _MODE_INTERNAL_NORMAL, 'count': 1})
        self.assertEqual(self.view.substr(self.R(0, self.view.size())), 'foo 100\nfoo bar\nfoo 300\n')
{'fraction_non_alphanumeric': 0.19718309859154928, 'fraction_numerical': 0.05075279261777562, 'mean_word_length': 3.4894622093023258, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6949291', 'n_tokens_mistral': 5324, 'n_tokens_neox': 4864, 'n_words': 876}