From 5d1cb73e7f17c29fc9e68ba293f63d8f8e71c264 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 22 Sep 2022 12:07:16 +0800 Subject: vim-patch:8.2.0712: various code not fully tested Problem: Various code not fully tested. Solution: Add a few more tests. (Yegappan Lakshmanan, closes vim/vim#6049) https://github.com/vim/vim/commit/0ff5dedf0f69e56320199db7a2aad46be2a1f9b7 Nvim does not support encoding=latin1 or setting keycodes/termcaps. --- src/nvim/testdir/test_functions.vim | 16 ++++++++++++++++ src/nvim/testdir/test_options.vim | 9 +++++++++ src/nvim/testdir/test_system.vim | 38 +++++++++++++++++++++++++++++++++++++ src/nvim/testdir/test_termcodes.vim | 26 +++++++++++++++++++++++++ 4 files changed, 89 insertions(+) (limited to 'src') diff --git a/src/nvim/testdir/test_functions.vim b/src/nvim/testdir/test_functions.vim index 8555e8c866..7262d2d71a 100644 --- a/src/nvim/testdir/test_functions.vim +++ b/src/nvim/testdir/test_functions.vim @@ -462,6 +462,12 @@ func Test_tolower() " invalid memory. call tolower("\xC0\x80\xC0") call tolower("123\xC0\x80\xC0") + + " Test in latin1 encoding + let save_enc = &encoding + " set encoding=latin1 + call assert_equal("abc", tolower("ABC")) + let &encoding = save_enc endfunc func Test_toupper() @@ -533,6 +539,12 @@ func Test_toupper() " invalid memory. call toupper("\xC0\x80\xC0") call toupper("123\xC0\x80\xC0") + + " Test in latin1 encoding + let save_enc = &encoding + " set encoding=latin1 + call assert_equal("ABC", toupper("abc")) + let &encoding = save_enc endfunc func Test_tr() @@ -1096,6 +1108,10 @@ func Test_filewritable() call assert_equal(0, filewritable('doesnotexist')) + call mkdir('Xdir') + call assert_equal(2, filewritable('Xdir')) + call delete('Xdir', 'd') + call delete('Xfilewritable') bw! endfunc diff --git a/src/nvim/testdir/test_options.vim b/src/nvim/testdir/test_options.vim index f11f3055f0..ec02f1f9da 100644 --- a/src/nvim/testdir/test_options.vim +++ b/src/nvim/testdir/test_options.vim @@ -282,6 +282,15 @@ func Test_set_completion() call feedkeys(":set fileencodings:\\\"\", 'tx') call assert_equal('"set fileencodings:ucs-bom,utf-8,default,latin1', @:) + " Expand key codes. + " call feedkeys(":set \\"\", 'tx') + " call assert_equal('"set ', @:) + + " Expand terminal options. + " call feedkeys(":set t_A\\\"\", 'tx') + " call assert_equal('"set t_AB t_AF t_AU t_AL', @:) + " call assert_fails('call feedkeys(":set =\\", "xt")', 'E474:') + " Expand directories. call feedkeys(":set cdpath=./\\\"\", 'tx') call assert_match('./samples/ ', @:) diff --git a/src/nvim/testdir/test_system.vim b/src/nvim/testdir/test_system.vim index 18692f42c9..bfa8a277bd 100644 --- a/src/nvim/testdir/test_system.vim +++ b/src/nvim/testdir/test_system.vim @@ -141,3 +141,41 @@ func Test_system_with_shell_quote() call delete('Xdir with spaces', 'rf') endtry endfunc + +" Test for 'shellxquote' +func Test_Shellxquote() + CheckUnix + + let save_shell = &shell + let save_sxq = &shellxquote + let save_sxe = &shellxescape + + call writefile(['#!/bin/sh', 'echo "Cmd: [$*]" > Xlog'], 'Xtestshell') + call setfperm('Xtestshell', "r-x------") + set shell=./Xtestshell + + set shellxquote=\\" + call feedkeys(":!pwd\\", 'xt') + call assert_equal(['Cmd: [-c "pwd"]'], readfile('Xlog')) + + set shellxquote=( + call feedkeys(":!pwd\\", 'xt') + call assert_equal(['Cmd: [-c (pwd)]'], readfile('Xlog')) + + set shellxquote=\\"( + call feedkeys(":!pwd\\", 'xt') + call assert_equal(['Cmd: [-c "(pwd)"]'], readfile('Xlog')) + + set shellxescape=\"&<<()@^ + set shellxquote=( + call feedkeys(":!pwd\"&<<{}@^\\", 'xt') + call assert_equal(['Cmd: [-c (pwd^"^&^<^<{}^@^^)]'], readfile('Xlog')) + + let &shell = save_shell + let &shellxquote = save_sxq + let &shellxescape = save_sxe + call delete('Xtestshell') + call delete('Xlog') +endfunc + +" vim: shiftwidth=2 sts=2 expandtab diff --git a/src/nvim/testdir/test_termcodes.vim b/src/nvim/testdir/test_termcodes.vim index eda485c512..99bc2d1d37 100644 --- a/src/nvim/testdir/test_termcodes.vim +++ b/src/nvim/testdir/test_termcodes.vim @@ -1,4 +1,30 @@ +" Test for translation of special key codes (, , etc.) +func Test_Keycode_Translation() + let keycodes = [ + \ ["", ""], + \ ["", ""], + \ ["", ""], + \ ["", ""], + \ ["", ""], + \ ["", ""], + \ ["", ""], + \ ["", ""], + \ ["", ""], + \ ["", ""], + \ ["", ""], + \ ["", ""], + \ ["", ""], + \ ["", ""], + \ ["", ""], + \ ["", ""]] + for [k1, k2] in keycodes + exe "nnoremap " .. k1 .. " 2wx" + call assert_true(maparg(k1, 'n', 0, 1).lhs == k2) + exe "nunmap " .. k1 + endfor +endfunc + " Test for terminal keycodes that doesn't have termcap entries func Test_special_term_keycodes() new -- cgit