1" Test for options 2 3function! Test_whichwrap() 4 set whichwrap=b,s 5 call assert_equal('b,s', &whichwrap) 6 7 set whichwrap+=h,l 8 call assert_equal('b,s,h,l', &whichwrap) 9 10 set whichwrap+=h,l 11 call assert_equal('b,s,h,l', &whichwrap) 12 13 set whichwrap+=h,l 14 call assert_equal('b,s,h,l', &whichwrap) 15 16 set whichwrap=h,h 17 call assert_equal('h', &whichwrap) 18 19 set whichwrap=h,h,h 20 call assert_equal('h', &whichwrap) 21 22 set whichwrap& 23endfunction 24 25function Test_options() 26 let caught = 'ok' 27 try 28 options 29 catch 30 let caught = v:throwpoint . "\n" . v:exception 31 endtry 32 call assert_equal('ok', caught) 33 34 " close option-window 35 close 36endfunction 37 38function Test_path_keep_commas() 39 " Test that changing 'path' keeps two commas. 40 set path=foo,,bar 41 set path-=bar 42 set path+=bar 43 call assert_equal('foo,,bar', &path) 44 45 set path& 46endfunction 47 48func Test_signcolumn() 49 if has('signs') 50 call assert_equal("auto", &signcolumn) 51 set signcolumn=yes 52 set signcolumn=no 53 call assert_fails('set signcolumn=nope') 54 endif 55endfunc 56 57func Test_filetype_valid() 58 if !has('autocmd') 59 return 60 endif 61 set ft=valid_name 62 call assert_equal("valid_name", &filetype) 63 set ft=valid-name 64 call assert_equal("valid-name", &filetype) 65 66 call assert_fails(":set ft=wrong;name", "E474:") 67 call assert_fails(":set ft=wrong\\\\name", "E474:") 68 call assert_fails(":set ft=wrong\\|name", "E474:") 69 call assert_fails(":set ft=wrong/name", "E474:") 70 call assert_fails(":set ft=wrong\\\nname", "E474:") 71 call assert_equal("valid-name", &filetype) 72 73 exe "set ft=trunc\x00name" 74 call assert_equal("trunc", &filetype) 75endfunc 76 77func Test_syntax_valid() 78 if !has('syntax') 79 return 80 endif 81 set syn=valid_name 82 call assert_equal("valid_name", &syntax) 83 set syn=valid-name 84 call assert_equal("valid-name", &syntax) 85 86 call assert_fails(":set syn=wrong;name", "E474:") 87 call assert_fails(":set syn=wrong\\\\name", "E474:") 88 call assert_fails(":set syn=wrong\\|name", "E474:") 89 call assert_fails(":set syn=wrong/name", "E474:") 90 call assert_fails(":set syn=wrong\\\nname", "E474:") 91 call assert_equal("valid-name", &syntax) 92 93 exe "set syn=trunc\x00name" 94 call assert_equal("trunc", &syntax) 95endfunc 96 97func Test_keymap_valid() 98 if !has('keymap') 99 return 100 endif 101 call assert_fails(":set kmp=valid_name", "E544:") 102 call assert_fails(":set kmp=valid_name", "valid_name") 103 call assert_fails(":set kmp=valid-name", "E544:") 104 call assert_fails(":set kmp=valid-name", "valid-name") 105 106 call assert_fails(":set kmp=wrong;name", "E474:") 107 call assert_fails(":set kmp=wrong\\\\name", "E474:") 108 call assert_fails(":set kmp=wrong\\|name", "E474:") 109 call assert_fails(":set kmp=wrong/name", "E474:") 110 call assert_fails(":set kmp=wrong\\\nname", "E474:") 111 112 call assert_fails(":set kmp=trunc\x00name", "E544:") 113 call assert_fails(":set kmp=trunc\x00name", "trunc") 114endfunc 115 116func Check_dir_option(name) 117 " Check that it's possible to set the option. 118 exe 'set ' . a:name . '=/usr/share/dict/words' 119 call assert_equal('/usr/share/dict/words', eval('&' . a:name)) 120 exe 'set ' . a:name . '=/usr/share/dict/words,/and/there' 121 call assert_equal('/usr/share/dict/words,/and/there', eval('&' . a:name)) 122 exe 'set ' . a:name . '=/usr/share/dict\ words' 123 call assert_equal('/usr/share/dict words', eval('&' . a:name)) 124 125 " Check rejecting weird characters. 126 call assert_fails("set " . a:name . "=/not&there", "E474:") 127 call assert_fails("set " . a:name . "=/not>there", "E474:") 128 call assert_fails("set " . a:name . "=/not.*there", "E474:") 129endfunc 130 131func Test_dictionary() 132 call Check_dir_option('dictionary') 133endfunc 134 135func Test_thesaurus() 136 call Check_dir_option('thesaurus') 137endfun 138 139func Test_set_completion() 140 call feedkeys(":set di\<C-A>\<C-B>\"\<CR>", 'tx') 141 call assert_equal('"set dictionary diff diffexpr diffopt digraph directory display', @:) 142 143 " Expand boolan options. When doing :set no<Tab> 144 " vim displays the options names without "no" but completion uses "no...". 145 call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx') 146 call assert_equal('"set nodiff digraph', @:) 147 148 call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx') 149 call assert_equal('"set invdiff digraph', @:) 150 151 " Expand abbreviation of options. 152 call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx') 153 call assert_equal('"set tabstop thesaurus ttyscroll', @:) 154 155 " Expand current value 156 call feedkeys(":set fileencodings=\<C-A>\<C-B>\"\<CR>", 'tx') 157 call assert_equal('"set fileencodings=ucs-bom,utf-8,default,latin1', @:) 158 159 call feedkeys(":set fileencodings:\<C-A>\<C-B>\"\<CR>", 'tx') 160 call assert_equal('"set fileencodings:ucs-bom,utf-8,default,latin1', @:) 161 162 " Expand key codes. 163 call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx') 164 call assert_equal('"set <Help> <Home>', @:) 165 166 " Expand terminal options. 167 call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx') 168 call assert_equal('"set t_AB t_AF t_AL', @:) 169 170 " Expand directories. 171 call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx') 172 call assert_match(' ./samples/ ', @:) 173 call assert_notmatch(' ./small.vim ', @:) 174 175 " Expand files and directories. 176 call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx') 177 call assert_match(' ./samples/.* ./small.vim', @:) 178 179 call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx') 180 call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:) 181endfunc 182 183func Test_set_errors() 184 call assert_fails('set scroll=-1', 'E49:') 185 call assert_fails('set backupcopy=', 'E474:') 186 call assert_fails('set regexpengine=3', 'E474:') 187 call assert_fails('set history=10001', 'E474:') 188 call assert_fails('set numberwidth=11', 'E474:') 189 call assert_fails('set colorcolumn=-a') 190 call assert_fails('set colorcolumn=a') 191 call assert_fails('set colorcolumn=1,') 192 call assert_fails('set cmdheight=-1', 'E487:') 193 call assert_fails('set cmdwinheight=-1', 'E487:') 194 if has('conceal') 195 call assert_fails('set conceallevel=-1', 'E487:') 196 call assert_fails('set conceallevel=4', 'E474:') 197 endif 198 call assert_fails('set helpheight=-1', 'E487:') 199 call assert_fails('set history=-1', 'E487:') 200 call assert_fails('set report=-1', 'E487:') 201 call assert_fails('set shiftwidth=-1', 'E487:') 202 call assert_fails('set sidescroll=-1', 'E487:') 203 call assert_fails('set tabstop=-1', 'E487:') 204 call assert_fails('set textwidth=-1', 'E487:') 205 call assert_fails('set timeoutlen=-1', 'E487:') 206 call assert_fails('set updatecount=-1', 'E487:') 207 call assert_fails('set updatetime=-1', 'E487:') 208 call assert_fails('set winheight=-1', 'E487:') 209 call assert_fails('set tabstop!', 'E488:') 210 call assert_fails('set xxx', 'E518:') 211 call assert_fails('set beautify?', 'E519:') 212 call assert_fails('set undolevels=x', 'E521:') 213 call assert_fails('set tabstop=', 'E521:') 214 call assert_fails('set comments=-', 'E524:') 215 call assert_fails('set comments=a', 'E525:') 216 call assert_fails('set foldmarker=x', 'E536:') 217 call assert_fails('set commentstring=x', 'E537:') 218 call assert_fails('set complete=x', 'E539:') 219 call assert_fails('set statusline=%{', 'E540:') 220 call assert_fails('set statusline=' . repeat("%p", 81), 'E541:') 221 call assert_fails('set statusline=%(', 'E542:') 222 call assert_fails('set guicursor=x', 'E545:') 223 call assert_fails('set backupext=~ patchmode=~', 'E589:') 224 call assert_fails('set winminheight=10 winheight=9', 'E591:') 225 call assert_fails('set winminwidth=10 winwidth=9', 'E592:') 226 call assert_fails("set showbreak=\x01", 'E595:') 227 call assert_fails('set t_foo=', 'E846:') 228endfunc 229