Exemplo n.º 1
0
 def setUp(self):
     Shell.run('rm -rf {}'.format(test_dir))
     self.prepare_test_dir(test_local_dir)
     nvim.command('silent tabe {}'.format(test_local_dir))
     self.ensure_buf_no_expand()
     # Clear all previous selection
     nvim.input('u')
Exemplo n.º 2
0
 def doit(name, offset):
     Shell.touch(name)
     exact_width = nvim.strwidth(name) + file_sz_display_wid + 1
     assert exact_width + offset > 0, "Not reasonable to test width <= 0"
     nvim.command(f'vertical resize {exact_width+offset}')
     nvim.input('rG')
     self.assertEqual(nvim.current.window.width,
                      nvim.strwidth(self.clineinfo.visible_text),
                      self.clineinfo.visible_text)
Exemplo n.º 3
0
    def test_size_display(self):
        Shell.run('echo {} > {}'.format('a' * 1035, 'a'))
        Shell.run('echo {} > {}'.format('b' * 1024, 'b'))

        nvim.command('edit .')
        nvim.input('Gk')

        self.assertEqual('1.01 K', self.clineinfo.size_str)

        nvim.input('j')
        self.assertEqual('1 K', self.clineinfo.size_str)
Exemplo n.º 4
0
def test_bookmark():
    Shell.run('rm -f {}'.format(nvim.vars['NETRBookmarkFile']))

    nvim.input('mal')
    nvim.input("'a")
    assert_content('dir')

    nvim.input('lemjrb')
    nvim.command('exit')
    time.sleep(0.5)
    nvim.input("'b")
    assert_content('dir')
Exemplo n.º 5
0
    def setUp(self):

        Shell.run('rm -rf {}'.format(test_dir))
        self.prepare_test_dir(test_local_dir)
        self.prepare_test_dir(test_remote_dir)
        Shell.run('rm -rf {}/*'.format(test_remote_cache_dir))
        nvim.command('NETRemoteList')
        # There is only one remote configure by netrtest_rclone.conf
        nvim.input('l')
        nvim.command('NETRemotePull')
        nvim.command('call cursor(2, 1)')
        self.ensure_buf_no_expand()
        # Clear all previous selection
        nvim.input('u')
Exemplo n.º 6
0
def test_sort():
    # only test extension, mtime, size
    # extension: [a, a.a, a.b]
    # size: [a.b, a.a, a]
    # mtime: [a, a.b, a.a]
    Shell.run('echo {} > dir/{}'.format('a' * 3, 'a'))
    Shell.run('echo {} > dir/{}'.format('a' * 2, 'a.a'))
    Shell.run('echo {} > dir/{}'.format('a' * 1, 'a.b'))
    time.sleep(0.01)
    Shell.run('touch dir/a.a')

    nvim.input('zaSe')
    assert_content('dir', ind=0, hi='dir', level=0)
    assert_content('a', ind=3, hi='file', level=1)
    assert_content('a.a', ind=4, hi='file', level=1)
    assert_content('a.b', ind=5, hi='file', level=1)
    assert_content('dir2', ind=6, hi='dir', level=0)

    nvim.input('SE')
    assert_content('dir2', ind=0, hi='dir', level=0)
    assert_content('dir', ind=1, hi='dir', level=0)
    assert_content('a.b', ind=2, hi='file', level=1)
    assert_content('a.a', ind=3, hi='file', level=1)
    assert_content('a', ind=4, hi='file', level=1)

    nvim.input('Ss')
    assert_content('dir2', ind=0, hi='dir', level=0)
    assert_content('dir', ind=1, hi='dir', level=0)
    assert_content('a.b', ind=4, hi='file', level=1)
    assert_content('a.a', ind=5, hi='file', level=1)
    assert_content('a', ind=6, hi='file', level=1)

    nvim.input('SS')
    assert_content('dir', ind=0, hi='dir', level=0)
    assert_content('a', ind=1, hi='file', level=1)
    assert_content('a.a', ind=2, hi='file', level=1)
    assert_content('a.b', ind=3, hi='file', level=1)
    assert_content('dir2', ind=6, hi='dir', level=0)

    nvim.input('Sm')
    assert_content('dir2', ind=0, hi='dir', level=0)
    assert_content('dir', ind=1, hi='dir', level=0)
    assert_content('a', ind=4, hi='file', level=1)
    assert_content('a.b', ind=5, hi='file', level=1)
    assert_content('a.a', ind=6, hi='file', level=1)

    nvim.input('SM')
    assert_content('dir', ind=0, hi='dir', level=0)
    assert_content('a.a', ind=1, hi='file', level=1)
    assert_content('a.b', ind=2, hi='file', level=1)
    assert_content('a', ind=3, hi='file', level=1)
    assert_content('dir2', ind=6, hi='dir', level=0)
    nvim.input('Sd')
Exemplo n.º 7
0
    def assert_fs(self, d, expect, root=test_local_dir):
        """
        Test whether 'expect' exists in directory root/d.
        """
        real = None
        for i in range(10):
            real = Shell.run(
                f'ls --group-directories-first {root}/{d}').split()
            if real == expect:
                return
            time.sleep(0.05)

        self.assertEqual(expect, real)
Exemplo n.º 8
0
def test_size_wide_char_display():
    # This vsplit is a rather ad-hoc work around in case of the screen is too
    # wide such that the following echo command failed because of too long
    # file name
    nvim.command('vsplit')

    width = nvim.current.window.width

    Shell.run('echo {} > {}'.format('a' * 1035, '測' * width + '.pdf'))
    Shell.run('echo {} > {}'.format('b' * 1024, '試' * width))

    nvim.command('edit .')
    nvim.input('Gk')
    assert cLine_ends_with(
        '~.pdf 1.01 K'), 'size display abbreviation fail: a~.pdf {}'.format(
            nvim.current.line[-10:])
    nvim.input('j')
    assert cLine_ends_with(
        '試~    1 K'), 'size display abbreviation fail: b~ {}'.format(
            nvim.current.line[-10:])

    # close the vsplit
    nvim.command('quit')
