comparison src/testdir/test_terminal.vim @ 18143:2416e1a887ca

patch 8.1.2066: no tests for state() Commit: https://github.com/vim/vim/commit/c2585490321854ca3df115efcf0b40986901d96c Author: Bram Moolenaar <Bram@vim.org> Date: Sun Sep 22 21:29:53 2019 +0200 patch 8.1.2066: no tests for state() Problem: No tests for state(). Solution: Add tests. Clean up some feature checks. Make "a" flag work.
author Bram Moolenaar <Bram@vim.org>
date Sun, 22 Sep 2019 21:30:04 +0200
parents 5a5e9eed6029
children 4ac8161e92e0
comparison
equal deleted inserted replaced
18142:6243a1690929 18143:2416e1a887ca
1031 endfunc 1031 endfunc
1032 1032
1033 " Run Vim in a terminal, then start a terminal in that Vim without a kill 1033 " Run Vim in a terminal, then start a terminal in that Vim without a kill
1034 " argument, check that :confirm qall works. 1034 " argument, check that :confirm qall works.
1035 func Test_terminal_qall_prompt() 1035 func Test_terminal_qall_prompt()
1036 if !CanRunVimInTerminal() 1036 CheckRunVimInTerminal
1037 throw 'Skipped: cannot run Vim in a terminal window'
1038 endif
1039 let buf = RunVimInTerminal('', {}) 1037 let buf = RunVimInTerminal('', {})
1040 1038
1041 " Open a terminal window and wait for the prompt to appear 1039 " Open a terminal window and wait for the prompt to appear
1042 call term_sendkeys(buf, ":term\<CR>") 1040 call term_sendkeys(buf, ":term\<CR>")
1043 call WaitForAssert({-> assert_match('\[running]', term_getline(buf, 10))}) 1041 call WaitForAssert({-> assert_match('\[running]', term_getline(buf, 10))})
1092 call assert_equal('~ Select Word', trim(getline(a:off + 7))) 1090 call assert_equal('~ Select Word', trim(getline(a:off + 7)))
1093 call assert_equal(':popup PopUp', trim(getline(a:off + 20))) 1091 call assert_equal(':popup PopUp', trim(getline(a:off + 20)))
1094 endfunc 1092 endfunc
1095 1093
1096 func Test_terminal_dumpwrite_composing() 1094 func Test_terminal_dumpwrite_composing()
1097 if !CanRunVimInTerminal() 1095 CheckRunVimInTerminal
1098 throw 'Skipped: cannot run Vim in a terminal window'
1099 endif
1100 let save_enc = &encoding 1096 let save_enc = &encoding
1101 set encoding=utf-8 1097 set encoding=utf-8
1102 call assert_equal(1, winnr('$')) 1098 call assert_equal(1, winnr('$'))
1103 1099
1104 let text = " a\u0300 e\u0302 o\u0308" 1100 let text = " a\u0300 e\u0302 o\u0308"
1217 call assert_true(winnr('$') >= 3) 1213 call assert_true(winnr('$') >= 3)
1218 return buf 1214 return buf
1219 endfunc 1215 endfunc
1220 1216
1221 func Test_terminal_api_drop_newwin() 1217 func Test_terminal_api_drop_newwin()
1222 if !CanRunVimInTerminal() 1218 CheckRunVimInTerminal
1223 throw 'Skipped: cannot run Vim in a terminal window'
1224 endif
1225 let buf = Api_drop_common('') 1219 let buf = Api_drop_common('')
1226 call assert_equal(0, &bin) 1220 call assert_equal(0, &bin)
1227 call assert_equal('', &fenc) 1221 call assert_equal('', &fenc)
1228 1222
1229 call StopVimInTerminal(buf) 1223 call StopVimInTerminal(buf)
1230 call delete('Xscript') 1224 call delete('Xscript')
1231 bwipe Xtextfile 1225 bwipe Xtextfile
1232 endfunc 1226 endfunc
1233 1227
1234 func Test_terminal_api_drop_newwin_bin() 1228 func Test_terminal_api_drop_newwin_bin()
1235 if !CanRunVimInTerminal() 1229 CheckRunVimInTerminal
1236 throw 'Skipped: cannot run Vim in a terminal window'
1237 endif
1238 let buf = Api_drop_common(',{"bin":1}') 1230 let buf = Api_drop_common(',{"bin":1}')
1239 call assert_equal(1, &bin) 1231 call assert_equal(1, &bin)
1240 1232
1241 call StopVimInTerminal(buf) 1233 call StopVimInTerminal(buf)
1242 call delete('Xscript') 1234 call delete('Xscript')
1243 bwipe Xtextfile 1235 bwipe Xtextfile
1244 endfunc 1236 endfunc
1245 1237
1246 func Test_terminal_api_drop_newwin_binary() 1238 func Test_terminal_api_drop_newwin_binary()
1247 if !CanRunVimInTerminal() 1239 CheckRunVimInTerminal
1248 throw 'Skipped: cannot run Vim in a terminal window'
1249 endif
1250 let buf = Api_drop_common(',{"binary":1}') 1240 let buf = Api_drop_common(',{"binary":1}')
1251 call assert_equal(1, &bin) 1241 call assert_equal(1, &bin)
1252 1242
1253 call StopVimInTerminal(buf) 1243 call StopVimInTerminal(buf)
1254 call delete('Xscript') 1244 call delete('Xscript')
1255 bwipe Xtextfile 1245 bwipe Xtextfile
1256 endfunc 1246 endfunc
1257 1247
1258 func Test_terminal_api_drop_newwin_nobin() 1248 func Test_terminal_api_drop_newwin_nobin()
1259 if !CanRunVimInTerminal() 1249 CheckRunVimInTerminal
1260 throw 'Skipped: cannot run Vim in a terminal window'
1261 endif
1262 set binary 1250 set binary
1263 let buf = Api_drop_common(',{"nobin":1}') 1251 let buf = Api_drop_common(',{"nobin":1}')
1264 call assert_equal(0, &bin) 1252 call assert_equal(0, &bin)
1265 1253
1266 call StopVimInTerminal(buf) 1254 call StopVimInTerminal(buf)
1268 bwipe Xtextfile 1256 bwipe Xtextfile
1269 set nobinary 1257 set nobinary
1270 endfunc 1258 endfunc
1271 1259
1272 func Test_terminal_api_drop_newwin_nobinary() 1260 func Test_terminal_api_drop_newwin_nobinary()
1273 if !CanRunVimInTerminal() 1261 CheckRunVimInTerminal
1274 throw 'Skipped: cannot run Vim in a terminal window'
1275 endif
1276 set binary 1262 set binary
1277 let buf = Api_drop_common(',{"nobinary":1}') 1263 let buf = Api_drop_common(',{"nobinary":1}')
1278 call assert_equal(0, &bin) 1264 call assert_equal(0, &bin)
1279 1265
1280 call StopVimInTerminal(buf) 1266 call StopVimInTerminal(buf)
1282 bwipe Xtextfile 1268 bwipe Xtextfile
1283 set nobinary 1269 set nobinary
1284 endfunc 1270 endfunc
1285 1271
1286 func Test_terminal_api_drop_newwin_ff() 1272 func Test_terminal_api_drop_newwin_ff()
1287 if !CanRunVimInTerminal() 1273 CheckRunVimInTerminal
1288 throw 'Skipped: cannot run Vim in a terminal window'
1289 endif
1290 let buf = Api_drop_common(',{"ff":"dos"}') 1274 let buf = Api_drop_common(',{"ff":"dos"}')
1291 call assert_equal("dos", &ff) 1275 call assert_equal("dos", &ff)
1292 1276
1293 call StopVimInTerminal(buf) 1277 call StopVimInTerminal(buf)
1294 call delete('Xscript') 1278 call delete('Xscript')
1295 bwipe Xtextfile 1279 bwipe Xtextfile
1296 endfunc 1280 endfunc
1297 1281
1298 func Test_terminal_api_drop_newwin_fileformat() 1282 func Test_terminal_api_drop_newwin_fileformat()
1299 if !CanRunVimInTerminal() 1283 CheckRunVimInTerminal
1300 throw 'Skipped: cannot run Vim in a terminal window'
1301 endif
1302 let buf = Api_drop_common(',{"fileformat":"dos"}') 1284 let buf = Api_drop_common(',{"fileformat":"dos"}')
1303 call assert_equal("dos", &ff) 1285 call assert_equal("dos", &ff)
1304 1286
1305 call StopVimInTerminal(buf) 1287 call StopVimInTerminal(buf)
1306 call delete('Xscript') 1288 call delete('Xscript')
1307 bwipe Xtextfile 1289 bwipe Xtextfile
1308 endfunc 1290 endfunc
1309 1291
1310 func Test_terminal_api_drop_newwin_enc() 1292 func Test_terminal_api_drop_newwin_enc()
1311 if !CanRunVimInTerminal() 1293 CheckRunVimInTerminal
1312 throw 'Skipped: cannot run Vim in a terminal window'
1313 endif
1314 let buf = Api_drop_common(',{"enc":"utf-16"}') 1294 let buf = Api_drop_common(',{"enc":"utf-16"}')
1315 call assert_equal("utf-16", &fenc) 1295 call assert_equal("utf-16", &fenc)
1316 1296
1317 call StopVimInTerminal(buf) 1297 call StopVimInTerminal(buf)
1318 call delete('Xscript') 1298 call delete('Xscript')
1319 bwipe Xtextfile 1299 bwipe Xtextfile
1320 endfunc 1300 endfunc
1321 1301
1322 func Test_terminal_api_drop_newwin_encoding() 1302 func Test_terminal_api_drop_newwin_encoding()
1323 if !CanRunVimInTerminal() 1303 CheckRunVimInTerminal
1324 throw 'Skipped: cannot run Vim in a terminal window'
1325 endif
1326 let buf = Api_drop_common(',{"encoding":"utf-16"}') 1304 let buf = Api_drop_common(',{"encoding":"utf-16"}')
1327 call assert_equal("utf-16", &fenc) 1305 call assert_equal("utf-16", &fenc)
1328 1306
1329 call StopVimInTerminal(buf) 1307 call StopVimInTerminal(buf)
1330 call delete('Xscript') 1308 call delete('Xscript')
1331 bwipe Xtextfile 1309 bwipe Xtextfile
1332 endfunc 1310 endfunc
1333 1311
1334 func Test_terminal_api_drop_oldwin() 1312 func Test_terminal_api_drop_oldwin()
1335 if !CanRunVimInTerminal() 1313 CheckRunVimInTerminal
1336 throw 'Skipped: cannot run Vim in a terminal window'
1337 endif
1338 let firstwinid = win_getid() 1314 let firstwinid = win_getid()
1339 split Xtextfile 1315 split Xtextfile
1340 let textfile_winid = win_getid() 1316 let textfile_winid = win_getid()
1341 call assert_equal(2, winnr('$')) 1317 call assert_equal(2, winnr('$'))
1342 call win_gotoid(firstwinid) 1318 call win_gotoid(firstwinid)
1373 \ "set t_ts=", 1349 \ "set t_ts=",
1374 \ ], 'Xscript') 1350 \ ], 'Xscript')
1375 endfunc 1351 endfunc
1376 1352
1377 func Test_terminal_api_call() 1353 func Test_terminal_api_call()
1378 if !CanRunVimInTerminal() 1354 CheckRunVimInTerminal
1379 throw 'Skipped: cannot run Vim in a terminal window'
1380 endif
1381 1355
1382 call WriteApiCall('Tapi_TryThis') 1356 call WriteApiCall('Tapi_TryThis')
1383 let buf = RunVimInTerminal('-S Xscript', {}) 1357 let buf = RunVimInTerminal('-S Xscript', {})
1384 call WaitFor({-> exists('g:called_bufnum')}) 1358 call WaitFor({-> exists('g:called_bufnum')})
1385 call assert_equal(buf, g:called_bufnum) 1359 call assert_equal(buf, g:called_bufnum)
1390 unlet g:called_bufnum 1364 unlet g:called_bufnum
1391 unlet g:called_arg 1365 unlet g:called_arg
1392 endfunc 1366 endfunc
1393 1367
1394 func Test_terminal_api_call_fails() 1368 func Test_terminal_api_call_fails()
1395 if !CanRunVimInTerminal() 1369 CheckRunVimInTerminal
1396 throw 'Skipped: cannot run Vim in a terminal window'
1397 endif
1398 1370
1399 call WriteApiCall('TryThis') 1371 call WriteApiCall('TryThis')
1400 call ch_logfile('Xlog', 'w') 1372 call ch_logfile('Xlog', 'w')
1401 let buf = RunVimInTerminal('-S Xscript', {}) 1373 let buf = RunVimInTerminal('-S Xscript', {})
1402 call WaitForAssert({-> assert_match('Invalid function name: TryThis', string(readfile('Xlog')))}) 1374 call WaitForAssert({-> assert_match('Invalid function name: TryThis', string(readfile('Xlog')))})
1416 let s:caught_e937 = 1 1388 let s:caught_e937 = 1
1417 endtry 1389 endtry
1418 endfunc 1390 endfunc
1419 1391
1420 func Test_terminal_api_call_fail_delete() 1392 func Test_terminal_api_call_fail_delete()
1421 if !CanRunVimInTerminal() 1393 CheckRunVimInTerminal
1422 throw 'Skipped: cannot run Vim in a terminal window'
1423 endif
1424 1394
1425 call WriteApiCall('Tapi_Delete') 1395 call WriteApiCall('Tapi_Delete')
1426 let buf = RunVimInTerminal('-S Xscript', {}) 1396 let buf = RunVimInTerminal('-S Xscript', {})
1427 call WaitForAssert({-> assert_equal(1, s:caught_e937)}) 1397 call WaitForAssert({-> assert_equal(1, s:caught_e937)})
1428 1398
1511 call term_wait(buf) 1481 call term_wait(buf)
1512 exe buf . 'bwipe' 1482 exe buf . 'bwipe'
1513 endfunc 1483 endfunc
1514 1484
1515 func Test_terminal_all_ansi_colors() 1485 func Test_terminal_all_ansi_colors()
1516 if !CanRunVimInTerminal() 1486 CheckRunVimInTerminal
1517 throw 'Skipped: cannot run Vim in a terminal window'
1518 endif
1519 1487
1520 " Use all the ANSI colors. 1488 " Use all the ANSI colors.
1521 call writefile([ 1489 call writefile([
1522 \ 'call setline(1, "AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPP XXYYZZ")', 1490 \ 'call setline(1, "AABBCCDDEEFFGGHHIIJJKKLLMMNNOOPP XXYYZZ")',
1523 \ 'hi Tblack ctermfg=0 ctermbg=8', 1491 \ 'hi Tblack ctermfg=0 ctermbg=8',
1568 call StopVimInTerminal(buf) 1536 call StopVimInTerminal(buf)
1569 call delete('Xcolorscript') 1537 call delete('Xcolorscript')
1570 endfunc 1538 endfunc
1571 1539
1572 func Test_terminal_termwinsize_option_fixed() 1540 func Test_terminal_termwinsize_option_fixed()
1573 if !CanRunVimInTerminal() 1541 CheckRunVimInTerminal
1574 throw 'Skipped: cannot run Vim in a terminal window'
1575 endif
1576 set termwinsize=6x40 1542 set termwinsize=6x40
1577 let text = [] 1543 let text = []
1578 for n in range(10) 1544 for n in range(10)
1579 call add(text, repeat(n, 50)) 1545 call add(text, repeat(n, 50))
1580 endfor 1546 endfor
2032 au! BufLeave 1998 au! BufLeave
2033 set statusline= 1999 set statusline=
2034 endfunc 2000 endfunc
2035 2001
2036 func Test_terminal_getwinpos() 2002 func Test_terminal_getwinpos()
2037 if !CanRunVimInTerminal() 2003 CheckRunVimInTerminal
2038 throw 'Skipped: cannot run Vim in a terminal window'
2039 endif
2040 2004
2041 " split, go to the bottom-right window 2005 " split, go to the bottom-right window
2042 split 2006 split
2043 wincmd j 2007 wincmd j
2044 set splitright 2008 set splitright