test_options.vim 89 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816
  1. " Test for options
  2. source shared.vim
  3. source check.vim
  4. source view_util.vim
  5. scriptencoding utf-8
  6. func Test_whichwrap()
  7. set whichwrap=b,s
  8. call assert_equal('b,s', &whichwrap)
  9. set whichwrap+=h,l
  10. call assert_equal('b,s,h,l', &whichwrap)
  11. set whichwrap+=h,l
  12. call assert_equal('b,s,h,l', &whichwrap)
  13. set whichwrap+=h,l
  14. call assert_equal('b,s,h,l', &whichwrap)
  15. set whichwrap=h,h
  16. call assert_equal('h', &whichwrap)
  17. set whichwrap=h,h,h
  18. call assert_equal('h', &whichwrap)
  19. " " For compatibility with Vim 3.0 and before, number values are also
  20. " " supported for 'whichwrap'
  21. " set whichwrap=1
  22. " call assert_equal('b', &whichwrap)
  23. " set whichwrap=2
  24. " call assert_equal('s', &whichwrap)
  25. " set whichwrap=4
  26. " call assert_equal('h,l', &whichwrap)
  27. " set whichwrap=8
  28. " call assert_equal('<,>', &whichwrap)
  29. " set whichwrap=16
  30. " call assert_equal('[,]', &whichwrap)
  31. " set whichwrap=31
  32. " call assert_equal('b,s,h,l,<,>,[,]', &whichwrap)
  33. set whichwrap&
  34. endfunc
  35. func Test_isfname()
  36. " This used to cause Vim to access uninitialized memory.
  37. set isfname=
  38. call assert_equal("~X", expand("~X"))
  39. set isfname&
  40. " Test for setting 'isfname' to an unsupported character
  41. let save_isfname = &isfname
  42. call assert_fails('exe $"set isfname+={"\u1234"}"', 'E474:')
  43. call assert_equal(save_isfname, &isfname)
  44. endfunc
  45. " Test for getting the value of 'pastetoggle'
  46. func Test_pastetoggle()
  47. throw "Skipped: 'pastetoggle' is removed from Nvim"
  48. " character with K_SPECIAL byte
  49. let &pastetoggle = '…'
  50. call assert_equal('…', &pastetoggle)
  51. call assert_equal("\n pastetoggle=…", execute('set pastetoggle?'))
  52. " modified character with K_SPECIAL byte
  53. let &pastetoggle = '<M-…>'
  54. call assert_equal('<M-…>', &pastetoggle)
  55. call assert_equal("\n pastetoggle=<M-…>", execute('set pastetoggle?'))
  56. " illegal bytes
  57. let str = ":\x7f:\x80:\x90:\xd0:"
  58. let &pastetoggle = str
  59. call assert_equal(str, &pastetoggle)
  60. call assert_equal("\n pastetoggle=" .. strtrans(str), execute('set pastetoggle?'))
  61. unlet str
  62. set pastetoggle&
  63. endfunc
  64. func Test_wildchar()
  65. " Empty 'wildchar' used to access invalid memory.
  66. call assert_fails('set wildchar=', 'E521:')
  67. call assert_fails('set wildchar=abc', 'E521:')
  68. set wildchar=<Esc>
  69. let a=execute('set wildchar?')
  70. call assert_equal("\n wildchar=<Esc>", a)
  71. set wildchar=27
  72. let a=execute('set wildchar?')
  73. call assert_equal("\n wildchar=<Esc>", a)
  74. set wildchar&
  75. endfunc
  76. func Test_wildoptions()
  77. set wildoptions=
  78. set wildoptions+=tagfile
  79. set wildoptions+=tagfile
  80. call assert_equal('tagfile', &wildoptions)
  81. endfunc
  82. func Test_options_command()
  83. let caught = 'ok'
  84. try
  85. options
  86. catch
  87. let caught = v:throwpoint . "\n" . v:exception
  88. endtry
  89. call assert_equal('ok', caught)
  90. " Check if the option-window is opened horizontally.
  91. wincmd j
  92. call assert_notequal('option-window', bufname(''))
  93. wincmd k
  94. call assert_equal('option-window', bufname(''))
  95. " close option-window
  96. close
  97. " Open the option-window vertically.
  98. vert options
  99. " Check if the option-window is opened vertically.
  100. wincmd l
  101. call assert_notequal('option-window', bufname(''))
  102. wincmd h
  103. call assert_equal('option-window', bufname(''))
  104. " close option-window
  105. close
  106. " Open the option-window at the top.
  107. set splitbelow
  108. topleft options
  109. call assert_equal(1, winnr())
  110. close
  111. " Open the option-window at the bottom.
  112. set nosplitbelow
  113. botright options
  114. call assert_equal(winnr('$'), winnr())
  115. close
  116. set splitbelow&
  117. " Open the option-window in a new tab.
  118. tab options
  119. " Check if the option-window is opened in a tab.
  120. normal gT
  121. call assert_notequal('option-window', bufname(''))
  122. normal gt
  123. call assert_equal('option-window', bufname(''))
  124. " close option-window
  125. close
  126. " Open the options window browse
  127. if has('browse')
  128. browse set
  129. call assert_equal('option-window', bufname(''))
  130. close
  131. endif
  132. endfunc
  133. func Test_path_keep_commas()
  134. " Test that changing 'path' keeps two commas.
  135. set path=foo,,bar
  136. set path-=bar
  137. set path+=bar
  138. call assert_equal('foo,,bar', &path)
  139. set path&
  140. endfunc
  141. func Test_path_too_long()
  142. exe 'set path=' .. repeat('x', 10000)
  143. call assert_fails('find x', 'E854:')
  144. set path&
  145. endfunc
  146. func Test_signcolumn()
  147. CheckFeature signs
  148. call assert_equal("auto", &signcolumn)
  149. set signcolumn=yes
  150. set signcolumn=no
  151. call assert_fails('set signcolumn=nope')
  152. endfunc
  153. func Test_filetype_valid()
  154. set ft=valid_name
  155. call assert_equal("valid_name", &filetype)
  156. set ft=valid-name
  157. call assert_equal("valid-name", &filetype)
  158. call assert_fails(":set ft=wrong;name", "E474:")
  159. call assert_fails(":set ft=wrong\\\\name", "E474:")
  160. call assert_fails(":set ft=wrong\\|name", "E474:")
  161. call assert_fails(":set ft=wrong/name", "E474:")
  162. call assert_fails(":set ft=wrong\\\nname", "E474:")
  163. call assert_equal("valid-name", &filetype)
  164. exe "set ft=trunc\x00name"
  165. call assert_equal("trunc", &filetype)
  166. endfunc
  167. func Test_syntax_valid()
  168. if !has('syntax')
  169. return
  170. endif
  171. set syn=valid_name
  172. call assert_equal("valid_name", &syntax)
  173. set syn=valid-name
  174. call assert_equal("valid-name", &syntax)
  175. call assert_fails(":set syn=wrong;name", "E474:")
  176. call assert_fails(":set syn=wrong\\\\name", "E474:")
  177. call assert_fails(":set syn=wrong\\|name", "E474:")
  178. call assert_fails(":set syn=wrong/name", "E474:")
  179. call assert_fails(":set syn=wrong\\\nname", "E474:")
  180. call assert_equal("valid-name", &syntax)
  181. exe "set syn=trunc\x00name"
  182. call assert_equal("trunc", &syntax)
  183. endfunc
  184. func Test_keymap_valid()
  185. if !has('keymap')
  186. return
  187. endif
  188. call assert_fails(":set kmp=valid_name", "E544:")
  189. call assert_fails(":set kmp=valid_name", "valid_name")
  190. call assert_fails(":set kmp=valid-name", "E544:")
  191. call assert_fails(":set kmp=valid-name", "valid-name")
  192. call assert_fails(":set kmp=wrong;name", "E474:")
  193. call assert_fails(":set kmp=wrong\\\\name", "E474:")
  194. call assert_fails(":set kmp=wrong\\|name", "E474:")
  195. call assert_fails(":set kmp=wrong/name", "E474:")
  196. call assert_fails(":set kmp=wrong\\\nname", "E474:")
  197. call assert_fails(":set kmp=trunc\x00name", "E544:")
  198. call assert_fails(":set kmp=trunc\x00name", "trunc")
  199. endfunc
  200. func Test_wildchar_valid()
  201. call assert_fails("set wildchar=<CR>", "E474:")
  202. call assert_fails("set wildcharm=<C-C>", "E474:")
  203. endfunc
  204. func Check_dir_option(name)
  205. " Check that it's possible to set the option.
  206. exe 'set ' . a:name . '=/usr/share/dict/words'
  207. call assert_equal('/usr/share/dict/words', eval('&' . a:name))
  208. exe 'set ' . a:name . '=/usr/share/dict/words,/and/there'
  209. call assert_equal('/usr/share/dict/words,/and/there', eval('&' . a:name))
  210. exe 'set ' . a:name . '=/usr/share/dict\ words'
  211. call assert_equal('/usr/share/dict words', eval('&' . a:name))
  212. " Check rejecting weird characters.
  213. call assert_fails("set " . a:name . "=/not&there", "E474:")
  214. call assert_fails("set " . a:name . "=/not>there", "E474:")
  215. call assert_fails("set " . a:name . "=/not.*there", "E474:")
  216. endfunc
  217. func Test_cinkeys()
  218. " This used to cause invalid memory access
  219. set cindent cinkeys=0
  220. norm a
  221. set cindent& cinkeys&
  222. endfunc
  223. func Test_dictionary()
  224. call Check_dir_option('dictionary')
  225. endfunc
  226. func Test_thesaurus()
  227. call Check_dir_option('thesaurus')
  228. endfun
  229. func Test_complete()
  230. " Trailing single backslash used to cause invalid memory access.
  231. set complete=s\
  232. new
  233. call feedkeys("i\<C-N>\<Esc>", 'xt')
  234. bwipe!
  235. call assert_fails('set complete=ix', 'E535:')
  236. set complete&
  237. endfun
  238. func Test_set_completion()
  239. call feedkeys(":set di\<C-A>\<C-B>\"\<CR>", 'tx')
  240. call assert_equal('"set dictionary diff diffexpr diffopt digraph directory display', @:)
  241. call feedkeys(":setlocal di\<C-A>\<C-B>\"\<CR>", 'tx')
  242. call assert_equal('"setlocal dictionary diff diffexpr diffopt digraph directory display', @:)
  243. call feedkeys(":setglobal di\<C-A>\<C-B>\"\<CR>", 'tx')
  244. call assert_equal('"setglobal dictionary diff diffexpr diffopt digraph directory display', @:)
  245. " Expand boolean options. When doing :set no<Tab> Vim prefixes the option
  246. " names with "no".
  247. call feedkeys(":set nodi\<C-A>\<C-B>\"\<CR>", 'tx')
  248. call assert_equal('"set nodiff nodigraph', @:)
  249. call feedkeys(":set invdi\<C-A>\<C-B>\"\<CR>", 'tx')
  250. call assert_equal('"set invdiff invdigraph', @:)
  251. " Expanding "set noinv" does nothing.
  252. call feedkeys(":set noinv\<C-A>\<C-B>\"\<CR>", 'tx')
  253. call assert_equal('"set noinv', @:)
  254. " Expand abbreviation of options.
  255. call feedkeys(":set ts\<C-A>\<C-B>\"\<CR>", 'tx')
  256. call assert_equal('"set tabstop thesaurus thesaurusfunc', @:)
  257. " Expand current value
  258. call feedkeys(":set suffixes=\<C-A>\<C-B>\"\<CR>", 'tx')
  259. call assert_equal('"set suffixes=.bak,~,.o,.h,.info,.swp,.obj', @:)
  260. call feedkeys(":set suffixes:\<C-A>\<C-B>\"\<CR>", 'tx')
  261. call assert_equal('"set suffixes:.bak,~,.o,.h,.info,.swp,.obj', @:)
  262. " Expand key codes.
  263. " call feedkeys(":set <H\<C-A>\<C-B>\"\<CR>", 'tx')
  264. " call assert_equal('"set <Help> <Home>', @:)
  265. " Expand terminal options.
  266. " call feedkeys(":set t_A\<C-A>\<C-B>\"\<CR>", 'tx')
  267. " call assert_equal('"set t_AB t_AF t_AU t_AL', @:)
  268. " call assert_fails('call feedkeys(":set <t_afoo>=\<C-A>\<CR>", "xt")', 'E474:')
  269. " Expand directories.
  270. call feedkeys(":set cdpath=./\<C-A>\<C-B>\"\<CR>", 'tx')
  271. call assert_match(' ./samples/ ', @:)
  272. call assert_notmatch(' ./summarize.vim ', @:)
  273. set cdpath&
  274. " Expand files and directories.
  275. call feedkeys(":set tags=./\<C-A>\<C-B>\"\<CR>", 'tx')
  276. call assert_match(' ./samples/.* ./summarize.vim', @:)
  277. call feedkeys(":set tags=./\\\\ dif\<C-A>\<C-B>\"\<CR>", 'tx')
  278. call assert_equal('"set tags=./\\ diff diffexpr diffopt', @:)
  279. " Expand files with spaces/commas in them. Make sure we delimit correctly.
  280. "
  281. " 'tags' allow for for spaces/commas to both act as delimiters, with actual
  282. " spaces requiring double escape, and commas need a single escape.
  283. " 'dictionary' is a normal comma-separated option where only commas act as
  284. " delimiters, and both space/comma need one single escape.
  285. " 'makeprg' is a non-comma-separated option. Commas don't need escape.
  286. defer delete('Xfoo Xspace.txt')
  287. defer delete('Xsp_dummy')
  288. defer delete('Xbar,Xcomma.txt')
  289. defer delete('Xcom_dummy')
  290. call writefile([], 'Xfoo Xspace.txt')
  291. call writefile([], 'Xsp_dummy')
  292. call writefile([], 'Xbar,Xcomma.txt')
  293. call writefile([], 'Xcom_dummy')
  294. call feedkeys(':set tags=./Xfoo\ Xsp' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
  295. call assert_equal('"set tags=./Xfoo\ Xsp_dummy', @:)
  296. call feedkeys(':set tags=./Xfoo\\\ Xsp' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
  297. call assert_equal('"set tags=./Xfoo\\\ Xspace.txt', @:)
  298. call feedkeys(':set dictionary=./Xfoo\ Xsp' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
  299. call assert_equal('"set dictionary=./Xfoo\ Xspace.txt', @:)
  300. call feedkeys(':set dictionary=./Xbar,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
  301. call assert_equal('"set dictionary=./Xbar,Xcom_dummy', @:)
  302. if has('win32')
  303. " In Windows, '\,' is literal, see `:help filename-backslash`, so this
  304. " means we treat it as one file name.
  305. call feedkeys(':set dictionary=Xbar\,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
  306. call assert_equal('"set dictionary=Xbar\,Xcomma.txt', @:)
  307. else
  308. " In other platforms, '\,' simply escape to ',', and indicate a delimiter
  309. " to split into a separate file name. You need '\\,' to escape the comma
  310. " as part of the file name.
  311. call feedkeys(':set dictionary=Xbar\,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
  312. call assert_equal('"set dictionary=Xbar\,Xcom_dummy', @:)
  313. call feedkeys(':set dictionary=Xbar\\,Xcom' .. "\<C-A>\<C-B>\"\<CR>", 'tx')
  314. call assert_equal('"set dictionary=Xbar\\,Xcomma.txt', @:)
  315. endif
  316. call feedkeys(":set makeprg=./Xbar,Xcom\<C-A>\<C-B>\"\<CR>", 'tx')
  317. call assert_equal('"set makeprg=./Xbar,Xcomma.txt', @:)
  318. set tags& dictionary& makeprg&
  319. " Expanding the option names
  320. call feedkeys(":set \<Tab>\<C-B>\"\<CR>", 'xt')
  321. call assert_equal('"set all', @:)
  322. " Expanding a second set of option names
  323. call feedkeys(":set wrapscan \<Tab>\<C-B>\"\<CR>", 'xt')
  324. call assert_equal('"set wrapscan all', @:)
  325. " Expanding a special keycode
  326. " call feedkeys(":set <Home>\<Tab>\<C-B>\"\<CR>", 'xt')
  327. " call assert_equal('"set <Home>', @:)
  328. " Expanding an invalid special keycode
  329. call feedkeys(":set <abcd>\<Tab>\<C-B>\"\<CR>", 'xt')
  330. call assert_equal("\"set <abcd>\<Tab>", @:)
  331. " Expanding a terminal keycode
  332. " call feedkeys(":set t_AB\<Tab>\<C-B>\"\<CR>", 'xt')
  333. " call assert_equal("\"set t_AB", @:)
  334. " Expanding an invalid option name
  335. call feedkeys(":set abcde=\<Tab>\<C-B>\"\<CR>", 'xt')
  336. call assert_equal("\"set abcde=\<Tab>", @:)
  337. " Expanding after a = for a boolean option
  338. call feedkeys(":set wrapscan=\<Tab>\<C-B>\"\<CR>", 'xt')
  339. call assert_equal("\"set wrapscan=\<Tab>", @:)
  340. " Expanding a numeric option
  341. call feedkeys(":set tabstop+=\<Tab>\<C-B>\"\<CR>", 'xt')
  342. call assert_equal("\"set tabstop+=" .. &tabstop, @:)
  343. " Expanding a non-boolean option
  344. call feedkeys(":set invtabstop=\<Tab>\<C-B>\"\<CR>", 'xt')
  345. call assert_equal("\"set invtabstop=", @:)
  346. " Expand options for 'spellsuggest'
  347. call feedkeys(":set spellsuggest=file:test_options.v\<Tab>\<C-B>\"\<CR>", 'xt')
  348. call assert_equal("\"set spellsuggest=file:test_options.vim", @:)
  349. call feedkeys(":set spellsuggest=best,file:test_options.v\<Tab>\<C-B>\"\<CR>", 'xt')
  350. call assert_equal("\"set spellsuggest=best,file:test_options.vim", @:)
  351. " Expanding value for 'key' is disallowed
  352. if exists('+key')
  353. set key=abcd
  354. call feedkeys(":set key=\<Tab>\<C-B>\"\<CR>", 'xt')
  355. call assert_equal('"set key=', @:)
  356. call feedkeys(":set key-=\<Tab>\<C-B>\"\<CR>", 'xt')
  357. call assert_equal('"set key-=', @:)
  358. set key=
  359. endif
  360. " Expand values for 'filetype'
  361. call feedkeys(":set filetype=sshdconfi\<Tab>\<C-B>\"\<CR>", 'xt')
  362. call assert_equal('"set filetype=sshdconfig', @:)
  363. call feedkeys(":set filetype=a\<C-A>\<C-B>\"\<CR>", 'xt')
  364. call assert_equal('"set filetype=' .. getcompletion('a*', 'filetype')->join(), @:)
  365. " Expand values for 'syntax'
  366. call feedkeys(":set syntax=sshdconfi\<Tab>\<C-B>\"\<CR>", 'xt')
  367. call assert_equal('"set syntax=sshdconfig', @:)
  368. call feedkeys(":set syntax=a\<C-A>\<C-B>\"\<CR>", 'xt')
  369. call assert_equal('"set syntax=' .. getcompletion('a*', 'syntax')->join(), @:)
  370. if has('keymap')
  371. " Expand values for 'keymap'
  372. call feedkeys(":set keymap=acc\<Tab>\<C-B>\"\<CR>", 'xt')
  373. call assert_equal('"set keymap=accents', @:)
  374. call feedkeys(":set keymap=a\<C-A>\<C-B>\"\<CR>", 'xt')
  375. call assert_equal('"set keymap=' .. getcompletion('a*', 'keymap')->join(), @:)
  376. endif
  377. endfunc
  378. " Test handling of expanding individual string option values
  379. func Test_set_completion_string_values()
  380. "
  381. " Test basic enum string options that have well-defined enum names
  382. "
  383. " call assert_equal(['lastline', 'truncate', 'uhex'], getcompletion('set display=', 'cmdline'))
  384. call assert_equal(['lastline', 'truncate', 'uhex', 'msgsep'], getcompletion('set display=', 'cmdline'))
  385. call assert_equal(['truncate'], getcompletion('set display=t', 'cmdline'))
  386. call assert_equal(['uhex'], getcompletion('set display=*ex*', 'cmdline'))
  387. " Test that if a value is set, it will populate the results, but only if
  388. " typed value is empty.
  389. set display=uhex,lastline
  390. " call assert_equal(['uhex,lastline', 'lastline', 'truncate', 'uhex'], getcompletion('set display=', 'cmdline'))
  391. call assert_equal(['uhex,lastline', 'lastline', 'truncate', 'uhex', 'msgsep'], getcompletion('set display=', 'cmdline'))
  392. call assert_equal(['uhex'], getcompletion('set display=u', 'cmdline'))
  393. " If the set value is part of the enum list, it will show as the first
  394. " result with no duplicate.
  395. set display=uhex
  396. " call assert_equal(['uhex', 'lastline', 'truncate'], getcompletion('set display=', 'cmdline'))
  397. call assert_equal(['uhex', 'lastline', 'truncate', 'msgsep'], getcompletion('set display=', 'cmdline'))
  398. " If empty value, will just show the normal list without an empty item
  399. set display=
  400. " call assert_equal(['lastline', 'truncate', 'uhex'], getcompletion('set display=', 'cmdline'))
  401. call assert_equal(['lastline', 'truncate', 'uhex', 'msgsep'], getcompletion('set display=', 'cmdline'))
  402. " Test escaping of the values
  403. " call assert_equal('vert:\|,fold:-,eob:~,lastline:@', getcompletion('set fillchars=', 'cmdline')[0])
  404. call assert_equal('vert:\|,foldsep:\|,fold:-', getcompletion('set fillchars=', 'cmdline')[0])
  405. " Test comma-separated lists will expand after a comma.
  406. call assert_equal(['uhex'], getcompletion('set display=truncate,*ex*', 'cmdline'))
  407. " Also test the positioning of the expansion is correct
  408. call feedkeys(":set display=truncate,l\<Tab>\<C-B>\"\<CR>", 'xt')
  409. call assert_equal('"set display=truncate,lastline', @:)
  410. set display&
  411. " Test single-value options will not expand after a comma
  412. call assert_equal([], getcompletion('set ambw=single,', 'cmdline'))
  413. " Test the other simple options to make sure they have basic auto-complete,
  414. " but don't exhaustively validate their results.
  415. call assert_equal('single', getcompletion('set ambw=', 'cmdline')[0])
  416. call assert_match('light\|dark', getcompletion('set bg=', 'cmdline')[1])
  417. call assert_equal('indent', getcompletion('set backspace=', 'cmdline')[0])
  418. call assert_equal('yes', getcompletion('set backupcopy=', 'cmdline')[1])
  419. call assert_equal('backspace', getcompletion('set belloff=', 'cmdline')[1])
  420. call assert_equal('min:', getcompletion('set briopt=', 'cmdline')[1])
  421. if exists('+browsedir')
  422. call assert_equal('current', getcompletion('set browsedir=', 'cmdline')[1])
  423. endif
  424. call assert_equal('unload', getcompletion('set bufhidden=', 'cmdline')[1])
  425. call assert_equal('nowrite', getcompletion('set buftype=', 'cmdline')[1])
  426. call assert_equal('internal', getcompletion('set casemap=', 'cmdline')[1])
  427. if exists('+clipboard')
  428. " call assert_match('unnamed', getcompletion('set clipboard=', 'cmdline')[1])
  429. call assert_match('unnamed', getcompletion('set clipboard=', 'cmdline')[0])
  430. endif
  431. call assert_equal('.', getcompletion('set complete=', 'cmdline')[1])
  432. call assert_equal('menu', getcompletion('set completeopt=', 'cmdline')[1])
  433. if exists('+completeslash')
  434. call assert_equal('backslash', getcompletion('set completeslash=', 'cmdline')[1])
  435. endif
  436. if exists('+cryptmethod')
  437. call assert_equal('zip', getcompletion('set cryptmethod=', 'cmdline')[1])
  438. endif
  439. if exists('+cursorlineopt')
  440. call assert_equal('line', getcompletion('set cursorlineopt=', 'cmdline')[1])
  441. endif
  442. call assert_equal('throw', getcompletion('set debug=', 'cmdline')[1])
  443. call assert_equal('ver', getcompletion('set eadirection=', 'cmdline')[1])
  444. call assert_equal('mac', getcompletion('set fileformat=', 'cmdline')[2])
  445. if exists('+foldclose')
  446. call assert_equal('all', getcompletion('set foldclose=', 'cmdline')[0])
  447. endif
  448. if exists('+foldmethod')
  449. call assert_equal('expr', getcompletion('set foldmethod=', 'cmdline')[1])
  450. endif
  451. if exists('+foldopen')
  452. call assert_equal('all', getcompletion('set foldopen=', 'cmdline')[1])
  453. endif
  454. call assert_equal('stack', getcompletion('set jumpoptions=', 'cmdline')[0])
  455. call assert_equal('stopsel', getcompletion('set keymodel=', 'cmdline')[1])
  456. call assert_equal('expr:1', getcompletion('set lispoptions=', 'cmdline')[1])
  457. call assert_match('popup', getcompletion('set mousemodel=', 'cmdline')[2])
  458. call assert_equal('bin', getcompletion('set nrformats=', 'cmdline')[1])
  459. if exists('+rightleftcmd')
  460. call assert_equal('search', getcompletion('set rightleftcmd=', 'cmdline')[0])
  461. endif
  462. call assert_equal('ver', getcompletion('set scrollopt=', 'cmdline')[1])
  463. call assert_equal('exclusive', getcompletion('set selection=', 'cmdline')[1])
  464. call assert_equal('key', getcompletion('set selectmode=', 'cmdline')[1])
  465. if exists('+ssop')
  466. call assert_equal('buffers', getcompletion('set ssop=', 'cmdline')[1])
  467. endif
  468. call assert_equal('statusline', getcompletion('set showcmdloc=', 'cmdline')[1])
  469. if exists('+signcolumn')
  470. call assert_equal('yes', getcompletion('set signcolumn=', 'cmdline')[1])
  471. endif
  472. if exists('+spelloptions')
  473. call assert_equal('camel', getcompletion('set spelloptions=', 'cmdline')[0])
  474. endif
  475. if exists('+spellsuggest')
  476. call assert_equal('best', getcompletion('set spellsuggest+=', 'cmdline')[0])
  477. endif
  478. call assert_equal('screen', getcompletion('set splitkeep=', 'cmdline')[1])
  479. " call assert_equal('sync', getcompletion('set swapsync=', 'cmdline')[1])
  480. call assert_equal('usetab', getcompletion('set switchbuf=', 'cmdline')[1])
  481. call assert_equal('ignore', getcompletion('set tagcase=', 'cmdline')[1])
  482. if exists('+tabclose')
  483. call assert_equal('left uselast', join(sort(getcompletion('set tabclose=', 'cmdline'))), ' ')
  484. endif
  485. if exists('+termwintype')
  486. call assert_equal('conpty', getcompletion('set termwintype=', 'cmdline')[1])
  487. endif
  488. if exists('+toolbar')
  489. call assert_equal('text', getcompletion('set toolbar=', 'cmdline')[1])
  490. endif
  491. if exists('+tbis')
  492. call assert_equal('medium', getcompletion('set tbis=', 'cmdline')[2])
  493. endif
  494. if exists('+ttymouse')
  495. set ttymouse=
  496. call assert_equal('xterm2', getcompletion('set ttymouse=', 'cmdline')[1])
  497. set ttymouse&
  498. endif
  499. call assert_equal('insert', getcompletion('set virtualedit=', 'cmdline')[1])
  500. call assert_equal('longest', getcompletion('set wildmode=', 'cmdline')[1])
  501. call assert_equal('full', getcompletion('set wildmode=list,longest:', 'cmdline')[0])
  502. call assert_equal('tagfile', getcompletion('set wildoptions=', 'cmdline')[1])
  503. if exists('+winaltkeys')
  504. call assert_equal('yes', getcompletion('set winaltkeys=', 'cmdline')[1])
  505. endif
  506. " Other string options that queries the system rather than fixed enum names
  507. call assert_equal(['all', 'BufAdd'], getcompletion('set eventignore=', 'cmdline')[0:1])
  508. call assert_equal('latin1', getcompletion('set fileencodings=', 'cmdline')[1])
  509. " call assert_equal('top', getcompletion('set printoptions=', 'cmdline')[0])
  510. " call assert_equal('SpecialKey', getcompletion('set wincolor=', 'cmdline')[0])
  511. call assert_equal('eol', getcompletion('set listchars+=', 'cmdline')[0])
  512. call assert_equal(['multispace', 'leadmultispace'], getcompletion('set listchars+=', 'cmdline')[-2:])
  513. call assert_equal('eol', getcompletion('setl listchars+=', 'cmdline')[0])
  514. call assert_equal(['multispace', 'leadmultispace'], getcompletion('setl listchars+=', 'cmdline')[-2:])
  515. call assert_equal('stl', getcompletion('set fillchars+=', 'cmdline')[0])
  516. call assert_equal('stl', getcompletion('setl fillchars+=', 'cmdline')[0])
  517. "
  518. " Unique string options below
  519. "
  520. " keyprotocol: only auto-complete when after ':' with known protocol types
  521. " call assert_equal([&keyprotocol], getcompletion('set keyprotocol=', 'cmdline'))
  522. " call feedkeys(":set keyprotocol+=someterm:m\<Tab>\<C-B>\"\<CR>", 'xt')
  523. " call assert_equal('"set keyprotocol+=someterm:mok2', @:)
  524. " set keyprotocol&
  525. " previewpopup / completepopup
  526. " call assert_equal('height:', getcompletion('set previewpopup=', 'cmdline')[0])
  527. " call assert_equal('EndOfBuffer', getcompletion('set previewpopup=highlight:End*Buffer', 'cmdline')[0])
  528. " call feedkeys(":set previewpopup+=border:\<Tab>\<C-B>\"\<CR>", 'xt')
  529. " call assert_equal('"set previewpopup+=border:on', @:)
  530. " call feedkeys(":set completepopup=height:10,align:\<Tab>\<C-B>\"\<CR>", 'xt')
  531. " call assert_equal('"set completepopup=height:10,align:item', @:)
  532. " call assert_equal([], getcompletion('set completepopup=bogusname:', 'cmdline'))
  533. " set previewpopup& completepopup&
  534. " diffopt: special handling of algorithm:<alg_list>
  535. call assert_equal('filler', getcompletion('set diffopt+=', 'cmdline')[0])
  536. call assert_equal([], getcompletion('set diffopt+=iblank,foldcolumn:', 'cmdline'))
  537. call assert_equal('patience', getcompletion('set diffopt+=iblank,algorithm:pat*', 'cmdline')[0])
  538. " highlight: special parsing, including auto-completing highlight groups
  539. " after ':'
  540. " call assert_equal([&hl, '8'], getcompletion('set hl=', 'cmdline')[0:1])
  541. " call assert_equal('8', getcompletion('set hl+=', 'cmdline')[0])
  542. " call assert_equal(['8:', '8b', '8i'], getcompletion('set hl+=8', 'cmdline')[0:2])
  543. " call assert_equal('8bi', getcompletion('set hl+=8b', 'cmdline')[0])
  544. " call assert_equal('NonText', getcompletion('set hl+=8:No*ext', 'cmdline')[0])
  545. " If all the display modes are used up we should be suggesting nothing. Make
  546. " a hl typed option with all the modes which will look like '8bi-nrsuc2d=t',
  547. " and make sure nothing is suggested from that.
  548. " let hl_display_modes = join(
  549. " \ filter(map(getcompletion('set hl+=8', 'cmdline'),
  550. " \ {idx, val -> val[1]}),
  551. " \ {idx, val -> val != ':'}),
  552. " \ '')
  553. " call assert_equal([], getcompletion('set hl+=8'..hl_display_modes, 'cmdline'))
  554. " Test completion in middle of the line
  555. " call feedkeys(":set hl=8b i\<Left>\<Left>\<Tab>\<C-B>\"\<CR>", 'xt')
  556. " call assert_equal("\"set hl=8bi i", @:)
  557. "
  558. " Test flag lists
  559. "
  560. " Test set=. Show the original value if nothing is typed after '='.
  561. " Otherwise, the list should avoid showing what's already typed.
  562. set mouse=v
  563. call assert_equal(['v','a','n','i','c','h','r'], getcompletion('set mouse=', 'cmdline'))
  564. set mouse=nvi
  565. call assert_equal(['nvi','a','n','v','i','c','h','r'], getcompletion('set mouse=', 'cmdline'))
  566. call assert_equal(['a','v','i','c','r'], getcompletion('set mouse=hn', 'cmdline'))
  567. " Test set+=. Never show original value, and it also tries to avoid listing
  568. " flags that's already in the option value.
  569. call assert_equal(['a','c','h','r'], getcompletion('set mouse+=', 'cmdline'))
  570. call assert_equal(['a','c','r'], getcompletion('set mouse+=hn', 'cmdline'))
  571. call assert_equal([], getcompletion('set mouse+=acrhn', 'cmdline'))
  572. " Test that the position of the expansion is correct (even if there are
  573. " additional values after the current cursor)
  574. call feedkeys(":set mouse=hn\<Left>\<Tab>\<C-B>\"\<CR>", 'xt')
  575. call assert_equal('"set mouse=han', @:)
  576. set mouse&
  577. " Test that other flag list options have auto-complete, but don't
  578. " exhaustively validate their results.
  579. if exists('+concealcursor')
  580. call assert_equal('n', getcompletion('set cocu=', 'cmdline')[0])
  581. endif
  582. call assert_equal('a', getcompletion('set cpo=', 'cmdline')[1])
  583. call assert_equal('t', getcompletion('set fo=', 'cmdline')[1])
  584. if exists('+guioptions')
  585. call assert_equal('!', getcompletion('set go=', 'cmdline')[1])
  586. endif
  587. call assert_equal('r', getcompletion('set shortmess=', 'cmdline')[1])
  588. call assert_equal('b', getcompletion('set whichwrap=', 'cmdline')[1])
  589. "
  590. "Test set-=
  591. "
  592. " Normal single-value option just shows the existing value
  593. set ambiwidth=double
  594. call assert_equal(['double'], getcompletion('set ambw-=', 'cmdline'))
  595. set ambiwidth&
  596. " Works on numbers and term options as well
  597. call assert_equal([string(&laststatus)], getcompletion('set laststatus-=', 'cmdline'))
  598. set t_Ce=testCe
  599. " call assert_equal(['testCe'], getcompletion('set t_Ce-=', 'cmdline'))
  600. set t_Ce&
  601. " Comma-separated lists should present each option
  602. set diffopt=context:123,,,,,iblank,iwhiteall
  603. call assert_equal(['context:123', 'iblank', 'iwhiteall'], getcompletion('set diffopt-=', 'cmdline'))
  604. call assert_equal(['context:123', 'iblank'], getcompletion('set diffopt-=*n*', 'cmdline'))
  605. call assert_equal(['iblank', 'iwhiteall'], getcompletion('set diffopt-=i', 'cmdline'))
  606. " Don't present more than one option as it doesn't make sense in set-=
  607. call assert_equal([], getcompletion('set diffopt-=iblank,', 'cmdline'))
  608. " Test empty option
  609. set diffopt=
  610. call assert_equal([], getcompletion('set diffopt-=', 'cmdline'))
  611. set diffopt&
  612. " Test escaping output
  613. call assert_equal('vert:\|', getcompletion('set fillchars-=', 'cmdline')[0])
  614. " Test files with commas in name are being parsed and escaped properly
  615. set path=has\\\ space,file\\,with\\,comma,normal_file
  616. if exists('+completeslash')
  617. call assert_equal(['has\\\ space', 'file\,with\,comma', 'normal_file'], getcompletion('set path-=', 'cmdline'))
  618. else
  619. call assert_equal(['has\\\ space', 'file\\,with\\,comma', 'normal_file'], getcompletion('set path-=', 'cmdline'))
  620. endif
  621. set path&
  622. " Flag list should present orig value, then individual flags
  623. set mouse=v
  624. call assert_equal(['v'], getcompletion('set mouse-=', 'cmdline'))
  625. set mouse=avn
  626. call assert_equal(['avn','a','v','n'], getcompletion('set mouse-=', 'cmdline'))
  627. " Don't auto-complete when we have at least one flags already
  628. call assert_equal([], getcompletion('set mouse-=n', 'cmdline'))
  629. " Test empty option
  630. set mouse=
  631. call assert_equal([], getcompletion('set mouse-=', 'cmdline'))
  632. set mouse&
  633. " 'whichwrap' is an odd case where it's both flag list and comma-separated
  634. set ww=b,h
  635. call assert_equal(['b','h'], getcompletion('set ww-=', 'cmdline'))
  636. set ww&
  637. endfunc
  638. func Test_set_option_errors()
  639. call assert_fails('set scroll=-1', 'E49:')
  640. call assert_fails('set backupcopy=', 'E474:')
  641. call assert_fails('set regexpengine=3', 'E474:')
  642. call assert_fails('set history=10001', 'E474:')
  643. call assert_fails('set msghistory=10001', 'E474:')
  644. call assert_fails('set numberwidth=21', 'E474:')
  645. call assert_fails('set colorcolumn=-a', 'E474:')
  646. call assert_fails('set colorcolumn=a', 'E474:')
  647. call assert_fails('set colorcolumn=1,', 'E474:')
  648. call assert_fails('set colorcolumn=1;', 'E474:')
  649. call assert_fails('set cmdheight=-1', 'E487:')
  650. call assert_fails('set cmdwinheight=-1', 'E487:')
  651. if has('conceal')
  652. call assert_fails('set conceallevel=-1', 'E487:')
  653. call assert_fails('set conceallevel=4', 'E474:')
  654. endif
  655. call assert_fails('set helpheight=-1', 'E487:')
  656. call assert_fails('set history=-1', 'E487:')
  657. call assert_fails('set msghistory=-1', 'E487:')
  658. call assert_fails('set report=-1', 'E487:')
  659. call assert_fails('set shiftwidth=-1', 'E487:')
  660. call assert_fails('set sidescroll=-1', 'E487:')
  661. call assert_fails('set tabstop=-1', 'E487:')
  662. call assert_fails('set tabstop=10000', 'E474:')
  663. call assert_fails('let &tabstop = 10000', 'E474:')
  664. call assert_fails('set tabstop=5500000000', 'E474:')
  665. call assert_fails('set textwidth=-1', 'E487:')
  666. call assert_fails('set timeoutlen=-1', 'E487:')
  667. call assert_fails('set updatecount=-1', 'E487:')
  668. call assert_fails('set updatetime=-1', 'E487:')
  669. call assert_fails('set winheight=-1', 'E487:')
  670. call assert_fails('set tabstop!', 'E488:')
  671. " Test for setting unknown option errors
  672. call assert_fails('set xxx', 'E518:')
  673. call assert_fails('setlocal xxx', 'E518:')
  674. call assert_fails('setglobal xxx', 'E518:')
  675. call assert_fails('set xxx=', 'E518:')
  676. call assert_fails('setlocal xxx=', 'E518:')
  677. call assert_fails('setglobal xxx=', 'E518:')
  678. call assert_fails('set xxx:', 'E518:')
  679. call assert_fails('setlocal xxx:', 'E518:')
  680. call assert_fails('setglobal xxx:', 'E518:')
  681. call assert_fails('set xxx!', 'E518:')
  682. call assert_fails('setlocal xxx!', 'E518:')
  683. call assert_fails('setglobal xxx!', 'E518:')
  684. call assert_fails('set xxx?', 'E518:')
  685. call assert_fails('setlocal xxx?', 'E518:')
  686. call assert_fails('setglobal xxx?', 'E518:')
  687. call assert_fails('set xxx&', 'E518:')
  688. call assert_fails('setlocal xxx&', 'E518:')
  689. call assert_fails('setglobal xxx&', 'E518:')
  690. call assert_fails('set xxx<', 'E518:')
  691. call assert_fails('setlocal xxx<', 'E518:')
  692. call assert_fails('setglobal xxx<', 'E518:')
  693. " Test for missing-options errors.
  694. " call assert_fails('set autoprint?', 'E519:')
  695. " call assert_fails('set beautify?', 'E519:')
  696. " call assert_fails('set flash?', 'E519:')
  697. " call assert_fails('set graphic?', 'E519:')
  698. " call assert_fails('set hardtabs?', 'E519:')
  699. " call assert_fails('set mesg?', 'E519:')
  700. " call assert_fails('set novice?', 'E519:')
  701. " call assert_fails('set open?', 'E519:')
  702. " call assert_fails('set optimize?', 'E519:')
  703. " call assert_fails('set redraw?', 'E519:')
  704. " call assert_fails('set slowopen?', 'E519:')
  705. " call assert_fails('set sourceany?', 'E519:')
  706. " call assert_fails('set w300?', 'E519:')
  707. " call assert_fails('set w1200?', 'E519:')
  708. " call assert_fails('set w9600?', 'E519:')
  709. call assert_fails('set undolevels=x', 'E521:')
  710. call assert_fails('set tabstop=', 'E521:')
  711. call assert_fails('set comments=-', 'E524:')
  712. call assert_fails('set comments=a', 'E525:')
  713. call assert_fails('set foldmarker=x', 'E536:')
  714. call assert_fails('set commentstring=x', 'E537:')
  715. call assert_fails('let &commentstring = "x"', 'E537:')
  716. call assert_fails('set complete=x', 'E539:')
  717. call assert_fails('set rulerformat=%-', 'E539:')
  718. call assert_fails('set rulerformat=%(', 'E542:')
  719. call assert_fails('set rulerformat=%15(%%', 'E542:')
  720. " Test for 'statusline' errors
  721. call assert_fails('set statusline=%$', 'E539:')
  722. call assert_fails('set statusline=%{', 'E540:')
  723. call assert_fails('set statusline=%{%', 'E540:')
  724. call assert_fails('set statusline=%{%}', 'E539:')
  725. call assert_fails('set statusline=%(', 'E542:')
  726. call assert_fails('set statusline=%)', 'E542:')
  727. " Test for 'tabline' errors
  728. call assert_fails('set tabline=%$', 'E539:')
  729. call assert_fails('set tabline=%{', 'E540:')
  730. call assert_fails('set tabline=%{%', 'E540:')
  731. call assert_fails('set tabline=%{%}', 'E539:')
  732. call assert_fails('set tabline=%(', 'E542:')
  733. call assert_fails('set tabline=%)', 'E542:')
  734. if has('cursorshape')
  735. " This invalid value for 'guicursor' used to cause Vim to crash.
  736. call assert_fails('set guicursor=i-ci,r-cr:h', 'E545:')
  737. call assert_fails('set guicursor=i-ci', 'E545:')
  738. call assert_fails('set guicursor=x', 'E545:')
  739. call assert_fails('set guicursor=x:', 'E546:')
  740. call assert_fails('set guicursor=r-cr:horx', 'E548:')
  741. call assert_fails('set guicursor=r-cr:hor0', 'E549:')
  742. endif
  743. if has('mouseshape')
  744. call assert_fails('se mouseshape=i-r:x', 'E547:')
  745. endif
  746. " Test for 'backupext' and 'patchmode' set to the same value
  747. set backupext=.bak
  748. set patchmode=.patch
  749. call assert_fails('set patchmode=.bak', 'E589:')
  750. call assert_equal('.patch', &patchmode)
  751. call assert_fails('set backupext=.patch', 'E589:')
  752. call assert_equal('.bak', &backupext)
  753. set backupext& patchmode&
  754. " 'winheight' cannot be smaller than 'winminheight'
  755. call assert_fails('set winminheight=10 winheight=9', 'E591:')
  756. set winminheight& winheight&
  757. set winheight=10 winminheight=10
  758. call assert_fails('set winheight=9', 'E591:')
  759. set winminheight& winheight&
  760. " 'winwidth' cannot be smaller than 'winminwidth'
  761. call assert_fails('set winminwidth=10 winwidth=9', 'E592:')
  762. set winminwidth& winwidth&
  763. call assert_fails('set winwidth=9 winminwidth=10', 'E592:')
  764. set winwidth& winminwidth&
  765. call assert_fails("set showbreak=\x01", 'E595:')
  766. " call assert_fails('set t_foo=', 'E846:')
  767. call assert_fails('set tabstop??', 'E488:')
  768. call assert_fails('set wrapscan!!', 'E488:')
  769. call assert_fails('set tabstop&&', 'E488:')
  770. call assert_fails('set wrapscan<<', 'E488:')
  771. call assert_fails('set wrapscan=1', 'E474:')
  772. call assert_fails('set autoindent@', 'E488:')
  773. call assert_fails('set wildchar=<abc>', 'E474:')
  774. call assert_fails('set cmdheight=1a', 'E521:')
  775. call assert_fails('set invcmdheight', 'E474:')
  776. if has('python') || has('python3')
  777. call assert_fails('set pyxversion=6', 'E474:')
  778. endif
  779. call assert_fails("let &tabstop='ab'", ['E521:', 'E521:'])
  780. call assert_fails('set spellcapcheck=%\\(', 'E54:')
  781. call assert_fails('set sessionoptions=curdir,sesdir', 'E474:')
  782. call assert_fails('set foldmarker={{{,', 'E474:')
  783. call assert_fails('set sessionoptions=sesdir,curdir', 'E474:')
  784. " 'ambiwidth' conflict 'listchars'
  785. setlocal listchars=trail:·
  786. call assert_fails('set ambiwidth=double', 'E834:')
  787. setlocal listchars=trail:-
  788. setglobal listchars=trail:·
  789. call assert_fails('set ambiwidth=double', 'E834:')
  790. set listchars&
  791. " 'ambiwidth' conflict 'fillchars'
  792. setlocal fillchars=stl:·
  793. call assert_fails('set ambiwidth=double', 'E835:')
  794. setlocal fillchars=stl:-
  795. setglobal fillchars=stl:·
  796. call assert_fails('set ambiwidth=double', 'E835:')
  797. set fillchars&
  798. call assert_fails('set fileencoding=latin1,utf-8', 'E474:')
  799. set nomodifiable
  800. call assert_fails('set fileencoding=latin1', 'E21:')
  801. set modifiable&
  802. " call assert_fails('set t_#-&', 'E522:')
  803. call assert_fails('let &formatoptions = "?"', 'E539:')
  804. call assert_fails('call setbufvar("", "&formatoptions", "?")', 'E539:')
  805. " Should raises only one error if passing a wrong variable type.
  806. call assert_fails('call setwinvar(0, "&scrolloff", [])', ['E745:', 'E745:'])
  807. call assert_fails('call setwinvar(0, "&list", [])', ['E745:', 'E745:'])
  808. call assert_fails('call setwinvar(0, "&listchars", [])', ['E730:', 'E730:'])
  809. call assert_fails('call setwinvar(0, "&nosuchoption", 0)', ['E355:', 'E355:'])
  810. call assert_fails('call setwinvar(0, "&nosuchoption", "")', ['E355:', 'E355:'])
  811. call assert_fails('call setwinvar(0, "&nosuchoption", [])', ['E355:', 'E355:'])
  812. endfunc
  813. func CheckWasSet(name)
  814. let verb_cm = execute('verbose set ' .. a:name .. '?')
  815. call assert_match('Last set from.*test_options.vim', verb_cm)
  816. endfunc
  817. func CheckWasNotSet(name)
  818. let verb_cm = execute('verbose set ' .. a:name .. '?')
  819. call assert_notmatch('Last set from', verb_cm)
  820. endfunc
  821. " Must be executed before other tests that set 'term'.
  822. func Test_000_term_option_verbose()
  823. throw "Skipped: Nvim does not support setting 'term'"
  824. CheckNotGui
  825. call CheckWasNotSet('t_cm')
  826. let term_save = &term
  827. set term=ansi
  828. call CheckWasSet('t_cm')
  829. let &term = term_save
  830. endfunc
  831. func Test_copy_context()
  832. setlocal list
  833. call CheckWasSet('list')
  834. split
  835. call CheckWasSet('list')
  836. quit
  837. setlocal nolist
  838. set ai
  839. call CheckWasSet('ai')
  840. set filetype=perl
  841. call CheckWasSet('filetype')
  842. set fo=tcroq
  843. call CheckWasSet('fo')
  844. split Xsomebuf
  845. call CheckWasSet('ai')
  846. call CheckWasNotSet('filetype')
  847. call CheckWasSet('fo')
  848. endfunc
  849. func Test_set_ttytype()
  850. throw "Skipped: Nvim does not support 'ttytype'"
  851. CheckUnix
  852. CheckNotGui
  853. " Setting 'ttytype' used to cause a double-free when exiting vim and
  854. " when vim is compiled with -DEXITFREE.
  855. set ttytype=ansi
  856. call assert_equal('ansi', &ttytype)
  857. call assert_equal(&ttytype, &term)
  858. set ttytype=xterm
  859. call assert_equal('xterm', &ttytype)
  860. call assert_equal(&ttytype, &term)
  861. try
  862. set ttytype=
  863. call assert_report('set ttytype= did not fail')
  864. catch /E529/
  865. endtry
  866. " Some systems accept any terminal name and return dumb settings,
  867. " check for failure of finding the entry and for missing 'cm' entry.
  868. try
  869. set ttytype=xxx
  870. call assert_report('set ttytype=xxx did not fail')
  871. catch /E522\|E437/
  872. endtry
  873. set ttytype&
  874. call assert_equal(&ttytype, &term)
  875. if has('gui') && !has('gui_running')
  876. call assert_fails('set term=gui', 'E531:')
  877. endif
  878. endfunc
  879. " Test for :set all
  880. func Test_set_all()
  881. set tw=75
  882. set iskeyword=a-z,A-Z
  883. set nosplitbelow
  884. let out = execute('set all')
  885. call assert_match('textwidth=75', out)
  886. call assert_match('iskeyword=a-z,A-Z', out)
  887. call assert_match('nosplitbelow', out)
  888. set tw& iskeyword& splitbelow&
  889. endfunc
  890. " Test for :set! all
  891. func Test_set_all_one_column()
  892. let out_mult = execute('set all')->split("\n")
  893. let out_one = execute('set! all')->split("\n")
  894. call assert_true(len(out_mult) < len(out_one))
  895. call assert_equal(out_one[0], '--- Options ---')
  896. let options = out_one[1:]->mapnew({_, line -> line[2:]})
  897. call assert_equal(sort(copy(options)), options)
  898. endfunc
  899. func Test_renderoptions()
  900. throw 'skipped: Nvim does not support renderoptions'
  901. " Only do this for Windows Vista and later, fails on Windows XP and earlier.
  902. " Doesn't hurt to do this on a non-Windows system.
  903. if windowsversion() !~ '^[345]\.'
  904. set renderoptions=type:directx
  905. set rop=type:directx
  906. endif
  907. endfunc
  908. func ResetIndentexpr()
  909. set indentexpr=
  910. endfunc
  911. func Test_set_indentexpr()
  912. " this was causing usage of freed memory
  913. set indentexpr=ResetIndentexpr()
  914. new
  915. call feedkeys("i\<c-f>", 'x')
  916. call assert_equal('', &indentexpr)
  917. bwipe!
  918. endfunc
  919. func Test_backupskip()
  920. " Option 'backupskip' may contain several comma-separated path
  921. " specifications if one or more of the environment variables TMPDIR, TMP,
  922. " or TEMP is defined. To simplify testing, convert the string value into a
  923. " list.
  924. let bsklist = split(&bsk, ',')
  925. if has("mac")
  926. let found = (index(bsklist, '/private/tmp/*') >= 0)
  927. call assert_true(found, '/private/tmp not in option bsk: ' . &bsk)
  928. elseif has("unix")
  929. let found = (index(bsklist, '/tmp/*') >= 0)
  930. call assert_true(found, '/tmp not in option bsk: ' . &bsk)
  931. endif
  932. " If our test platform is Windows, the path(s) in option bsk will use
  933. " backslash for the path separator and the components could be in short
  934. " (8.3) format. As such, we need to replace the backslashes with forward
  935. " slashes and convert the path components to long format. The expand()
  936. " function will do this but it cannot handle comma-separated paths. This is
  937. " why bsk was converted from a string into a list of strings above.
  938. "
  939. " One final complication is that the wildcard "/*" is at the end of each
  940. " path and so expand() might return a list of matching files. To prevent
  941. " this, we need to remove the wildcard before calling expand() and then
  942. " append it afterwards.
  943. if has('win32')
  944. let item_nbr = 0
  945. while item_nbr < len(bsklist)
  946. let path_spec = bsklist[item_nbr]
  947. let path_spec = strcharpart(path_spec, 0, strlen(path_spec)-2)
  948. let path_spec = substitute(expand(path_spec), '\\', '/', 'g')
  949. let bsklist[item_nbr] = path_spec . '/*'
  950. let item_nbr += 1
  951. endwhile
  952. endif
  953. " Option bsk will also include these environment variables if defined.
  954. " If they're defined, verify they appear in the option value.
  955. for var in ['$TMPDIR', '$TMP', '$TEMP']
  956. if exists(var)
  957. let varvalue = substitute(expand(var), '\\', '/', 'g')
  958. let varvalue = substitute(varvalue, '/$', '', '')
  959. let varvalue .= '/*'
  960. let found = (index(bsklist, varvalue) >= 0)
  961. call assert_true(found, var . ' (' . varvalue . ') not in option bsk: ' . &bsk)
  962. endif
  963. endfor
  964. " Duplicates from environment variables should be filtered out (option has
  965. " P_NODUP). Run this in a separate instance and write v:errors in a file,
  966. " so that we see what happens on startup.
  967. let after =<< trim [CODE]
  968. let bsklist = split(&backupskip, ',')
  969. call assert_equal(uniq(copy(bsklist)), bsklist)
  970. call writefile(['errors:'] + v:errors, 'Xtestout')
  971. qall
  972. [CODE]
  973. call writefile(after, 'Xafter')
  974. " let cmd = GetVimProg() . ' --not-a-term -S Xafter --cmd "set enc=utf8"'
  975. let cmd = GetVimProg() . ' -S Xafter --cmd "set enc=utf8"'
  976. let saveenv = {}
  977. for var in ['TMPDIR', 'TMP', 'TEMP']
  978. let saveenv[var] = getenv(var)
  979. call setenv(var, '/duplicate/path')
  980. endfor
  981. exe 'silent !' . cmd
  982. call assert_equal(['errors:'], readfile('Xtestout'))
  983. " restore environment variables
  984. for var in ['TMPDIR', 'TMP', 'TEMP']
  985. call setenv(var, saveenv[var])
  986. endfor
  987. call delete('Xtestout')
  988. call delete('Xafter')
  989. " Duplicates should be filtered out (option has P_NODUP)
  990. let backupskip = &backupskip
  991. set backupskip=
  992. set backupskip+=/test/dir
  993. set backupskip+=/other/dir
  994. set backupskip+=/test/dir
  995. call assert_equal('/test/dir,/other/dir', &backupskip)
  996. let &backupskip = backupskip
  997. endfunc
  998. func Test_buf_copy_winopt()
  999. set hidden
  1000. " Test copy option from current buffer in window
  1001. split
  1002. enew
  1003. setlocal numberwidth=5
  1004. wincmd w
  1005. call assert_equal(4,&numberwidth)
  1006. bnext
  1007. call assert_equal(5,&numberwidth)
  1008. bw!
  1009. call assert_equal(4,&numberwidth)
  1010. " Test copy value from window that used to be display the buffer
  1011. split
  1012. enew
  1013. setlocal numberwidth=6
  1014. bnext
  1015. wincmd w
  1016. call assert_equal(4,&numberwidth)
  1017. bnext
  1018. call assert_equal(6,&numberwidth)
  1019. bw!
  1020. " Test that if buffer is current, don't use the stale cached value
  1021. " from the last time the buffer was displayed.
  1022. split
  1023. enew
  1024. setlocal numberwidth=7
  1025. bnext
  1026. bnext
  1027. setlocal numberwidth=8
  1028. wincmd w
  1029. call assert_equal(4,&numberwidth)
  1030. bnext
  1031. call assert_equal(8,&numberwidth)
  1032. bw!
  1033. " Test value is not copied if window already has seen the buffer
  1034. enew
  1035. split
  1036. setlocal numberwidth=9
  1037. bnext
  1038. setlocal numberwidth=10
  1039. wincmd w
  1040. call assert_equal(4,&numberwidth)
  1041. bnext
  1042. call assert_equal(4,&numberwidth)
  1043. bw!
  1044. set hidden&
  1045. endfunc
  1046. func Test_split_copy_options()
  1047. let values = [
  1048. \['cursorbind', 1, 0],
  1049. \['fillchars', '"vert:-"', '"' .. &fillchars .. '"'],
  1050. \['list', 1, 0],
  1051. \['listchars', '"space:-"', '"' .. &listchars .. '"'],
  1052. \['number', 1, 0],
  1053. \['relativenumber', 1, 0],
  1054. \['scrollbind', 1, 0],
  1055. \['smoothscroll', 1, 0],
  1056. \['virtualedit', '"block"', '"' .. &virtualedit .. '"'],
  1057. "\ ['wincolor', '"Search"', '"' .. &wincolor .. '"'],
  1058. \['wrap', 0, 1],
  1059. \]
  1060. if has('linebreak')
  1061. let values += [
  1062. \['breakindent', 1, 0],
  1063. \['breakindentopt', '"min:5"', '"' .. &breakindentopt .. '"'],
  1064. \['linebreak', 1, 0],
  1065. \['numberwidth', 7, 4],
  1066. \['showbreak', '"++"', '"' .. &showbreak .. '"'],
  1067. \]
  1068. endif
  1069. if has('rightleft')
  1070. let values += [
  1071. \['rightleft', 1, 0],
  1072. \['rightleftcmd', '"search"', '"' .. &rightleftcmd .. '"'],
  1073. \]
  1074. endif
  1075. if has('statusline')
  1076. let values += [
  1077. \['statusline', '"---%f---"', '"' .. &statusline .. '"'],
  1078. \]
  1079. endif
  1080. if has('spell')
  1081. let values += [
  1082. \['spell', 1, 0],
  1083. \]
  1084. endif
  1085. if has('syntax')
  1086. let values += [
  1087. \['cursorcolumn', 1, 0],
  1088. \['cursorline', 1, 0],
  1089. \['cursorlineopt', '"screenline"', '"' .. &cursorlineopt .. '"'],
  1090. \['colorcolumn', '"+1"', '"' .. &colorcolumn .. '"'],
  1091. \]
  1092. endif
  1093. if has('diff')
  1094. let values += [
  1095. \['diff', 1, 0],
  1096. \]
  1097. endif
  1098. if has('conceal')
  1099. let values += [
  1100. \['concealcursor', '"nv"', '"' .. &concealcursor .. '"'],
  1101. \['conceallevel', '3', &conceallevel],
  1102. \]
  1103. endif
  1104. if has('terminal')
  1105. let values += [
  1106. \['termwinkey', '"<C-X>"', '"' .. &termwinkey .. '"'],
  1107. \['termwinsize', '"10x20"', '"' .. &termwinsize .. '"'],
  1108. \]
  1109. endif
  1110. if has('folding')
  1111. let values += [
  1112. \['foldcolumn', '"5"', &foldcolumn],
  1113. \['foldenable', 0, 1],
  1114. \['foldexpr', '"2 + 3"', '"' .. &foldexpr .. '"'],
  1115. \['foldignore', '"+="', '"' .. &foldignore .. '"'],
  1116. \['foldlevel', 4, &foldlevel],
  1117. \['foldmarker', '">>,<<"', '"' .. &foldmarker .. '"'],
  1118. \['foldmethod', '"marker"', '"' .. &foldmethod .. '"'],
  1119. \['foldminlines', 3, &foldminlines],
  1120. \['foldnestmax', 17, &foldnestmax],
  1121. \['foldtext', '"closed"', '"' .. &foldtext .. '"'],
  1122. \]
  1123. endif
  1124. if has('signs')
  1125. let values += [
  1126. \['signcolumn', '"number"', '"' .. &signcolumn .. '"'],
  1127. \]
  1128. endif
  1129. " set options to non-default value
  1130. for item in values
  1131. exe $"let &{item[0]} = {item[1]}"
  1132. endfor
  1133. " check values are set in new window
  1134. split
  1135. for item in values
  1136. exe $'call assert_equal({item[1]}, &{item[0]}, "{item[0]}")'
  1137. endfor
  1138. " restore
  1139. close
  1140. for item in values
  1141. exe $"let &{item[0]} = {item[1]}"
  1142. endfor
  1143. endfunc
  1144. func Test_shortmess_F()
  1145. new
  1146. call assert_match('\[No Name\]', execute('file'))
  1147. set shortmess+=F
  1148. call assert_match('\[No Name\]', execute('file'))
  1149. call assert_match('^\s*$', execute('file foo'))
  1150. call assert_match('foo', execute('file'))
  1151. set shortmess-=F
  1152. call assert_match('bar', execute('file bar'))
  1153. call assert_match('bar', execute('file'))
  1154. set shortmess&
  1155. bwipe
  1156. endfunc
  1157. func Test_shortmess_F2()
  1158. e file1
  1159. e file2
  1160. call assert_match('file1', execute('bn', ''))
  1161. call assert_match('file2', execute('bn', ''))
  1162. set shortmess+=F
  1163. call assert_true(empty(execute('bn', '')))
  1164. " call assert_false(test_getvalue('need_fileinfo'))
  1165. call assert_true(empty(execute('bn', '')))
  1166. " call assert_false(test_getvalue('need_fileinfo'))
  1167. set hidden
  1168. call assert_true(empty(execute('bn', '')))
  1169. " call assert_false(test_getvalue('need_fileinfo'))
  1170. call assert_true(empty(execute('bn', '')))
  1171. " call assert_false(test_getvalue('need_fileinfo'))
  1172. set nohidden
  1173. call assert_true(empty(execute('bn', '')))
  1174. " call assert_false(test_getvalue('need_fileinfo'))
  1175. call assert_true(empty(execute('bn', '')))
  1176. " call assert_false(test_getvalue('need_fileinfo'))
  1177. set shortmess-=F " Accommodate Nvim default.
  1178. call assert_match('file1', execute('bn', ''))
  1179. call assert_match('file2', execute('bn', ''))
  1180. bwipe
  1181. bwipe
  1182. " call assert_fails('call test_getvalue("abc")', 'E475:')
  1183. endfunc
  1184. func Test_shortmess_F3()
  1185. call writefile(['foo'], 'X_dummy', 'D')
  1186. set hidden
  1187. set autoread
  1188. e X_dummy
  1189. e Xotherfile
  1190. call assert_equal(['foo'], getbufline('X_dummy', 1, '$'))
  1191. set shortmess+=F
  1192. echo ''
  1193. if has('nanotime')
  1194. sleep 10m
  1195. else
  1196. sleep 2
  1197. endif
  1198. call writefile(['bar'], 'X_dummy')
  1199. bprev
  1200. call assert_equal('', Screenline(&lines))
  1201. call assert_equal(['bar'], getbufline('X_dummy', 1, '$'))
  1202. if has('nanotime')
  1203. sleep 10m
  1204. else
  1205. sleep 2
  1206. endif
  1207. call writefile(['baz'], 'X_dummy')
  1208. checktime
  1209. call assert_equal('', Screenline(&lines))
  1210. call assert_equal(['baz'], getbufline('X_dummy', 1, '$'))
  1211. set shortmess&
  1212. set autoread&
  1213. set hidden&
  1214. bwipe X_dummy
  1215. bwipe Xotherfile
  1216. endfunc
  1217. func Test_local_scrolloff()
  1218. set so=5
  1219. set siso=7
  1220. split
  1221. call assert_equal(5, &so)
  1222. setlocal so=3
  1223. call assert_equal(3, &so)
  1224. wincmd w
  1225. call assert_equal(5, &so)
  1226. wincmd w
  1227. call assert_equal(3, &so)
  1228. "setlocal so<
  1229. set so<
  1230. call assert_equal(5, &so)
  1231. setglob so=8
  1232. call assert_equal(8, &so)
  1233. call assert_equal(-1, &l:so)
  1234. setlocal so=0
  1235. call assert_equal(0, &so)
  1236. setlocal so=-1
  1237. call assert_equal(8, &so)
  1238. call assert_equal(7, &siso)
  1239. setlocal siso=3
  1240. call assert_equal(3, &siso)
  1241. wincmd w
  1242. call assert_equal(7, &siso)
  1243. wincmd w
  1244. call assert_equal(3, &siso)
  1245. "setlocal siso<
  1246. set siso<
  1247. call assert_equal(7, &siso)
  1248. setglob siso=4
  1249. call assert_equal(4, &siso)
  1250. call assert_equal(-1, &l:siso)
  1251. setlocal siso=0
  1252. call assert_equal(0, &siso)
  1253. setlocal siso=-1
  1254. call assert_equal(4, &siso)
  1255. close
  1256. set so&
  1257. set siso&
  1258. endfunc
  1259. func Test_writedelay()
  1260. CheckFunction reltimefloat
  1261. new
  1262. call setline(1, 'empty')
  1263. " Nvim: 'writedelay' is applied per screen line.
  1264. " Create 7 vertical splits first.
  1265. vs | vs | vs | vs | vs | vs
  1266. redraw
  1267. set writedelay=10
  1268. let start = reltime()
  1269. " call setline(1, repeat('x', 70))
  1270. " Nvim: enable 'writedelay' per screen line.
  1271. " In each of the 7 vertical splits, 10 screen lines need to be drawn.
  1272. set redrawdebug+=line
  1273. call setline(1, repeat(['x'], 10))
  1274. redraw
  1275. let elapsed = reltimefloat(reltime(start))
  1276. set writedelay=0
  1277. " With 'writedelay' set should take at least 30 * 10 msec
  1278. call assert_inrange(30 * 0.01, 999.0, elapsed)
  1279. bwipe!
  1280. endfunc
  1281. func Test_visualbell()
  1282. set belloff=
  1283. set visualbell
  1284. call assert_beeps('normal 0h')
  1285. set novisualbell
  1286. set belloff=all
  1287. endfunc
  1288. " Test for the 'write' option
  1289. func Test_write()
  1290. new
  1291. call setline(1, ['L1'])
  1292. set nowrite
  1293. call assert_fails('write Xwrfile', 'E142:')
  1294. set write
  1295. " close swapfile
  1296. bw!
  1297. endfunc
  1298. " Test for 'buftype' option
  1299. func Test_buftype()
  1300. new
  1301. call setline(1, ['L1'])
  1302. set buftype=nowrite
  1303. call assert_fails('write', 'E382:')
  1304. " for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'terminal', 'prompt', 'popup']
  1305. for val in ['', 'nofile', 'nowrite', 'acwrite', 'quickfix', 'help', 'prompt']
  1306. exe 'set buftype=' .. val
  1307. call writefile(['something'], 'XBuftype')
  1308. call assert_fails('write XBuftype', 'E13:', 'with buftype=' .. val)
  1309. endfor
  1310. call delete('XBuftype')
  1311. bwipe!
  1312. endfunc
  1313. " Test for the 'rightleftcmd' option
  1314. func Test_rightleftcmd()
  1315. CheckFeature rightleft
  1316. set rightleft
  1317. let g:l = []
  1318. func AddPos()
  1319. call add(g:l, screencol())
  1320. return ''
  1321. endfunc
  1322. cmap <expr> <F2> AddPos()
  1323. set rightleftcmd=
  1324. call feedkeys("/\<F2>abc\<Right>\<F2>\<Left>\<Left>\<F2>" ..
  1325. \ "\<Right>\<F2>\<Esc>", 'xt')
  1326. call assert_equal([2, 5, 3, 4], g:l)
  1327. let g:l = []
  1328. set rightleftcmd=search
  1329. call feedkeys("/\<F2>abc\<Left>\<F2>\<Right>\<Right>\<F2>" ..
  1330. \ "\<Left>\<F2>\<Esc>", 'xt')
  1331. call assert_equal([&co - 1, &co - 4, &co - 2, &co - 3], g:l)
  1332. cunmap <F2>
  1333. unlet g:l
  1334. set rightleftcmd&
  1335. set rightleft&
  1336. endfunc
  1337. " Test for the 'debug' option
  1338. func Test_debug_option()
  1339. " redraw to avoid matching previous messages
  1340. redraw
  1341. set debug=beep
  1342. exe "normal \<C-c>"
  1343. call assert_equal('Beep!', Screenline(&lines))
  1344. call assert_equal('line 4:', Screenline(&lines - 1))
  1345. " also check a line above, with a certain window width the colon is there
  1346. call assert_match('Test_debug_option:$',
  1347. \ Screenline(&lines - 3) .. Screenline(&lines - 2))
  1348. set debug&
  1349. endfunc
  1350. " Test for the default CDPATH option
  1351. func Test_opt_default_cdpath()
  1352. let after =<< trim [CODE]
  1353. call assert_equal(',/path/to/dir1,/path/to/dir2', &cdpath)
  1354. call writefile(v:errors, 'Xtestout')
  1355. qall
  1356. [CODE]
  1357. if has('unix')
  1358. let $CDPATH='/path/to/dir1:/path/to/dir2'
  1359. else
  1360. let $CDPATH='/path/to/dir1;/path/to/dir2'
  1361. endif
  1362. if RunVim([], after, '')
  1363. call assert_equal([], readfile('Xtestout'))
  1364. call delete('Xtestout')
  1365. endif
  1366. endfunc
  1367. " Test for setting keycodes using set
  1368. func Test_opt_set_keycode()
  1369. " call assert_fails('set <t_k1=l', 'E474:')
  1370. " call assert_fails('set <Home=l', 'E474:')
  1371. call assert_fails('set <t_k1=l', 'E518:')
  1372. call assert_fails('set <Home=l', 'E518:')
  1373. set <t_k9>=abcd
  1374. " call assert_equal('abcd', &t_k9)
  1375. set <t_k9>&
  1376. set <F9>=xyz
  1377. " call assert_equal('xyz', &t_k9)
  1378. set <t_k9>&
  1379. endfunc
  1380. " Test for changing options in a sandbox
  1381. func Test_opt_sandbox()
  1382. for opt in ['backupdir', 'cdpath', 'exrc', 'findfunc']
  1383. call assert_fails('sandbox set ' .. opt .. '?', 'E48:')
  1384. call assert_fails('sandbox let &' .. opt .. ' = 1', 'E48:')
  1385. endfor
  1386. call assert_fails('sandbox let &modelineexpr = 1', 'E48:')
  1387. endfunc
  1388. " Test for setting string global-local option value
  1389. func Test_set_string_global_local_option()
  1390. setglobal equalprg=gprg
  1391. setlocal equalprg=lprg
  1392. call assert_equal('gprg', &g:equalprg)
  1393. call assert_equal('lprg', &l:equalprg)
  1394. call assert_equal('lprg', &equalprg)
  1395. " :set {option}< removes the local value, so that the global value will be used.
  1396. set equalprg<
  1397. call assert_equal('', &l:equalprg)
  1398. call assert_equal('gprg', &equalprg)
  1399. " :setlocal {option}< set the effective value of {option} to its global value.
  1400. setglobal equalprg=gnewprg
  1401. setlocal equalprg=lnewprg
  1402. setlocal equalprg<
  1403. call assert_equal('gnewprg', &l:equalprg)
  1404. call assert_equal('gnewprg', &equalprg)
  1405. set equalprg&
  1406. endfunc
  1407. " Test for setting number global-local option value
  1408. func Test_set_number_global_local_option()
  1409. setglobal scrolloff=10
  1410. setlocal scrolloff=12
  1411. call assert_equal(10, &g:scrolloff)
  1412. call assert_equal(12, &l:scrolloff)
  1413. call assert_equal(12, &scrolloff)
  1414. " :setlocal {option}< set the effective value of {option} to its global value.
  1415. "set scrolloff<
  1416. setlocal scrolloff<
  1417. call assert_equal(10, &l:scrolloff)
  1418. call assert_equal(10, &scrolloff)
  1419. " :set {option}< removes the local value, so that the global value will be used.
  1420. setglobal scrolloff=15
  1421. setlocal scrolloff=18
  1422. "setlocal scrolloff<
  1423. set scrolloff<
  1424. call assert_equal(-1, &l:scrolloff)
  1425. call assert_equal(15, &scrolloff)
  1426. set scrolloff&
  1427. endfunc
  1428. " Test for setting boolean global-local option value
  1429. func Test_set_boolean_global_local_option()
  1430. setglobal autoread
  1431. setlocal noautoread
  1432. call assert_equal(1, &g:autoread)
  1433. call assert_equal(0, &l:autoread)
  1434. call assert_equal(0, &autoread)
  1435. " :setlocal {option}< set the effective value of {option} to its global value.
  1436. "set autoread<
  1437. setlocal autoread<
  1438. call assert_equal(1, &l:autoread)
  1439. call assert_equal(1, &autoread)
  1440. " :set {option}< removes the local value, so that the global value will be used.
  1441. setglobal noautoread
  1442. setlocal autoread
  1443. "setlocal autoread<
  1444. set autoread<
  1445. call assert_equal(-1, &l:autoread)
  1446. call assert_equal(0, &autoread)
  1447. set autoread&
  1448. endfunc
  1449. func Test_set_in_sandbox()
  1450. " Some boolean options cannot be set in sandbox, some can.
  1451. call assert_fails('sandbox set modelineexpr', 'E48:')
  1452. sandbox set number
  1453. call assert_true(&number)
  1454. set number&
  1455. " Some boolean options cannot be set in sandbox, some can.
  1456. if has('python') || has('python3')
  1457. call assert_fails('sandbox set pyxversion=3', 'E48:')
  1458. endif
  1459. sandbox set tabstop=4
  1460. call assert_equal(4, &tabstop)
  1461. set tabstop&
  1462. " Some string options cannot be set in sandbox, some can.
  1463. call assert_fails('sandbox set backupdir=/tmp', 'E48:')
  1464. sandbox set filetype=perl
  1465. call assert_equal('perl', &filetype)
  1466. set filetype&
  1467. endfunc
  1468. " Test for setting string option value
  1469. func Test_set_string_option()
  1470. " :set {option}=
  1471. set makeprg=
  1472. call assert_equal('', &mp)
  1473. set makeprg=abc
  1474. call assert_equal('abc', &mp)
  1475. " :set {option}:
  1476. set makeprg:
  1477. call assert_equal('', &mp)
  1478. set makeprg:abc
  1479. call assert_equal('abc', &mp)
  1480. " Let string
  1481. let &makeprg = ''
  1482. call assert_equal('', &mp)
  1483. let &makeprg = 'abc'
  1484. call assert_equal('abc', &mp)
  1485. " Let number converts to string
  1486. let &makeprg = 42
  1487. call assert_equal('42', &mp)
  1488. " Appending
  1489. set makeprg=abc
  1490. set makeprg+=def
  1491. call assert_equal('abcdef', &mp)
  1492. set makeprg+=def
  1493. call assert_equal('abcdefdef', &mp, ':set+= appends a value even if it already contained')
  1494. let &makeprg .= 'gh'
  1495. call assert_equal('abcdefdefgh', &mp)
  1496. let &makeprg ..= 'ij'
  1497. call assert_equal('abcdefdefghij', &mp)
  1498. " Removing
  1499. set makeprg=abcdefghi
  1500. set makeprg-=def
  1501. call assert_equal('abcghi', &mp)
  1502. set makeprg-=def
  1503. call assert_equal('abcghi', &mp, ':set-= does not remove a value if it is not contained')
  1504. " Prepending
  1505. set makeprg=abc
  1506. set makeprg^=def
  1507. call assert_equal('defabc', &mp)
  1508. set makeprg^=def
  1509. call assert_equal('defdefabc', &mp, ':set+= prepends a value even if it already contained')
  1510. set makeprg&
  1511. endfunc
  1512. " Test for setting string comma-separated list option value
  1513. func Test_set_string_comma_list_option()
  1514. " :set {option}=
  1515. set wildignore=
  1516. call assert_equal('', &wildignore)
  1517. set wildignore=*.png
  1518. call assert_equal('*.png', &wildignore)
  1519. " :set {option}:
  1520. set wildignore:
  1521. call assert_equal('', &wildignore)
  1522. set wildignore:*.png
  1523. call assert_equal('*.png', &wildignore)
  1524. " Let string
  1525. let &wildignore = ''
  1526. call assert_equal('', &wildignore)
  1527. let &wildignore = '*.png'
  1528. call assert_equal('*.png', &wildignore)
  1529. " Let number converts to string
  1530. let &wildignore = 42
  1531. call assert_equal('42', &wildignore)
  1532. " Appending
  1533. set wildignore=*.png
  1534. set wildignore+=*.jpg
  1535. call assert_equal('*.png,*.jpg', &wildignore, ':set+= prepends a comma to append a value')
  1536. set wildignore+=*.jpg
  1537. call assert_equal('*.png,*.jpg', &wildignore, ':set+= does not append a value if it already contained')
  1538. set wildignore+=jpg
  1539. call assert_equal('*.png,*.jpg,jpg', &wildignore, ':set+= prepends a comma to append a value if it is not exactly match to item')
  1540. let &wildignore .= 'foo'
  1541. call assert_equal('*.png,*.jpg,jpgfoo', &wildignore, ':let-& .= appends a value without a comma')
  1542. let &wildignore ..= 'bar'
  1543. call assert_equal('*.png,*.jpg,jpgfoobar', &wildignore, ':let-& ..= appends a value without a comma')
  1544. " Removing
  1545. set wildignore=*.png,*.jpg,*.obj
  1546. set wildignore-=*.jpg
  1547. call assert_equal('*.png,*.obj', &wildignore)
  1548. set wildignore-=*.jpg
  1549. call assert_equal('*.png,*.obj', &wildignore, ':set-= does not remove a value if it is not contained')
  1550. set wildignore-=jpg
  1551. call assert_equal('*.png,*.obj', &wildignore, ':set-= does not remove a value if it is not exactly match to item')
  1552. " Prepending
  1553. set wildignore=*.png
  1554. set wildignore^=*.jpg
  1555. call assert_equal('*.jpg,*.png', &wildignore)
  1556. set wildignore^=*.jpg
  1557. call assert_equal('*.jpg,*.png', &wildignore, ':set+= does not prepend a value if it already contained')
  1558. set wildignore^=jpg
  1559. call assert_equal('jpg,*.jpg,*.png', &wildignore, ':set+= prepend a value if it is not exactly match to item')
  1560. set wildignore&
  1561. endfunc
  1562. " Test for setting string flags option value
  1563. func Test_set_string_flags_option()
  1564. " :set {option}=
  1565. set formatoptions=
  1566. call assert_equal('', &fo)
  1567. set formatoptions=abc
  1568. call assert_equal('abc', &fo)
  1569. " :set {option}:
  1570. set formatoptions:
  1571. call assert_equal('', &fo)
  1572. set formatoptions:abc
  1573. call assert_equal('abc', &fo)
  1574. " Let string
  1575. let &formatoptions = ''
  1576. call assert_equal('', &fo)
  1577. let &formatoptions = 'abc'
  1578. call assert_equal('abc', &fo)
  1579. " Let number converts to string
  1580. let &formatoptions = 12
  1581. call assert_equal('12', &fo)
  1582. " Appending
  1583. set formatoptions=abc
  1584. set formatoptions+=pqr
  1585. call assert_equal('abcpqr', &fo)
  1586. set formatoptions+=pqr
  1587. call assert_equal('abcpqr', &fo, ':set+= does not append a value if it already contained')
  1588. let &formatoptions .= 'r'
  1589. call assert_equal('abcpqrr', &fo, ':let-& .= appends a value even if it already contained')
  1590. let &formatoptions ..= 'r'
  1591. call assert_equal('abcpqrrr', &fo, ':let-& ..= appends a value even if it already contained')
  1592. " Removing
  1593. set formatoptions=abcpqr
  1594. set formatoptions-=cp
  1595. call assert_equal('abqr', &fo)
  1596. set formatoptions-=cp
  1597. call assert_equal('abqr', &fo, ':set-= does not remove a value if it is not contained')
  1598. set formatoptions-=ar
  1599. call assert_equal('abqr', &fo, ':set-= does not remove a value if it is not exactly match')
  1600. " Prepending
  1601. set formatoptions=abc
  1602. set formatoptions^=pqr
  1603. call assert_equal('pqrabc', &fo)
  1604. set formatoptions^=qr
  1605. call assert_equal('pqrabc', &fo, ':set+= does not prepend a value if it already contained')
  1606. set formatoptions&
  1607. endfunc
  1608. " Test for setting number option value
  1609. func Test_set_number_option()
  1610. " :set {option}=
  1611. set scrolljump=5
  1612. call assert_equal(5, &sj)
  1613. set scrolljump=-3
  1614. call assert_equal(-3, &sj)
  1615. " :set {option}:
  1616. set scrolljump:7
  1617. call assert_equal(7, &sj)
  1618. set scrolljump:-5
  1619. call assert_equal(-5, &sj)
  1620. " Set hex
  1621. set scrolljump=0x10
  1622. call assert_equal(16, &sj)
  1623. set scrolljump=-0x10
  1624. call assert_equal(-16, &sj)
  1625. set scrolljump=0X12
  1626. call assert_equal(18, &sj)
  1627. set scrolljump=-0X12
  1628. call assert_equal(-18, &sj)
  1629. " Set octal
  1630. set scrolljump=010
  1631. call assert_equal(8, &sj)
  1632. set scrolljump=-010
  1633. call assert_equal(-8, &sj)
  1634. set scrolljump=0o12
  1635. call assert_equal(10, &sj)
  1636. set scrolljump=-0o12
  1637. call assert_equal(-10, &sj)
  1638. set scrolljump=0O15
  1639. call assert_equal(13, &sj)
  1640. set scrolljump=-0O15
  1641. call assert_equal(-13, &sj)
  1642. " Let number
  1643. let &scrolljump = 4
  1644. call assert_equal(4, &sj)
  1645. let &scrolljump = -6
  1646. call assert_equal(-6, &sj)
  1647. " Let numeric string converts to number
  1648. let &scrolljump = '7'
  1649. call assert_equal(7, &sj)
  1650. let &scrolljump = '-9'
  1651. call assert_equal(-9, &sj)
  1652. " Incrementing
  1653. set shiftwidth=4
  1654. set sw+=2
  1655. call assert_equal(6, &sw)
  1656. let &shiftwidth += 2
  1657. call assert_equal(8, &sw)
  1658. " Decrementing
  1659. set shiftwidth=6
  1660. set sw-=2
  1661. call assert_equal(4, &sw)
  1662. let &shiftwidth -= 2
  1663. call assert_equal(2, &sw)
  1664. " Multiplying
  1665. set shiftwidth=4
  1666. set sw^=2
  1667. call assert_equal(8, &sw)
  1668. let &shiftwidth *= 2
  1669. call assert_equal(16, &sw)
  1670. set scrolljump&
  1671. set shiftwidth&
  1672. endfunc
  1673. " Test for setting boolean option value
  1674. func Test_set_boolean_option()
  1675. set number&
  1676. " :set {option}
  1677. set number
  1678. call assert_equal(1, &nu)
  1679. " :set no{option}
  1680. set nonu
  1681. call assert_equal(0, &nu)
  1682. " :set {option}!
  1683. set number!
  1684. call assert_equal(1, &nu)
  1685. set number!
  1686. call assert_equal(0, &nu)
  1687. " :set inv{option}
  1688. set invnumber
  1689. call assert_equal(1, &nu)
  1690. set invnumber
  1691. call assert_equal(0, &nu)
  1692. " Let number
  1693. let &number = 1
  1694. call assert_equal(1, &nu)
  1695. let &number = 0
  1696. call assert_equal(0, &nu)
  1697. " Let numeric string converts to number
  1698. let &number = '1'
  1699. call assert_equal(1, &nu)
  1700. let &number = '0'
  1701. call assert_equal(0, &nu)
  1702. " Let v:true and v:false
  1703. let &nu = v:true
  1704. call assert_equal(1, &nu)
  1705. let &nu = v:false
  1706. call assert_equal(0, &nu)
  1707. set number&
  1708. endfunc
  1709. " Test for setting string option errors
  1710. func Test_set_string_option_errors()
  1711. " :set no{option}
  1712. call assert_fails('set nomakeprg', 'E474:')
  1713. call assert_fails('setlocal nomakeprg', 'E474:')
  1714. call assert_fails('setglobal nomakeprg', 'E474:')
  1715. " :set inv{option}
  1716. call assert_fails('set invmakeprg', 'E474:')
  1717. call assert_fails('setlocal invmakeprg', 'E474:')
  1718. call assert_fails('setglobal invmakeprg', 'E474:')
  1719. " :set {option}!
  1720. call assert_fails('set makeprg!', 'E488:')
  1721. call assert_fails('setlocal makeprg!', 'E488:')
  1722. call assert_fails('setglobal makeprg!', 'E488:')
  1723. " Invalid trailing chars
  1724. call assert_fails('set makeprg??', 'E488:')
  1725. call assert_fails('setlocal makeprg??', 'E488:')
  1726. call assert_fails('setglobal makeprg??', 'E488:')
  1727. call assert_fails('set makeprg&&', 'E488:')
  1728. call assert_fails('setlocal makeprg&&', 'E488:')
  1729. call assert_fails('setglobal makeprg&&', 'E488:')
  1730. call assert_fails('set makeprg<<', 'E488:')
  1731. call assert_fails('setlocal makeprg<<', 'E488:')
  1732. call assert_fails('setglobal makeprg<<', 'E488:')
  1733. call assert_fails('set makeprg@', 'E488:')
  1734. call assert_fails('setlocal makeprg@', 'E488:')
  1735. call assert_fails('setglobal makeprg@', 'E488:')
  1736. " Invalid type
  1737. call assert_fails("let &makeprg = ['xxx']", 'E730:')
  1738. endfunc
  1739. " Test for setting number option errors
  1740. func Test_set_number_option_errors()
  1741. " :set no{option}
  1742. call assert_fails('set notabstop', 'E474:')
  1743. call assert_fails('setlocal notabstop', 'E474:')
  1744. call assert_fails('setglobal notabstop', 'E474:')
  1745. " :set inv{option}
  1746. call assert_fails('set invtabstop', 'E474:')
  1747. call assert_fails('setlocal invtabstop', 'E474:')
  1748. call assert_fails('setglobal invtabstop', 'E474:')
  1749. " :set {option}!
  1750. call assert_fails('set tabstop!', 'E488:')
  1751. call assert_fails('setlocal tabstop!', 'E488:')
  1752. call assert_fails('setglobal tabstop!', 'E488:')
  1753. " Invalid trailing chars
  1754. call assert_fails('set tabstop??', 'E488:')
  1755. call assert_fails('setlocal tabstop??', 'E488:')
  1756. call assert_fails('setglobal tabstop??', 'E488:')
  1757. call assert_fails('set tabstop&&', 'E488:')
  1758. call assert_fails('setlocal tabstop&&', 'E488:')
  1759. call assert_fails('setglobal tabstop&&', 'E488:')
  1760. call assert_fails('set tabstop<<', 'E488:')
  1761. call assert_fails('setlocal tabstop<<', 'E488:')
  1762. call assert_fails('setglobal tabstop<<', 'E488:')
  1763. call assert_fails('set tabstop@', 'E488:')
  1764. call assert_fails('setlocal tabstop@', 'E488:')
  1765. call assert_fails('setglobal tabstop@', 'E488:')
  1766. " Not a number
  1767. call assert_fails('set tabstop=', 'E521:')
  1768. call assert_fails('setlocal tabstop=', 'E521:')
  1769. call assert_fails('setglobal tabstop=', 'E521:')
  1770. call assert_fails('set tabstop=x', 'E521:')
  1771. call assert_fails('setlocal tabstop=x', 'E521:')
  1772. call assert_fails('setglobal tabstop=x', 'E521:')
  1773. call assert_fails('set tabstop=1x', 'E521:')
  1774. call assert_fails('setlocal tabstop=1x', 'E521:')
  1775. call assert_fails('setglobal tabstop=1x', 'E521:')
  1776. call assert_fails('set tabstop=-x', 'E521:')
  1777. call assert_fails('setlocal tabstop=-x', 'E521:')
  1778. call assert_fails('setglobal tabstop=-x', 'E521:')
  1779. call assert_fails('set tabstop=0x', 'E521:')
  1780. call assert_fails('setlocal tabstop=0x', 'E521:')
  1781. call assert_fails('setglobal tabstop=0x', 'E521:')
  1782. call assert_fails('set tabstop=0o', 'E521:')
  1783. call assert_fails('setlocal tabstop=0o', 'E521:')
  1784. call assert_fails('setglobal tabstop=0o', 'E521:')
  1785. call assert_fails("let &tabstop = 'x'", 'E521:')
  1786. call assert_fails("let &g:tabstop = 'x'", 'E521:')
  1787. call assert_fails("let &l:tabstop = 'x'", 'E521:')
  1788. " Invalid type
  1789. call assert_fails("let &tabstop = 'xxx'", 'E521:')
  1790. endfunc
  1791. " Test for setting boolean option errors
  1792. func Test_set_boolean_option_errors()
  1793. " :set {option}=
  1794. call assert_fails('set number=', 'E474:')
  1795. call assert_fails('setlocal number=', 'E474:')
  1796. call assert_fails('setglobal number=', 'E474:')
  1797. call assert_fails('set number=1', 'E474:')
  1798. call assert_fails('setlocal number=1', 'E474:')
  1799. call assert_fails('setglobal number=1', 'E474:')
  1800. " :set {option}:
  1801. call assert_fails('set number:', 'E474:')
  1802. call assert_fails('setlocal number:', 'E474:')
  1803. call assert_fails('setglobal number:', 'E474:')
  1804. call assert_fails('set number:1', 'E474:')
  1805. call assert_fails('setlocal number:1', 'E474:')
  1806. call assert_fails('setglobal number:1', 'E474:')
  1807. " :set {option}+=
  1808. call assert_fails('set number+=1', 'E474:')
  1809. call assert_fails('setlocal number+=1', 'E474:')
  1810. call assert_fails('setglobal number+=1', 'E474:')
  1811. " :set {option}^=
  1812. call assert_fails('set number^=1', 'E474:')
  1813. call assert_fails('setlocal number^=1', 'E474:')
  1814. call assert_fails('setglobal number^=1', 'E474:')
  1815. " :set {option}-=
  1816. call assert_fails('set number-=1', 'E474:')
  1817. call assert_fails('setlocal number-=1', 'E474:')
  1818. call assert_fails('setglobal number-=1', 'E474:')
  1819. " Invalid trailing chars
  1820. call assert_fails('set number!!', 'E488:')
  1821. call assert_fails('setlocal number!!', 'E488:')
  1822. call assert_fails('setglobal number!!', 'E488:')
  1823. call assert_fails('set number??', 'E488:')
  1824. call assert_fails('setlocal number??', 'E488:')
  1825. call assert_fails('setglobal number??', 'E488:')
  1826. call assert_fails('set number&&', 'E488:')
  1827. call assert_fails('setlocal number&&', 'E488:')
  1828. call assert_fails('setglobal number&&', 'E488:')
  1829. call assert_fails('set number<<', 'E488:')
  1830. call assert_fails('setlocal number<<', 'E488:')
  1831. call assert_fails('setglobal number<<', 'E488:')
  1832. call assert_fails('set number@', 'E488:')
  1833. call assert_fails('setlocal number@', 'E488:')
  1834. call assert_fails('setglobal number@', 'E488:')
  1835. " Invalid type
  1836. call assert_fails("let &number = 'xxx'", 'E521:')
  1837. endfunc
  1838. " Test for the 'window' option
  1839. func Test_window_opt()
  1840. " Needs only one open widow
  1841. %bw!
  1842. call setline(1, range(1, 8))
  1843. set window=5
  1844. exe "normal \<C-F>"
  1845. call assert_equal(4, line('w0'))
  1846. exe "normal \<C-F>"
  1847. call assert_equal(7, line('w0'))
  1848. exe "normal \<C-F>"
  1849. call assert_equal(8, line('w0'))
  1850. exe "normal \<C-B>"
  1851. call assert_equal(5, line('w0'))
  1852. exe "normal \<C-B>"
  1853. call assert_equal(2, line('w0'))
  1854. exe "normal \<C-B>"
  1855. call assert_equal(1, line('w0'))
  1856. set window=1
  1857. exe "normal gg\<C-F>"
  1858. call assert_equal(2, line('w0'))
  1859. exe "normal \<C-F>"
  1860. call assert_equal(3, line('w0'))
  1861. exe "normal \<C-B>"
  1862. call assert_equal(2, line('w0'))
  1863. exe "normal \<C-B>"
  1864. call assert_equal(1, line('w0'))
  1865. enew!
  1866. set window&
  1867. endfunc
  1868. " Test for the 'winminheight' option
  1869. func Test_opt_winminheight()
  1870. only!
  1871. let &winheight = &lines + 4
  1872. call assert_fails('let &winminheight = &lines + 2', 'E36:')
  1873. call assert_true(&winminheight <= &lines)
  1874. set winminheight&
  1875. set winheight&
  1876. endfunc
  1877. func Test_opt_winminheight_term()
  1878. " See test/functional/legacy/options_spec.lua
  1879. CheckRunVimInTerminal
  1880. " The tabline should be taken into account.
  1881. let lines =<< trim END
  1882. set wmh=0 stal=2
  1883. below sp | wincmd _
  1884. below sp | wincmd _
  1885. below sp | wincmd _
  1886. below sp
  1887. END
  1888. call writefile(lines, 'Xwinminheight')
  1889. let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
  1890. call term_sendkeys(buf, ":set wmh=1\n")
  1891. call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
  1892. call StopVimInTerminal(buf)
  1893. call delete('Xwinminheight')
  1894. endfunc
  1895. func Test_opt_winminheight_term_tabs()
  1896. " See test/functional/legacy/options_spec.lua
  1897. CheckRunVimInTerminal
  1898. " The tabline should be taken into account.
  1899. let lines =<< trim END
  1900. set wmh=0 stal=2
  1901. split
  1902. split
  1903. split
  1904. split
  1905. tabnew
  1906. END
  1907. call writefile(lines, 'Xwinminheight')
  1908. let buf = RunVimInTerminal('-S Xwinminheight', #{rows: 11})
  1909. call term_sendkeys(buf, ":set wmh=1\n")
  1910. call WaitForAssert({-> assert_match('E36: Not enough room', term_getline(buf, 11))})
  1911. call StopVimInTerminal(buf)
  1912. call delete('Xwinminheight')
  1913. endfunc
  1914. " Test for the 'winminwidth' option
  1915. func Test_opt_winminwidth()
  1916. only!
  1917. let &winwidth = &columns + 4
  1918. call assert_fails('let &winminwidth = &columns + 2', 'E36:')
  1919. call assert_true(&winminwidth <= &columns)
  1920. set winminwidth&
  1921. set winwidth&
  1922. endfunc
  1923. " Test for setting option value containing spaces with isfname+=32
  1924. func Test_isfname_with_options()
  1925. set isfname+=32
  1926. setlocal keywordprg=:term\ help.exe
  1927. call assert_equal(':term help.exe', &keywordprg)
  1928. set isfname&
  1929. setlocal keywordprg&
  1930. endfunc
  1931. " Test that resetting laststatus does change scroll option
  1932. func Test_opt_reset_scroll()
  1933. " See test/functional/legacy/options_spec.lua
  1934. CheckRunVimInTerminal
  1935. let vimrc =<< trim [CODE]
  1936. set scroll=2
  1937. set laststatus=2
  1938. [CODE]
  1939. call writefile(vimrc, 'Xscroll')
  1940. let buf = RunVimInTerminal('-S Xscroll', {'rows': 16, 'cols': 45})
  1941. call term_sendkeys(buf, ":verbose set scroll?\n")
  1942. call WaitForAssert({-> assert_match('Last set.*window size', term_getline(buf, 15))})
  1943. call assert_match('^\s*scroll=7$', term_getline(buf, 14))
  1944. call StopVimInTerminal(buf)
  1945. " clean up
  1946. call delete('Xscroll')
  1947. endfunc
  1948. " Check that VIM_POSIX env variable influences default value of 'cpo' and 'shm'
  1949. func Test_VIM_POSIX()
  1950. throw 'Skipped: Nvim does not support $VIM_POSIX'
  1951. let saved_VIM_POSIX = getenv("VIM_POSIX")
  1952. call setenv('VIM_POSIX', "1")
  1953. let after =<< trim [CODE]
  1954. call writefile([&cpo, &shm], 'X_VIM_POSIX')
  1955. qall
  1956. [CODE]
  1957. if RunVim([], after, '')
  1958. call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>#{|&/\.;',
  1959. \ 'AS'], readfile('X_VIM_POSIX'))
  1960. endif
  1961. call setenv('VIM_POSIX', v:null)
  1962. let after =<< trim [CODE]
  1963. call writefile([&cpo, &shm], 'X_VIM_POSIX')
  1964. qall
  1965. [CODE]
  1966. if RunVim([], after, '')
  1967. call assert_equal(['aAbBcCdDeEfFgHiIjJkKlLmMnoOpPqrRsStuvwWxXyZ$!%*-+<>;',
  1968. \ 'S'], readfile('X_VIM_POSIX'))
  1969. endif
  1970. call delete('X_VIM_POSIX')
  1971. call setenv('VIM_POSIX', saved_VIM_POSIX)
  1972. endfunc
  1973. " Test for setting an option to a Vi or Vim default
  1974. func Test_opt_default()
  1975. throw 'Skipped: Nvim has different defaults'
  1976. set formatoptions&vi
  1977. call assert_equal('vt', &formatoptions)
  1978. set formatoptions&vim
  1979. call assert_equal('tcq', &formatoptions)
  1980. endfunc
  1981. " Test for the 'cmdheight' option
  1982. func Test_cmdheight()
  1983. %bw!
  1984. let ht = &lines
  1985. set cmdheight=9999
  1986. call assert_equal(1, winheight(0))
  1987. call assert_equal(ht - 1, &cmdheight)
  1988. set cmdheight&
  1989. endfunc
  1990. " To specify a control character as an option value, '^' can be used
  1991. func Test_opt_control_char()
  1992. set wildchar=^v
  1993. call assert_equal("\<C-V>", nr2char(&wildchar))
  1994. set wildcharm=^r
  1995. call assert_equal("\<C-R>", nr2char(&wildcharm))
  1996. " Bug: This doesn't work for the 'cedit' and 'termwinkey' options
  1997. set wildchar& wildcharm&
  1998. endfunc
  1999. " Test for the 'errorbells' option
  2000. func Test_opt_errorbells()
  2001. set errorbells
  2002. call assert_beeps('s/a1b2/x1y2/')
  2003. set noerrorbells
  2004. endfunc
  2005. func Test_opt_scrolljump()
  2006. help
  2007. resize 10
  2008. " Test with positive 'scrolljump'.
  2009. set scrolljump=2
  2010. norm! Lj
  2011. call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
  2012. \ 'topline':3, 'coladd':0, 'skipcol':0, 'curswant':0},
  2013. \ winsaveview())
  2014. " Test with negative 'scrolljump' (percentage of window height).
  2015. set scrolljump=-40
  2016. norm! ggLj
  2017. call assert_equal({'lnum':11, 'leftcol':0, 'col':0, 'topfill':0,
  2018. \ 'topline':5, 'coladd':0, 'skipcol':0, 'curswant':0},
  2019. \ winsaveview())
  2020. set scrolljump&
  2021. bw
  2022. endfunc
  2023. " Test for the 'cdhome' option
  2024. func Test_opt_cdhome()
  2025. if has('unix') || has('vms')
  2026. throw 'Skipped: only works on non-Unix'
  2027. endif
  2028. set cdhome&
  2029. call assert_equal(0, &cdhome)
  2030. set cdhome
  2031. " This paragraph is copied from Test_cd_no_arg().
  2032. let path = getcwd()
  2033. cd
  2034. call assert_equal($HOME, getcwd())
  2035. call assert_notequal(path, getcwd())
  2036. exe 'cd ' .. fnameescape(path)
  2037. call assert_equal(path, getcwd())
  2038. set cdhome&
  2039. endfunc
  2040. func Test_set_completion_fuzzy()
  2041. CheckOption termguicolors
  2042. " Test default option completion
  2043. set wildoptions=
  2044. call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
  2045. call assert_equal('"set termguicolors', @:)
  2046. call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
  2047. call assert_equal('"set notermguicolors', @:)
  2048. " Test fuzzy option completion
  2049. set wildoptions=fuzzy
  2050. call feedkeys(":set termg\<C-A>\<C-B>\"\<CR>", 'tx')
  2051. " Nvim doesn't have 'termencoding'
  2052. " call assert_equal('"set termguicolors termencoding', @:)
  2053. call assert_equal('"set termguicolors', @:)
  2054. call feedkeys(":set notermg\<C-A>\<C-B>\"\<CR>", 'tx')
  2055. call assert_equal('"set notermguicolors', @:)
  2056. set wildoptions=
  2057. endfunc
  2058. func Test_switchbuf_reset()
  2059. set switchbuf=useopen
  2060. sblast
  2061. call assert_equal(1, winnr('$'))
  2062. set all&
  2063. " Nvim has a different default for 'switchbuf'
  2064. " call assert_equal('', &switchbuf)
  2065. call assert_equal('uselast', &switchbuf)
  2066. sblast
  2067. call assert_equal(2, winnr('$'))
  2068. only!
  2069. endfunc
  2070. " :set empty string for global 'keywordprg' falls back to ":help"
  2071. func Test_keywordprg_empty()
  2072. let k = &keywordprg
  2073. set keywordprg=man
  2074. call assert_equal('man', &keywordprg)
  2075. set keywordprg=
  2076. call assert_equal(':help', &keywordprg)
  2077. set keywordprg=man
  2078. call assert_equal('man', &keywordprg)
  2079. call assert_equal("\n keywordprg=:help", execute('set kp= kp?'))
  2080. let &keywordprg = k
  2081. endfunc
  2082. " check that the very first buffer created does not have 'endoffile' set
  2083. func Test_endoffile_default()
  2084. let after =<< trim [CODE]
  2085. call writefile([execute('set eof?')], 'Xtestout')
  2086. qall!
  2087. [CODE]
  2088. if RunVim([], after, '')
  2089. call assert_equal(["\nnoendoffile"], readfile('Xtestout'))
  2090. endif
  2091. call delete('Xtestout')
  2092. endfunc
  2093. " Test for setting the 'lines' and 'columns' options to a minimum value
  2094. func Test_set_min_lines_columns()
  2095. let save_lines = &lines
  2096. let save_columns = &columns
  2097. let after =<< trim END
  2098. set laststatus=1
  2099. set nomore
  2100. let msg = []
  2101. let v:errmsg = ''
  2102. silent! let &columns=0
  2103. call add(msg, v:errmsg)
  2104. silent! set columns=0
  2105. call add(msg, v:errmsg)
  2106. silent! call setbufvar('', '&columns', 0)
  2107. call add(msg, v:errmsg)
  2108. "call writefile(msg, 'XResultsetminlines')
  2109. silent! let &lines=0
  2110. call add(msg, v:errmsg)
  2111. silent! set lines=0
  2112. call add(msg, v:errmsg)
  2113. silent! call setbufvar('', '&lines', 0)
  2114. call add(msg, v:errmsg)
  2115. call writefile(msg, 'XResultsetminlines')
  2116. qall!
  2117. END
  2118. if RunVim([], after, '')
  2119. call assert_equal(['E594: Need at least 12 columns',
  2120. \ 'E594: Need at least 12 columns: columns=0',
  2121. \ 'E594: Need at least 12 columns',
  2122. \ 'E593: Need at least 2 lines',
  2123. \ 'E593: Need at least 2 lines: lines=0',
  2124. \ 'E593: Need at least 2 lines',], readfile('XResultsetminlines'))
  2125. endif
  2126. call delete('XResultsetminlines')
  2127. let &lines = save_lines
  2128. let &columns = save_columns
  2129. endfunc
  2130. " Test for reverting a string option value if the new value is invalid.
  2131. func Test_string_option_revert_on_failure()
  2132. new
  2133. let optlist = [
  2134. \ ['ambiwidth', 'double', 'a123'],
  2135. \ ['background', 'dark', 'a123'],
  2136. \ ['backspace', 'eol', 'a123'],
  2137. \ ['backupcopy', 'no', 'a123'],
  2138. \ ['belloff', 'showmatch', 'a123'],
  2139. \ ['breakindentopt', 'min:10', 'list'],
  2140. \ ['bufhidden', 'wipe', 'a123'],
  2141. \ ['buftype', 'nowrite', 'a123'],
  2142. \ ['casemap', 'keepascii', 'a123'],
  2143. \ ['cedit', "\<C-Y>", 'z'],
  2144. \ ['colorcolumn', '10', 'z'],
  2145. \ ['commentstring', '#%s', 'a123'],
  2146. \ ['complete', '.,t', 'a'],
  2147. \ ['completefunc', 'MyCmplFunc', '1a-'],
  2148. "\ ['completeopt', 'popup', 'a123'],
  2149. \ ['completeopt', 'preview', 'a123'],
  2150. "\ ['completepopup', 'width:20', 'border'],
  2151. \ ['concealcursor', 'v', 'xyz'],
  2152. "\ ['cpoptions', 'HJ', '~'],
  2153. \ ['cpoptions', 'J', '~'],
  2154. "\ ['cryptmethod', 'zip', 'a123'],
  2155. \ ['cursorlineopt', 'screenline', 'a123'],
  2156. \ ['debug', 'throw', 'a123'],
  2157. \ ['diffopt', 'iwhite', 'a123'],
  2158. \ ['display', 'uhex', 'a123'],
  2159. \ ['eadirection', 'hor', 'a123'],
  2160. \ ['encoding', 'utf-8', 'a123'],
  2161. \ ['eventignore', 'TextYankPost', 'a123'],
  2162. \ ['fileencoding', 'utf-8', 'a123,'],
  2163. \ ['fileformat', 'mac', 'a123'],
  2164. \ ['fileformats', 'mac', 'a123'],
  2165. \ ['filetype', 'abc', 'a^b'],
  2166. \ ['fillchars', 'diff:~', 'a123'],
  2167. \ ['foldclose', 'all', 'a123'],
  2168. \ ['foldmarker', '[[[,]]]', '[[['],
  2169. \ ['foldmethod', 'marker', 'a123'],
  2170. \ ['foldopen', 'percent', 'a123'],
  2171. \ ['formatoptions', 'an', '*'],
  2172. \ ['guicursor', 'n-v-c:block-Cursor/lCursor', 'n-v-c'],
  2173. \ ['helplang', 'en', 'a'],
  2174. "\ ['highlight', '!:CursorColumn', '8:'],
  2175. \ ['keymodel', 'stopsel', 'a123'],
  2176. "\ ['keyprotocol', 'kitty:kitty', 'kitty:'],
  2177. \ ['lispoptions', 'expr:1', 'a123'],
  2178. \ ['listchars', 'tab:->', 'tab:'],
  2179. \ ['matchpairs', '<:>', '<:'],
  2180. \ ['mkspellmem', '100000,1000,100', '100000'],
  2181. \ ['mouse', 'nvi', 'z'],
  2182. \ ['mousemodel', 'extend', 'a123'],
  2183. \ ['nrformats', 'alpha', 'a123'],
  2184. \ ['omnifunc', 'MyOmniFunc', '1a-'],
  2185. \ ['operatorfunc', 'MyOpFunc', '1a-'],
  2186. "\ ['previewpopup', 'width:20', 'a123'],
  2187. "\ ['printoptions', 'paper:A4', 'a123:'],
  2188. \ ['quickfixtextfunc', 'MyQfFunc', '1a-'],
  2189. \ ['rulerformat', '%l', '%['],
  2190. \ ['scrollopt', 'hor,jump', 'a123'],
  2191. \ ['selection', 'exclusive', 'a123'],
  2192. \ ['selectmode', 'cmd', 'a123'],
  2193. \ ['sessionoptions', 'options', 'a123'],
  2194. \ ['shortmess', 'w', '2'],
  2195. \ ['showbreak', '>>', "\x01"],
  2196. \ ['showcmdloc', 'statusline', 'a123'],
  2197. \ ['signcolumn', 'no', 'a123'],
  2198. \ ['spellcapcheck', '[.?!]\+', '%\{'],
  2199. \ ['spellfile', 'MySpell.en.add', "\x01"],
  2200. \ ['spelllang', 'en', "#"],
  2201. \ ['spelloptions', 'camel', 'a123'],
  2202. \ ['spellsuggest', 'double', 'a123'],
  2203. \ ['splitkeep', 'topline', 'a123'],
  2204. \ ['statusline', '%f', '%['],
  2205. "\ ['swapsync', 'sync', 'a123'],
  2206. \ ['switchbuf', 'usetab', 'a123'],
  2207. \ ['syntax', 'abc', 'a^b'],
  2208. \ ['tabline', '%f', '%['],
  2209. \ ['tagcase', 'ignore', 'a123'],
  2210. \ ['tagfunc', 'MyTagFunc', '1a-'],
  2211. \ ['thesaurusfunc', 'MyThesaurusFunc', '1a-'],
  2212. \ ['viewoptions', 'options', 'a123'],
  2213. \ ['virtualedit', 'onemore', 'a123'],
  2214. \ ['whichwrap', '<,>', '{,}'],
  2215. \ ['wildmode', 'list', 'a123'],
  2216. \ ['wildoptions', 'pum', 'a123']
  2217. \ ]
  2218. if has('gui')
  2219. call add(optlist, ['browsedir', 'buffer', 'a123'])
  2220. endif
  2221. if has('clipboard_working')
  2222. call add(optlist, ['clipboard', 'unnamed', 'a123'])
  2223. endif
  2224. if has('win32')
  2225. call add(optlist, ['completeslash', 'slash', 'a123'])
  2226. endif
  2227. if has('cscope')
  2228. call add(optlist, ['cscopequickfix', 't-', 'z-'])
  2229. endif
  2230. if !has('win32') && !has('nvim')
  2231. call add(optlist, ['imactivatefunc', 'MyActFunc', '1a-'])
  2232. call add(optlist, ['imstatusfunc', 'MyStatusFunc', '1a-'])
  2233. endif
  2234. if has('keymap')
  2235. call add(optlist, ['keymap', 'greek', '[]'])
  2236. endif
  2237. if has('mouseshape')
  2238. call add(optlist, ['mouseshape', 'm:no', 'a123:'])
  2239. endif
  2240. if has('win32') && has('gui')
  2241. call add(optlist, ['renderoptions', 'type:directx', 'type:directx,a123'])
  2242. endif
  2243. if has('rightleft')
  2244. call add(optlist, ['rightleftcmd', 'search', 'a123'])
  2245. endif
  2246. if has('terminal')
  2247. call add(optlist, ['termwinkey', '<C-L>', '<C'])
  2248. call add(optlist, ['termwinsize', '24x80', '100'])
  2249. endif
  2250. if has('win32') && has('terminal')
  2251. call add(optlist, ['termwintype', 'winpty', 'a123'])
  2252. endif
  2253. if exists('+toolbar')
  2254. call add(optlist, ['toolbar', 'text', 'a123'])
  2255. endif
  2256. if exists('+toolbariconsize')
  2257. call add(optlist, ['toolbariconsize', 'medium', 'a123'])
  2258. endif
  2259. if exists('+ttymouse') && !has('gui')
  2260. call add(optlist, ['ttymouse', 'xterm', 'a123'])
  2261. endif
  2262. if exists('+vartabs')
  2263. call add(optlist, ['varsofttabstop', '12', 'a123'])
  2264. call add(optlist, ['vartabstop', '4,20', '4,'])
  2265. endif
  2266. if exists('+winaltkeys')
  2267. call add(optlist, ['winaltkeys', 'no', 'a123'])
  2268. endif
  2269. for opt in optlist
  2270. exe $"let save_opt = &{opt[0]}"
  2271. try
  2272. exe $"let &{opt[0]} = '{opt[1]}'"
  2273. catch
  2274. call assert_report($"Caught {v:exception} with {opt->string()}")
  2275. endtry
  2276. call assert_fails($"let &{opt[0]} = '{opt[2]}'", '', opt[0])
  2277. call assert_equal(opt[1], eval($"&{opt[0]}"), opt[0])
  2278. exe $"let &{opt[0]} = save_opt"
  2279. endfor
  2280. bw!
  2281. endfunc
  2282. func Test_set_option_window_global_local()
  2283. new Xbuffer1
  2284. let [ _gso, _lso ] = [ &g:scrolloff, &l:scrolloff ]
  2285. setlocal scrolloff=2
  2286. setglobal scrolloff=3
  2287. setl modified
  2288. " A new buffer has its own window-local options
  2289. hide enew
  2290. call assert_equal(-1, &l:scrolloff)
  2291. call assert_equal(3, &g:scrolloff)
  2292. " A new window opened with its own buffer-local options
  2293. new
  2294. call assert_equal(-1, &l:scrolloff)
  2295. call assert_equal(3, &g:scrolloff)
  2296. " Re-open Xbuffer1 and it should use
  2297. " the previous set window-local options
  2298. b Xbuffer1
  2299. call assert_equal(2, &l:scrolloff)
  2300. call assert_equal(3, &g:scrolloff)
  2301. bw!
  2302. bw!
  2303. let &g:scrolloff = _gso
  2304. endfunc
  2305. func GetGlobalLocalWindowOptions()
  2306. new
  2307. sil! r $VIMRUNTIME/doc/options.txt
  2308. " Filter for global or local to window
  2309. v/^'.*'.*\n.*global or local to window |global-local/d
  2310. " get option value and type
  2311. sil %s/^'\([^']*\)'.*'\s\+\(\w\+\)\s\+(default \%(\(".*"\|\d\+\|empty\)\).*/\1 \2 \3/g
  2312. " sil %s/empty/""/g
  2313. " split the result
  2314. " let result=getline(1,'$')->map({_, val -> split(val, ' ')})
  2315. let result = getline(1, '$')->map({_, val -> matchlist(val, '\([^ ]\+\) \+\([^ ]\+\) \+\(.*\)')[1:3]})
  2316. bw!
  2317. return result
  2318. endfunc
  2319. func Test_set_option_window_global_local_all()
  2320. new Xbuffer2
  2321. let optionlist = GetGlobalLocalWindowOptions()
  2322. for [opt, type, default] in optionlist
  2323. let _old = eval('&g:' .. opt)
  2324. if type == 'string'
  2325. if opt == 'fillchars'
  2326. exe 'setl ' .. opt .. '=vert:+'
  2327. exe 'setg ' .. opt .. '=vert:+,fold:+'
  2328. elseif opt == 'listchars'
  2329. exe 'setl ' .. opt .. '=tab:>>'
  2330. exe 'setg ' .. opt .. '=tab:++'
  2331. elseif opt == 'virtualedit'
  2332. exe 'setl ' .. opt .. '=all'
  2333. exe 'setg ' .. opt .. '=block'
  2334. else
  2335. exe 'setl ' .. opt .. '=Local'
  2336. exe 'setg ' .. opt .. '=Global'
  2337. endif
  2338. elseif type == 'number'
  2339. exe 'setl ' .. opt .. '=5'
  2340. exe 'setg ' .. opt .. '=10'
  2341. endif
  2342. setl modified
  2343. hide enew
  2344. if type == 'string'
  2345. call assert_equal('', eval('&l:' .. opt))
  2346. if opt == 'fillchars'
  2347. call assert_equal('vert:+,fold:+', eval('&g:' .. opt), 'option:' .. opt)
  2348. elseif opt == 'listchars'
  2349. call assert_equal('tab:++', eval('&g:' .. opt), 'option:' .. opt)
  2350. elseif opt == 'virtualedit'
  2351. call assert_equal('block', eval('&g:' .. opt), 'option:' .. opt)
  2352. else
  2353. call assert_equal('Global', eval('&g:' .. opt), 'option:' .. opt)
  2354. endif
  2355. elseif type == 'number'
  2356. call assert_equal(-1, eval('&l:' .. opt), 'option:' .. opt)
  2357. call assert_equal(10, eval('&g:' .. opt), 'option:' .. opt)
  2358. endif
  2359. bw!
  2360. exe 'let &g:' .. opt .. '=' .. default
  2361. endfor
  2362. bw!
  2363. endfunc
  2364. func Test_paste_depending_options()
  2365. " setting the paste option, resets all dependent options
  2366. " and will be reported correctly using :verbose set <option>?
  2367. let lines =<< trim [CODE]
  2368. " set paste test
  2369. set autoindent
  2370. set expandtab
  2371. " disabled, because depends on compiled feature set
  2372. " set hkmap
  2373. " set revins
  2374. " set varsofttabstop=8,32,8
  2375. set ruler
  2376. set showmatch
  2377. set smarttab
  2378. set softtabstop=4
  2379. set textwidth=80
  2380. set wrapmargin=10
  2381. source Xvimrc_paste2
  2382. redir > Xoutput_paste
  2383. verbose set expandtab?
  2384. verbose setg expandtab?
  2385. verbose setl expandtab?
  2386. redir END
  2387. qall!
  2388. [CODE]
  2389. call writefile(lines, 'Xvimrc_paste', 'D')
  2390. call writefile(['set paste'], 'Xvimrc_paste2', 'D')
  2391. if !RunVim([], lines, '--clean')
  2392. return
  2393. endif
  2394. let result = readfile('Xoutput_paste')->filter('!empty(v:val)')
  2395. call assert_equal('noexpandtab', result[0])
  2396. call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[1])
  2397. call assert_equal('noexpandtab', result[2])
  2398. call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[3])
  2399. call assert_equal('noexpandtab', result[4])
  2400. call assert_match("^\tLast set from .*Xvimrc_paste2 line 1$", result[5])
  2401. call delete('Xoutput_paste')
  2402. endfunc
  2403. func Test_binary_depending_options()
  2404. " setting the paste option, resets all dependent options
  2405. " and will be reported correctly using :verbose set <option>?
  2406. let lines =<< trim [CODE]
  2407. " set binary test
  2408. set expandtab
  2409. source Xvimrc_bin2
  2410. redir > Xoutput_bin
  2411. verbose set expandtab?
  2412. verbose setg expandtab?
  2413. verbose setl expandtab?
  2414. redir END
  2415. qall!
  2416. [CODE]
  2417. call writefile(lines, 'Xvimrc_bin', 'D')
  2418. call writefile(['set binary'], 'Xvimrc_bin2', 'D')
  2419. if !RunVim([], lines, '--clean')
  2420. return
  2421. endif
  2422. let result = readfile('Xoutput_bin')->filter('!empty(v:val)')
  2423. call assert_equal('noexpandtab', result[0])
  2424. call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[1])
  2425. call assert_equal('noexpandtab', result[2])
  2426. call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[3])
  2427. call assert_equal('noexpandtab', result[4])
  2428. call assert_match("^\tLast set from .*Xvimrc_bin2 line 1$", result[5])
  2429. call delete('Xoutput_bin')
  2430. endfunc
  2431. func Test_set_wrap()
  2432. " Unsetting 'wrap' when 'smoothscroll' is set does not result in incorrect
  2433. " cursor position.
  2434. set wrap smoothscroll scrolloff=5
  2435. call setline(1, ['', 'aaaa'->repeat(500)])
  2436. 20 split
  2437. 20 vsplit
  2438. norm 2G$
  2439. redraw
  2440. set nowrap
  2441. call assert_equal(2, winline())
  2442. set wrap& smoothscroll& scrolloff&
  2443. endfunc
  2444. func Test_delcombine()
  2445. new
  2446. set backspace=indent,eol,start
  2447. set delcombine
  2448. call setline(1, 'β̳̈:β̳̈')
  2449. normal! 0x
  2450. call assert_equal('β̈:β̳̈', getline(1))
  2451. exe "normal! A\<BS>"
  2452. call assert_equal('β̈:β̈', getline(1))
  2453. normal! 0x
  2454. call assert_equal('β:β̈', getline(1))
  2455. exe "normal! A\<BS>"
  2456. call assert_equal('β:β', getline(1))
  2457. normal! 0x
  2458. call assert_equal(':β', getline(1))
  2459. exe "normal! A\<BS>"
  2460. call assert_equal(':', getline(1))
  2461. set nodelcombine
  2462. call setline(1, 'β̳̈:β̳̈')
  2463. normal! 0x
  2464. call assert_equal(':β̳̈', getline(1))
  2465. exe "normal! A\<BS>"
  2466. call assert_equal(':', getline(1))
  2467. set backspace& delcombine&
  2468. bwipe!
  2469. endfunc
  2470. " Should not raise errors when set missing-options.
  2471. func Test_set_missing_options()
  2472. throw 'Skipped: N/A'
  2473. set autoprint
  2474. set beautify
  2475. set flash
  2476. set graphic
  2477. set hardtabs=8
  2478. set mesg
  2479. set novice
  2480. set open
  2481. set optimize
  2482. set redraw
  2483. set slowopen
  2484. set sourceany
  2485. set w300=23
  2486. set w1200=23
  2487. set w9600=23
  2488. endfunc
  2489. " vim: shiftwidth=2 sts=2 expandtab