test_options.vim 92 KB

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