test_options.vim 91 KB

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