From cade17cbf944584db8c4b751897fe0b6bb751fc4 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Fri, 10 Apr 2026 17:22:14 +0200 Subject: [PATCH] test: replace_termcodes, UTF-8 chdir Problem: No test coverage for replace_termcodes (including non-ASCII input #52) or chdir with UTF-8 paths (#442). Solution: - Add test_replace_termcodes covering basic key sequences, non-ASCII passthrough, and the known 0x80-mangling behavior. - Add test_python_cwd_utf8 confirming that :cd with multi-byte paths propagates correctly to the Python host. Close #52 Close #442 --- test/test_vim.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/test_vim.py b/test/test_vim.py index 26e2fcea..2f69fa99 100644 --- a/test/test_vim.py +++ b/test/test_vim.py @@ -77,6 +77,32 @@ def test_api(vim: Nvim) -> None: assert vim.api.eval('g:var') == 3 +# issue #52 +def test_replace_termcodes(vim: Nvim) -> None: + # Simple key sequences should round-trip through feedkeys. + esc = vim.replace_termcodes('') + assert isinstance(esc, str) + cr = vim.replace_termcodes('') + assert isinstance(cr, str) + assert cr == '\r' + # Special keys produce Nvim's internal representation (may contain + # non-UTF-8 bytes). With surrogateescape these become surrogate chars. + up = vim.replace_termcodes('') + assert isinstance(up, str) + # feedkeys should accept the result without error. + vim.feedkeys(vim.replace_termcodes('')) + # Non-ASCII input (issue #52): replace_termcodes on literal unicode text + # should not raise, even though decode is enabled (surrogateescape). + result = vim.replace_termcodes('¬✓↓⏎') + assert isinstance(result, str) + assert result == '¬✓↓⏎' + # Unicode chars whose UTF-8 contains 0x80 (e.g. ‽ = \xe2\x80\xbd) get + # mangled by Nvim's internal key encoding. This is a known Nvim behavior. + result_mangled = vim.replace_termcodes('‽') + assert isinstance(result_mangled, str) + assert result_mangled != '‽' # confirms the mangling + + def test_strwidth(vim: Nvim) -> None: assert vim.strwidth('abc') == 3 # 6 + (neovim) @@ -257,6 +283,16 @@ def test_python_cwd(vim: Nvim, tmp_path: Path) -> None: assert cwd_python != cwd_before +# issue #442 +def test_python_cwd_utf8(vim: Nvim, tmp_path: Path) -> None: + utf8_dir = tmp_path / '日本語テスト' + utf8_dir.mkdir() + vim.command('python3 import os') + vim.command('cd {}'.format(str(utf8_dir))) + cwd_python = vim.command_output('python3 print(os.getcwd())') + assert cwd_python == str(utf8_dir) + + lua_code = """ local a = vim.api local y = ...