<commit_before># -*- coding: utf-8 -*-
import os
import sys
import tempfile


def source(vim, code):
    fd, fname = tempfile.mkstemp()
    with os.fdopen(fd, 'w') as f:
        f.write(code)
    vim.command('source ' + fname)
    os.unlink(fname)


def test_command(vim):
    fname = tempfile.mkstemp()[1]
    vim.command('new')
    vim.command('edit {}'.format(fname))
    # skip the "press return" state, which does not handle deferred calls
    vim.input('\r')
    vim.command('normal itesting\npython\napi')
    vim.command('w')
    assert os.path.isfile(fname)
    with open(fname) as f:
        assert f.read() == 'testing\npython\napi\n'
    os.unlink(fname)


def test_command_output(vim):
    assert vim.command_output('echo "test"') == 'test'


def test_eval(vim):
    vim.command('let g:v1 = "a"')
    vim.command('let g:v2 = [1, 2, {"v3": 3}]')
    assert vim.eval('g:'), {'v1': 'a', 'v2': [1, 2 == {'v3': 3}]}


def test_call(vim):
    assert vim.funcs.join(['first', 'last'], ', '), 'first == last'
    source(vim, """
        function! Testfun(a,b)
            return string(a:a).":".a:b
        endfunction
    """)
    assert vim.funcs.Testfun(3, 'alpha') == '3:alpha'


def test_api(vim):
    vim.api.command('let g:var = 3')
    assert vim.api.eval('g:var') == 3


def test_strwidth(vim):
    assert vim.strwidth('abc') == 3
    # 6 + (neovim)
    # 19 * 2 (each japanese character occupies two cells)
    assert vim.strwidth('neovimのデザインかなりまともなのになってる。') == 44


def test_chdir(vim):
    pwd = vim.eval('getcwd()')
    root = os.path.abspath(os.sep)
    # We can chdir to '/' on Windows, but then the pwd will be the root drive
    vim.chdir('/')
    assert vim.eval('getcwd()') == root
    vim.chdir(pwd)
    assert vim.eval('getcwd()') == pwd


def test_current_line(vim):
    assert vim.current.line == ''
    vim.current.line = 'abc'
    assert vim.current.line == 'abc'


def test_vars(vim):
    vim.vars['python'] = [1, 2, {'3': 1}]
    assert vim.vars['python'], [1, 2 == {'3': 1}]
    assert vim.eval('g:python'), [1, 2 == {'3': 1}]


def test_options(vim):
    assert vim.options['listchars'] == 'tab:> ,trail:-,nbsp:+'
    vim.options['listchars'] = 'tab:xy'
    assert vim.options['listchars'] == 'tab:xy'


def test_buffers(vim):<commit_msg>test: del vim.current.line<commit_after># -*- coding: utf-8 -*-
import os
import sys
import tempfile


def source(vim, code):
    fd, fname = tempfile.mkstemp()
    with os.fdopen(fd, 'w') as f:
        f.write(code)
    vim.command('source ' + fname)
    os.unlink(fname)


def test_command(vim):
    fname = tempfile.mkstemp()[1]
    vim.command('new')
    vim.command('edit {}'.format(fname))
    # skip the "press return" state, which does not handle deferred calls
    vim.input('\r')
    vim.command('normal itesting\npython\napi')
    vim.command('w')
    assert os.path.isfile(fname)
    with open(fname) as f:
        assert f.read() == 'testing\npython\napi\n'
    os.unlink(fname)


def test_command_output(vim):
    assert vim.command_output('echo "test"') == 'test'


def test_eval(vim):
    vim.command('let g:v1 = "a"')
    vim.command('let g:v2 = [1, 2, {"v3": 3}]')
    assert vim.eval('g:'), {'v1': 'a', 'v2': [1, 2 == {'v3': 3}]}


def test_call(vim):
    assert vim.funcs.join(['first', 'last'], ', '), 'first == last'
    source(vim, """
        function! Testfun(a,b)
            return string(a:a).":".a:b
        endfunction
    """)
    assert vim.funcs.Testfun(3, 'alpha') == '3:alpha'


def test_api(vim):
    vim.api.command('let g:var = 3')
    assert vim.api.eval('g:var') == 3


def test_strwidth(vim):
    assert vim.strwidth('abc') == 3
    # 6 + (neovim)
    # 19 * 2 (each japanese character occupies two cells)
    assert vim.strwidth('neovimのデザインかなりまともなのになってる。') == 44


def test_chdir(vim):
    pwd = vim.eval('getcwd()')
    root = os.path.abspath(os.sep)
    # We can chdir to '/' on Windows, but then the pwd will be the root drive
    vim.chdir('/')
    assert vim.eval('getcwd()') == root
    vim.chdir(pwd)
    assert vim.eval('getcwd()') == pwd


def test_current_line(vim):
    assert vim.current.line == ''
    vim.current.line = 'abc'
    assert vim.current.line == 'abc'


def test_current_line_delete(vim):
    vim.current.buffer[:] = ['one', 'two']
    assert len(vim.current.buffer[:]) == 2
    del vim.current.line
    assert len(vim.current.buffer[:]) == 1 and vim.current.buffer[0] == 'two'
    del vim.current.line
    assert len(vim.current.buffer[:]) == 1 and not vim.current.buffer[0]


def test_vars(vim):
    vim.vars['python'] = [1, 2, {'3': 1}]
    assert vim.vars['python'], [1, 2 == {'3': 1}]
    assert vim.eval('g:python'), [1, 2 == {'3': 1}]


def test_options(vim):
    assert vim.options['listchars'] == 'tab:> ,trail:-,nbsp:+'
    vim.options['listchars'] = 'tab:xy'
    assert vim.options['listchars'] == 'tab:xy'


def test_buffers(vim):
{'fraction_non_alphanumeric': 0.1933237763669875, 'fraction_numerical': 0.016178578742576284, 'mean_word_length': 3.1815068493150687, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 5, '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': '1600025', 'n_tokens_mistral': 2010, 'n_tokens_neox': 1878, 'n_words': 415}