Bram Moolenaar | ae3150e | 2016-06-11 23:22:36 +0200 | [diff] [blame] | 1 | " Tests for editing the command line. |
| 2 | |
| 3 | func Test_complete_tab() |
| 4 | call writefile(['testfile'], 'Xtestfile') |
| 5 | call feedkeys(":e Xtest\t\r", "tx") |
| 6 | call assert_equal('testfile', getline(1)) |
| 7 | call delete('Xtestfile') |
| 8 | endfunc |
| 9 | |
| 10 | func Test_complete_list() |
| 11 | " We can't see the output, but at least we check the code runs properly. |
| 12 | call feedkeys(":e test\<C-D>\r", "tx") |
| 13 | call assert_equal('test', expand('%:t')) |
| 14 | endfunc |
| 15 | |
| 16 | func Test_complete_wildmenu() |
| 17 | call writefile(['testfile1'], 'Xtestfile1') |
| 18 | call writefile(['testfile2'], 'Xtestfile2') |
| 19 | set wildmenu |
| 20 | call feedkeys(":e Xtest\t\t\r", "tx") |
| 21 | call assert_equal('testfile2', getline(1)) |
| 22 | |
| 23 | call delete('Xtestfile1') |
| 24 | call delete('Xtestfile2') |
| 25 | set nowildmenu |
| 26 | endfunc |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 27 | |
| 28 | func Test_getcompletion() |
Bram Moolenaar | 0d3e24b | 2016-07-09 19:20:59 +0200 | [diff] [blame] | 29 | if !has('cmdline_compl') |
| 30 | return |
| 31 | endif |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 32 | let groupcount = len(getcompletion('', 'event')) |
| 33 | call assert_true(groupcount > 0) |
| 34 | let matchcount = len(getcompletion('File', 'event')) |
| 35 | call assert_true(matchcount > 0) |
| 36 | call assert_true(groupcount > matchcount) |
| 37 | |
Bram Moolenaar | 0d3e24b | 2016-07-09 19:20:59 +0200 | [diff] [blame] | 38 | if has('menu') |
| 39 | source $VIMRUNTIME/menu.vim |
| 40 | let matchcount = len(getcompletion('', 'menu')) |
| 41 | call assert_true(matchcount > 0) |
| 42 | call assert_equal(['File.'], getcompletion('File', 'menu')) |
| 43 | call assert_true(matchcount > 0) |
| 44 | let matchcount = len(getcompletion('File.', 'menu')) |
| 45 | call assert_true(matchcount > 0) |
| 46 | endif |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 47 | |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 48 | let l = getcompletion('v:n', 'var') |
| 49 | call assert_true(index(l, 'v:null') >= 0) |
| 50 | |
| 51 | let l = getcompletion('', 'augroup') |
| 52 | call assert_true(index(l, 'END') >= 0) |
| 53 | |
| 54 | let l = getcompletion('', 'behave') |
| 55 | call assert_true(index(l, 'mswin') >= 0) |
| 56 | |
| 57 | let l = getcompletion('', 'color') |
| 58 | call assert_true(index(l, 'default') >= 0) |
| 59 | |
| 60 | let l = getcompletion('', 'command') |
| 61 | call assert_true(index(l, 'sleep') >= 0) |
| 62 | |
| 63 | let l = getcompletion('', 'dir') |
| 64 | call assert_true(index(l, 'samples') >= 0) |
| 65 | |
| 66 | let l = getcompletion('exe', 'expression') |
| 67 | call assert_true(index(l, 'executable(') >= 0) |
| 68 | |
| 69 | let l = getcompletion('tag', 'function') |
| 70 | call assert_true(index(l, 'taglist(') >= 0) |
| 71 | |
Bram Moolenaar | b49edc1 | 2016-07-23 15:47:34 +0200 | [diff] [blame] | 72 | let Flambda = {-> 'hello'} |
| 73 | let l = getcompletion('', 'function') |
| 74 | let l = filter(l, {i, v -> v =~ 'lambda'}) |
| 75 | call assert_equal(0, len(l)) |
| 76 | |
Bram Moolenaar | c1fb763 | 2016-07-17 23:34:21 +0200 | [diff] [blame] | 77 | let l = getcompletion('run', 'file') |
| 78 | call assert_true(index(l, 'runtest.vim') >= 0) |
| 79 | |
| 80 | let l = getcompletion('ha', 'filetype') |
| 81 | call assert_true(index(l, 'hamster') >= 0) |
| 82 | |
| 83 | let l = getcompletion('z', 'syntax') |
| 84 | call assert_true(index(l, 'zimbu') >= 0) |
| 85 | |
| 86 | let l = getcompletion('jikes', 'compiler') |
| 87 | call assert_true(index(l, 'jikes') >= 0) |
| 88 | |
| 89 | let l = getcompletion('last', 'help') |
| 90 | call assert_true(index(l, ':tablast') >= 0) |
| 91 | |
| 92 | let l = getcompletion('time', 'option') |
| 93 | call assert_true(index(l, 'timeoutlen') >= 0) |
| 94 | |
| 95 | let l = getcompletion('er', 'highlight') |
| 96 | call assert_true(index(l, 'ErrorMsg') >= 0) |
| 97 | |
| 98 | " For others test if the name is recognized. |
| 99 | let names = ['buffer', 'environment', 'file_in_path', |
| 100 | \ 'mapping', 'shellcmd', 'tag', 'tag_listfiles', 'user'] |
| 101 | if has('cscope') |
| 102 | call add(names, 'cscope') |
| 103 | endif |
| 104 | if has('cmdline_hist') |
| 105 | call add(names, 'history') |
| 106 | endif |
| 107 | if has('gettext') |
| 108 | call add(names, 'locale') |
| 109 | endif |
| 110 | if has('profile') |
| 111 | call add(names, 'syntime') |
| 112 | endif |
| 113 | if has('signs') |
| 114 | call add(names, 'sign') |
| 115 | endif |
| 116 | |
| 117 | set tags=Xtags |
| 118 | call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags') |
| 119 | |
| 120 | for name in names |
| 121 | let matchcount = len(getcompletion('', name)) |
| 122 | call assert_true(matchcount >= 0, 'No matches for ' . name) |
| 123 | endfor |
| 124 | |
| 125 | call delete('Xtags') |
| 126 | |
Bram Moolenaar | aa4d732 | 2016-07-09 18:50:29 +0200 | [diff] [blame] | 127 | call assert_fails('call getcompletion("", "burp")', 'E475:') |
| 128 | endfunc |