comparison src/testdir/test_cmdline.vim @ 19536:bab20768e1fd v8.2.0325

patch 8.2.0325: ex_getln.c code not covered by tests Commit: https://github.com/vim/vim/commit/578fe947e3ad0cc7313c798cf76cc43dbf9b4ea6 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Feb 27 21:32:51 2020 +0100 patch 8.2.0325: ex_getln.c code not covered by tests Problem: Ex_getln.c code not covered by tests. Solution: Add a few more tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/5702)
author Bram Moolenaar <Bram@vim.org>
date Thu, 27 Feb 2020 21:45:04 +0100
parents 738a4fe2c8c5
children b3ef3538b389
comparison
equal deleted inserted replaced
19535:b8ce0a9d1657 19536:bab20768e1fd
12 12
13 func Test_complete_list() 13 func Test_complete_list()
14 " We can't see the output, but at least we check the code runs properly. 14 " We can't see the output, but at least we check the code runs properly.
15 call feedkeys(":e test\<C-D>\r", "tx") 15 call feedkeys(":e test\<C-D>\r", "tx")
16 call assert_equal('test', expand('%:t')) 16 call assert_equal('test', expand('%:t'))
17
18 " If a command doesn't support completion, then CTRL-D should be literally
19 " used.
20 call feedkeys(":chistory \<C-D>\<C-B>\"\<CR>", 'xt')
21 call assert_equal("\"chistory \<C-D>", @:)
17 endfunc 22 endfunc
18 23
19 func Test_complete_wildmenu() 24 func Test_complete_wildmenu()
20 call mkdir('Xdir1/Xdir2', 'p') 25 call mkdir('Xdir1/Xdir2', 'p')
21 call writefile(['testfile1'], 'Xdir1/Xtestfile1') 26 call writefile(['testfile1'], 'Xdir1/Xtestfile1')
48 " <Up>/<Down> to go up/down directories. 53 " <Up>/<Down> to go up/down directories.
49 call feedkeys(":e Xdir1/\<Tab>\<Down>\<CR>", 'tx') 54 call feedkeys(":e Xdir1/\<Tab>\<Down>\<CR>", 'tx')
50 call assert_equal('testfile3', getline(1)) 55 call assert_equal('testfile3', getline(1))
51 call feedkeys(":e Xdir1/\<Tab>\<Down>\<Up>\<Right>\<CR>", 'tx') 56 call feedkeys(":e Xdir1/\<Tab>\<Down>\<Up>\<Right>\<CR>", 'tx')
52 call assert_equal('testfile1', getline(1)) 57 call assert_equal('testfile1', getline(1))
58
59 " Test for canceling the wild menu by adding a character
60 redrawstatus
61 call feedkeys(":e Xdir1/\<Tab>x\<C-B>\"\<CR>", 'xt')
62 call assert_equal('"e Xdir1/Xdir2/x', @:)
53 63
54 " Completion using a relative path 64 " Completion using a relative path
55 cd Xdir1/Xdir2 65 cd Xdir1/Xdir2
56 call feedkeys(":e ../\<Tab>\<Right>\<Down>\<C-A>\<C-B>\"\<CR>", 'tx') 66 call feedkeys(":e ../\<Tab>\<Right>\<Down>\<C-A>\<C-B>\"\<CR>", 'tx')
57 call assert_equal('"e Xtestfile3 Xtestfile4', @:) 67 call assert_equal('"e Xtestfile3 Xtestfile4', @:)
464 call assert_equal("Xtestfile", bufname("%")) 474 call assert_equal("Xtestfile", bufname("%"))
465 475
466 " Use an invalid expression for <C-\>e 476 " Use an invalid expression for <C-\>e
467 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")') 477 call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
468 478
479 " Try to paste an invalid register using <C-R>
480 call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
481 call assert_equal('"onetwo', @:)
482
483 let @a = "xy\<C-H>z"
484 call feedkeys(":\"\<C-R>a\<CR>", 'xt')
485 call assert_equal('"xz', @:)
486 call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
487 call assert_equal("\"xy\<C-H>z", @:)
488
489 call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
490
469 bwipe! 491 bwipe!
470 endfunc 492 endfunc
471 493
472 func Test_cmdline_remove_char() 494 func Test_cmdline_remove_char()
473 let encoding_save = &encoding 495 let encoding_save = &encoding
1051 let $HOME = save_HOME 1073 let $HOME = save_HOME
1052 cd .. 1074 cd ..
1053 call delete('Xdir', 'rf') 1075 call delete('Xdir', 'rf')
1054 endfunc 1076 endfunc
1055 1077
1078 " Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
1079 " or insert mode (when 'insertmode' is set)
1080 func Test_cmdline_ctrl_g()
1081 new
1082 call setline(1, 'abc')
1083 call cursor(1, 3)
1084 " If command line is entered from insert mode, using C-\ C-G should back to
1085 " insert mode
1086 call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
1087 call assert_equal('abxyc', getline(1))
1088 call assert_equal(4, col('.'))
1089
1090 " If command line is entered in 'insertmode', using C-\ C-G should back to
1091 " 'insertmode'
1092 call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
1093 call assert_equal('ab12xyc', getline(1))
1094 close!
1095 endfunc
1096
1097 " Return the 'len' characters in screen starting from (row,col)
1098 func s:ScreenLine(row, col, len)
1099 let s = ''
1100 for i in range(a:len)
1101 let s .= nr2char(screenchar(a:row, a:col + i))
1102 endfor
1103 return s
1104 endfunc
1105
1106 " Test for 'wildmode'
1107 func Test_wildmode()
1108 func T(a, c, p)
1109 return "oneA\noneB\noneC"
1110 endfunc
1111 command -nargs=1 -complete=custom,T MyCmd
1112
1113 func SaveScreenLine()
1114 let g:Sline = s:ScreenLine(&lines - 1, 1, 20)
1115 return ''
1116 endfunc
1117 cnoremap <expr> <F2> SaveScreenLine()
1118
1119 set nowildmenu
1120 set wildmode=full,list
1121 let g:Sline = ''
1122 call feedkeys(":MyCmd \t\t\<F2>\<C-B>\"\<CR>", 'xt')
1123 call assert_equal('oneA oneB oneC ', g:Sline)
1124 call assert_equal('"MyCmd oneA', @:)
1125
1126 set wildmode=longest,full
1127 call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
1128 call assert_equal('"MyCmd one', @:)
1129 call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
1130 call assert_equal('"MyCmd oneC', @:)
1131
1132 set wildmode=longest
1133 call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
1134 call assert_equal('"MyCmd one', @:)
1135
1136 set wildmode=list:longest
1137 let g:Sline = ''
1138 call feedkeys(":MyCmd \t\<F2>\<C-B>\"\<CR>", 'xt')
1139 call assert_equal('oneA oneB oneC ', g:Sline)
1140 call assert_equal('"MyCmd one', @:)
1141
1142 set wildmode=""
1143 call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
1144 call assert_equal('"MyCmd oneA', @:)
1145
1146 delcommand MyCmd
1147 delfunc T
1148 delfunc SaveScreenLine
1149 cunmap <F2>
1150 set wildmode&
1151 endfunc
1152
1153 " Test for interrupting the command-line completion
1154 func Test_interrupt_compl()
1155 func F(lead, cmdl, p)
1156 if a:lead =~ 'tw'
1157 call interrupt()
1158 return
1159 endif
1160 return "one\ntwo\nthree"
1161 endfunc
1162 command -nargs=1 -complete=custom,F Tcmd
1163
1164 set nowildmenu
1165 set wildmode=full
1166 let interrupted = 0
1167 try
1168 call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
1169 catch /^Vim:Interrupt$/
1170 let interrupted = 1
1171 endtry
1172 call assert_equal(1, interrupted)
1173
1174 delcommand Tcmd
1175 delfunc F
1176 set wildmode&
1177 endfunc
1178
1179 func Test_cmdline_edit()
1180 call feedkeys(":\"buffer\<Right>\<Home>\<Left>\<CR>", 'xt')
1181 call assert_equal("\"buffer", @:)
1182 endfunc
1183
1056 " vim: shiftwidth=2 sts=2 expandtab 1184 " vim: shiftwidth=2 sts=2 expandtab