Exemplo n.º 9
0
def test_on_bufenter_fs_change():
    nvim.input('lh')
    Shell.touch('dir/b')
    Shell.mkdir('dir3')
    nvim.command('split new')
    nvim.command('quit')
    nvim.input('zA')
    assert_content('dir', ind=0, hi='dir', hi_fg=True)
    assert_content('b', ind=7, level=1, hi='file')
    assert_content('dir3', ind=9, hi='dir')
    assert_num_content_line(10)

    Shell.rm('dir/subdir2/placeholder')
    nvim.input('lh')
    assert_num_content_line(9)
Exemplo n.º 10
0
def assert_fs(d, expected, root=None):
    """
    Test whether 'expected' exists in directory cwd/d, where
    cwd is /tmp/netrtest/local when testing local functions and
    cwd is /tmp/netrtest/remote when testing remote functions.
    """

    if root:
        old_cwd = os.getcwd()
        os.chdir(root)

    real = None
    for i in range(10):
        real = Shell.run('ls --group-directories-first ' + d).split()
        if real == expected:
            return
        time.sleep(0.05)

    assert real == expected, 'expected: {}, real: {}'.format(expected, real)

    if root:
        os.chdir(old_cwd)
Exemplo n.º 11
0
def test_NETRForceDeleteSingle():
    Shell.run('chmod u-w dir/a')
    nvim.input('zajjjXX')
    wait_for_fs_free()
    assert_content('dir2', ind=3, hi='dir', hi_fg=True)
Exemplo n.º 12
0
    def prepare_test_dir(dirname):
        Shell.mkdir(dirname)
        os.chdir(dirname)
        Shell.mkdir('dir/subdir')
        Shell.mkdir('dir/subdir/subsubdir')
        Shell.mkdir('dir/subdir2')
        Shell.touch('dir/a')
        Shell.touch('.a')
        Shell.mkdir('dir2/')

        # The following should be removed when rclone fix "not copying empty
        # directories" bug.
        Shell.touch('dir/subdir/subsubdir/placeholder')
        Shell.touch('dir/subdir2/placeholder')
        Shell.touch('dir/subdir2/placeholder')
Exemplo n.º 13
0
def do_test(fn=None, fn_remote=None):
    """
    Note on the mecahnism of testing rclone on localhost:
    1. Tester run rclone to create a "local" remote named netrtest (must be
       exact this name)
    2. In default.py, the vim variable 'NETRemoteRoots' is set to
       {test_remote_name: test_remote_dir}, which defaults to
       {'netrtest', '/tmp/netrtest/remote'}.
    3. 'NETRemoteRoots' is passed to Rclone constructor, so that the rpath
       of the netrtest remote is mapped to '/tmp/netrtest/remote'.
    4. This just works in netranger. In cmd line, running
       'rclone lsl netrtest:/' still shows you the content of the root
       directory of the localhost.
    """
    old_cwd = os.getcwd()
    Shell.run('rm -rf {}'.format(test_dir))

    def prepare_test_dir(dirname):
        Shell.mkdir(dirname)
        os.chdir(dirname)
        Shell.mkdir('dir/subdir')
        Shell.mkdir('dir/subdir/subsubdir')
        Shell.mkdir('dir/subdir2')
        Shell.touch('dir/a')
        Shell.touch('.a')
        Shell.mkdir('dir2/')

        # The following should be removed when rclone fix "not copying empty
        # directories" bug.
        Shell.touch('dir/subdir/subsubdir/placeholder')
        Shell.touch('dir/subdir2/placeholder')
        Shell.touch('dir/subdir2/placeholder')

    prepare_test_dir(test_local_dir)
    if fn is not None:
        nvim.command('silent tabe {}'.format(test_local_dir))
        ensure_buf_no_expand()
        fn()
        print('== {} success =='.format(str(fn.__name__)))

    prepare_test_dir(test_remote_dir)
    Shell.run('rm -rf {}/*'.format(test_remote_cache_dir))
    if fn_remote is not None:
        nvim.command('NETRemoteList')
        found_remote = False
        for i, line in enumerate(nvim.current.buffer):
            if re.findall('.+(netrtest)', line):
                nvim.command('call cursor({}, 1)'.format(i + 1))
                found_remote = True
                break

        assert found_remote, 'You must set up an rclone remote named "{}" \
            to test remote function'.format(test_remote_name)
        nvim.input('l')
        nvim.command('NETRemotePull')
        nvim.command('call cursor(2, 1)')
        ensure_buf_no_expand()
        fn_remote()
        print('== {} success =='.format(str(fn_remote.__name__)))

    while nvim.eval('&ft') == 'netranger':
        nvim.command('bwipeout')
    os.chdir(old_cwd)
Exemplo n.º 14
0
 def test_on_bufenter_fs_change_with_expanded_nodes(self):
     nvim.input('za')
     nvim.command('split new')
     Shell.touch('dir/b')
     nvim.command('quit')
     self.assert_num_content_line(6)
Exemplo n.º 15
0
 def test_NETRForceDeleteSingle(self):
     Shell.run('chmod u-w dir/a')
     nvim.input('zajjjXX')
     self.wait_for_fs_free()
     self.assert_content('dir2', ind=3, hi='dir')