Skip to content

Commit 99236bf

Browse files
authored
test: replace_termcodes, UTF-8 chdir #619
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
1 parent 6f92a33 commit 99236bf

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

test/test_vim.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,32 @@ def test_api(vim: Nvim) -> None:
7777
assert vim.api.eval('g:var') == 3
7878

7979

80+
# issue #52
81+
def test_replace_termcodes(vim: Nvim) -> None:
82+
# Simple key sequences should round-trip through feedkeys.
83+
esc = vim.replace_termcodes('<esc>')
84+
assert isinstance(esc, str)
85+
cr = vim.replace_termcodes('<cr>')
86+
assert isinstance(cr, str)
87+
assert cr == '\r'
88+
# Special keys produce Nvim's internal representation (may contain
89+
# non-UTF-8 bytes). With surrogateescape these become surrogate chars.
90+
up = vim.replace_termcodes('<up>')
91+
assert isinstance(up, str)
92+
# feedkeys should accept the result without error.
93+
vim.feedkeys(vim.replace_termcodes('<esc>'))
94+
# Non-ASCII input (issue #52): replace_termcodes on literal unicode text
95+
# should not raise, even though decode is enabled (surrogateescape).
96+
result = vim.replace_termcodes('¬✓↓⏎')
97+
assert isinstance(result, str)
98+
assert result == '¬✓↓⏎'
99+
# Unicode chars whose UTF-8 contains 0x80 (e.g. ‽ = \xe2\x80\xbd) get
100+
# mangled by Nvim's internal key encoding. This is a known Nvim behavior.
101+
result_mangled = vim.replace_termcodes('‽')
102+
assert isinstance(result_mangled, str)
103+
assert result_mangled != '‽' # confirms the mangling
104+
105+
80106
def test_strwidth(vim: Nvim) -> None:
81107
assert vim.strwidth('abc') == 3
82108
# 6 + (neovim)
@@ -257,6 +283,16 @@ def test_python_cwd(vim: Nvim, tmp_path: Path) -> None:
257283
assert cwd_python != cwd_before
258284

259285

286+
# issue #442
287+
def test_python_cwd_utf8(vim: Nvim, tmp_path: Path) -> None:
288+
utf8_dir = tmp_path / '日本語テスト'
289+
utf8_dir.mkdir()
290+
vim.command('python3 import os')
291+
vim.command('cd {}'.format(str(utf8_dir)))
292+
cwd_python = vim.command_output('python3 print(os.getcwd())')
293+
assert cwd_python == str(utf8_dir)
294+
295+
260296
lua_code = """
261297
local a = vim.api
262298
local y = ...

0 commit comments

Comments
 (0)