test_cmdline.vim 146 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364
  1. " Tests for editing the command line.
  2. source check.vim
  3. source screendump.vim
  4. source view_util.vim
  5. source shared.vim
  6. func SetUp()
  7. func SaveLastScreenLine()
  8. let g:Sline = Screenline(&lines - 1)
  9. return ''
  10. endfunc
  11. cnoremap <expr> <F4> SaveLastScreenLine()
  12. endfunc
  13. func TearDown()
  14. delfunc SaveLastScreenLine
  15. cunmap <F4>
  16. endfunc
  17. func Test_complete_tab()
  18. call writefile(['testfile'], 'Xtestfile')
  19. call feedkeys(":e Xtest\t\r", "tx")
  20. call assert_equal('testfile', getline(1))
  21. " Pressing <Tab> after '%' completes the current file, also on MS-Windows
  22. call feedkeys(":e %\t\r", "tx")
  23. call assert_equal('e Xtestfile', @:)
  24. call delete('Xtestfile')
  25. endfunc
  26. func Test_complete_list()
  27. " We can't see the output, but at least we check the code runs properly.
  28. call feedkeys(":e test\<C-D>\r", "tx")
  29. call assert_equal('test', expand('%:t'))
  30. " If a command doesn't support completion, then CTRL-D should be literally
  31. " used.
  32. call feedkeys(":chistory \<C-D>\<C-B>\"\<CR>", 'xt')
  33. call assert_equal("\"chistory \<C-D>", @:)
  34. " Test for displaying the tail of the completion matches
  35. set wildmode=longest,full
  36. call mkdir('Xtest')
  37. call writefile([], 'Xtest/a.c')
  38. call writefile([], 'Xtest/a.h')
  39. let g:Sline = ''
  40. call feedkeys(":e Xtest/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
  41. call assert_equal('a.c a.h', g:Sline)
  42. call assert_equal('"e Xtest/', @:)
  43. if has('win32')
  44. " Test for 'completeslash'
  45. set completeslash=backslash
  46. call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt')
  47. call assert_equal('"e Xtest\', @:)
  48. call feedkeys(":e Xtest/\<Tab>\<C-B>\"\<CR>", 'xt')
  49. call assert_equal('"e Xtest\a.', @:)
  50. set completeslash=slash
  51. call feedkeys(":e Xtest\<Tab>\<C-B>\"\<CR>", 'xt')
  52. call assert_equal('"e Xtest/', @:)
  53. call feedkeys(":e Xtest\\\<Tab>\<C-B>\"\<CR>", 'xt')
  54. call assert_equal('"e Xtest/a.', @:)
  55. set completeslash&
  56. endif
  57. " Test for displaying the tail with wildcards
  58. let g:Sline = ''
  59. call feedkeys(":e Xtes?/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
  60. call assert_equal('Xtest/a.c Xtest/a.h', g:Sline)
  61. call assert_equal('"e Xtes?/', @:)
  62. let g:Sline = ''
  63. call feedkeys(":e Xtes*/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
  64. call assert_equal('Xtest/a.c Xtest/a.h', g:Sline)
  65. call assert_equal('"e Xtes*/', @:)
  66. let g:Sline = ''
  67. call feedkeys(":e Xtes[/\<C-D>\<F4>\<C-B>\"\<CR>", 'xt')
  68. call assert_equal(':e Xtes[/', g:Sline)
  69. call assert_equal('"e Xtes[/', @:)
  70. call delete('Xtest', 'rf')
  71. set wildmode&
  72. endfunc
  73. func Test_complete_wildmenu()
  74. call mkdir('Xwilddir1/Xdir2', 'pR')
  75. call writefile(['testfile1'], 'Xwilddir1/Xtestfile1')
  76. call writefile(['testfile2'], 'Xwilddir1/Xtestfile2')
  77. call writefile(['testfile3'], 'Xwilddir1/Xdir2/Xtestfile3')
  78. call writefile(['testfile3'], 'Xwilddir1/Xdir2/Xtestfile4')
  79. set wildmenu
  80. " Pressing <Tab> completes, and moves to next files when pressing again.
  81. call feedkeys(":e Xwilddir1/\<Tab>\<Tab>\<CR>", 'tx')
  82. call assert_equal('testfile1', getline(1))
  83. call feedkeys(":e Xwilddir1/\<Tab>\<Tab>\<Tab>\<CR>", 'tx')
  84. call assert_equal('testfile2', getline(1))
  85. " <S-Tab> is like <Tab> but begin with the last match and then go to
  86. " previous.
  87. call feedkeys(":e Xwilddir1/Xtest\<S-Tab>\<CR>", 'tx')
  88. call assert_equal('testfile2', getline(1))
  89. call feedkeys(":e Xwilddir1/Xtest\<S-Tab>\<S-Tab>\<CR>", 'tx')
  90. call assert_equal('testfile1', getline(1))
  91. " <Left>/<Right> to move to previous/next file.
  92. call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<CR>", 'tx')
  93. call assert_equal('testfile1', getline(1))
  94. call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<Right>\<CR>", 'tx')
  95. call assert_equal('testfile2', getline(1))
  96. call feedkeys(":e Xwilddir1/\<Tab>\<Right>\<Right>\<Left>\<CR>", 'tx')
  97. call assert_equal('testfile1', getline(1))
  98. " <Up>/<Down> to go up/down directories.
  99. call feedkeys(":e Xwilddir1/\<Tab>\<Down>\<CR>", 'tx')
  100. call assert_equal('testfile3', getline(1))
  101. call feedkeys(":e Xwilddir1/\<Tab>\<Down>\<Up>\<Right>\<CR>", 'tx')
  102. call assert_equal('testfile1', getline(1))
  103. " this fails in some Unix GUIs, not sure why
  104. if !has('unix') || !has('gui_running')
  105. " <C-J>/<C-K> mappings to go up/down directories when 'wildcharm' is
  106. " different than 'wildchar'.
  107. set wildcharm=<C-Z>
  108. cnoremap <C-J> <Down><C-Z>
  109. cnoremap <C-K> <Up><C-Z>
  110. call feedkeys(":e Xwilddir1/\<Tab>\<C-J>\<CR>", 'tx')
  111. call assert_equal('testfile3', getline(1))
  112. call feedkeys(":e Xwilddir1/\<Tab>\<C-J>\<C-K>\<CR>", 'tx')
  113. call assert_equal('testfile1', getline(1))
  114. set wildcharm=0
  115. cunmap <C-J>
  116. cunmap <C-K>
  117. endif
  118. " Test for canceling the wild menu by adding a character
  119. redrawstatus
  120. call feedkeys(":e Xwilddir1/\<Tab>x\<C-B>\"\<CR>", 'xt')
  121. call assert_equal('"e Xwilddir1/Xdir2/x', @:)
  122. " Completion using a relative path
  123. cd Xwilddir1/Xdir2
  124. call feedkeys(":e ../\<Tab>\<Right>\<Down>\<C-A>\<C-B>\"\<CR>", 'tx')
  125. call assert_equal('"e Xtestfile3 Xtestfile4', @:)
  126. cd -
  127. " test for wildmenumode()
  128. cnoremap <expr> <F2> wildmenumode()
  129. call feedkeys(":cd Xwilddir\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
  130. call assert_equal('"cd Xwilddir1/0', @:)
  131. call feedkeys(":e Xwilddir1/\<Tab>\<F2>\<C-B>\"\<CR>", 'tx')
  132. call assert_equal('"e Xwilddir1/Xdir2/1', @:)
  133. cunmap <F2>
  134. " Test for canceling the wild menu by pressing <PageDown> or <PageUp>.
  135. " After this pressing <Left> or <Right> should not change the selection.
  136. call feedkeys(":sign \<Tab>\<PageDown>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx')
  137. call assert_equal('"sign define', @:)
  138. call histadd('cmd', 'TestWildMenu')
  139. call feedkeys(":sign \<Tab>\<PageUp>\<Left>\<Right>\<C-A>\<C-B>\"\<CR>", 'tx')
  140. call assert_equal('"TestWildMenu', @:)
  141. " Test for Ctrl-E/Ctrl-Y being able to cancel / accept a match
  142. call feedkeys(":sign un zz\<Left>\<Left>\<Left>\<Tab>\<C-E> yy\<C-B>\"\<CR>", 'tx')
  143. call assert_equal('"sign un yy zz', @:)
  144. call feedkeys(":sign un zz\<Left>\<Left>\<Left>\<Tab>\<Tab>\<C-Y> yy\<C-B>\"\<CR>", 'tx')
  145. call assert_equal('"sign unplace yy zz', @:)
  146. " cleanup
  147. %bwipe
  148. set nowildmenu
  149. endfunc
  150. func Test_wildmenu_screendump()
  151. CheckScreendump
  152. let lines =<< trim [SCRIPT]
  153. set wildmenu hlsearch
  154. [SCRIPT]
  155. call writefile(lines, 'XTest_wildmenu', 'D')
  156. " Test simple wildmenu
  157. let buf = RunVimInTerminal('-S XTest_wildmenu', {'rows': 8})
  158. call term_sendkeys(buf, ":vim\<Tab>")
  159. call VerifyScreenDump(buf, 'Test_wildmenu_1', {})
  160. call term_sendkeys(buf, "\<Tab>")
  161. call VerifyScreenDump(buf, 'Test_wildmenu_2', {})
  162. call term_sendkeys(buf, "\<Tab>")
  163. call VerifyScreenDump(buf, 'Test_wildmenu_3', {})
  164. " Looped back to the original value
  165. call term_sendkeys(buf, "\<Tab>\<Tab>")
  166. call VerifyScreenDump(buf, 'Test_wildmenu_4', {})
  167. " Test that the wild menu is cleared properly
  168. call term_sendkeys(buf, " ")
  169. call VerifyScreenDump(buf, 'Test_wildmenu_5', {})
  170. " Test that a different wildchar still works
  171. call term_sendkeys(buf, "\<Esc>:set wildchar=<Esc>\<CR>")
  172. call term_sendkeys(buf, ":vim\<Esc>")
  173. call VerifyScreenDump(buf, 'Test_wildmenu_1', {})
  174. " Double-<Esc> is a hard-coded method to escape while wildchar=<Esc>. Make
  175. " sure clean up is properly done in edge case like this.
  176. call term_sendkeys(buf, "\<Esc>")
  177. call VerifyScreenDump(buf, 'Test_wildmenu_6', {})
  178. " clean up
  179. call StopVimInTerminal(buf)
  180. endfunc
  181. func Test_wildmenu_with_input_func()
  182. CheckScreendump
  183. let buf = RunVimInTerminal('-c "set wildmenu"', {'rows': 8})
  184. call term_sendkeys(buf, ":call input('Command? ', '', 'command')\<CR>")
  185. call VerifyScreenDump(buf, 'Test_wildmenu_input_func_1', {})
  186. call term_sendkeys(buf, "ech\<Tab>")
  187. call VerifyScreenDump(buf, 'Test_wildmenu_input_func_2', {})
  188. call term_sendkeys(buf, "\<Space>")
  189. call VerifyScreenDump(buf, 'Test_wildmenu_input_func_3', {})
  190. call term_sendkeys(buf, "bufn\<Tab>")
  191. call VerifyScreenDump(buf, 'Test_wildmenu_input_func_4', {})
  192. call term_sendkeys(buf, "\<CR>")
  193. call term_sendkeys(buf, ":set wildoptions+=pum\<CR>")
  194. call term_sendkeys(buf, ":call input('Command? ', '', 'command')\<CR>")
  195. call VerifyScreenDump(buf, 'Test_wildmenu_input_func_5', {})
  196. call term_sendkeys(buf, "ech\<Tab>")
  197. call VerifyScreenDump(buf, 'Test_wildmenu_input_func_6', {})
  198. call term_sendkeys(buf, "\<Space>")
  199. call VerifyScreenDump(buf, 'Test_wildmenu_input_func_7', {})
  200. call term_sendkeys(buf, "bufn\<Tab>")
  201. call VerifyScreenDump(buf, 'Test_wildmenu_input_func_8', {})
  202. call term_sendkeys(buf, "\<CR>")
  203. " clean up
  204. call StopVimInTerminal(buf)
  205. endfunc
  206. func Test_redraw_in_autocmd()
  207. CheckScreendump
  208. let lines =<< trim END
  209. set cmdheight=2
  210. autocmd CmdlineChanged * redraw
  211. END
  212. call writefile(lines, 'XTest_redraw', 'D')
  213. let buf = RunVimInTerminal('-S XTest_redraw', {'rows': 8})
  214. call term_sendkeys(buf, ":for i in range(3)\<CR>")
  215. call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_1', {})
  216. call term_sendkeys(buf, "let i =")
  217. call VerifyScreenDump(buf, 'Test_redraw_in_autocmd_2', {})
  218. " clean up
  219. call term_sendkeys(buf, "\<CR>")
  220. call StopVimInTerminal(buf)
  221. endfunc
  222. func Test_redrawstatus_in_autocmd()
  223. CheckScreendump
  224. let lines =<< trim END
  225. set laststatus=2
  226. set statusline=%=:%{getcmdline()}
  227. autocmd CmdlineChanged * redrawstatus
  228. END
  229. call writefile(lines, 'XTest_redrawstatus', 'D')
  230. let buf = RunVimInTerminal('-S XTest_redrawstatus', {'rows': 8})
  231. " :redrawstatus is postponed if messages have scrolled
  232. call term_sendkeys(buf, ":echo \"one\\ntwo\\nthree\\nfour\"\<CR>")
  233. call term_sendkeys(buf, ":foobar")
  234. call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_1', {})
  235. " it is not postponed if messages have not scrolled
  236. call term_sendkeys(buf, "\<Esc>:for in in range(3)")
  237. call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_2', {})
  238. " with cmdheight=1 messages have scrolled when typing :endfor
  239. call term_sendkeys(buf, "\<CR>:endfor")
  240. call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_3', {})
  241. call term_sendkeys(buf, "\<CR>:set cmdheight=2\<CR>")
  242. " with cmdheight=2 messages haven't scrolled when typing :for or :endfor
  243. call term_sendkeys(buf, ":for in in range(3)")
  244. call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_4', {})
  245. call term_sendkeys(buf, "\<CR>:endfor")
  246. call VerifyScreenDump(buf, 'Test_redrawstatus_in_autocmd_5', {})
  247. " clean up
  248. call term_sendkeys(buf, "\<CR>")
  249. call StopVimInTerminal(buf)
  250. endfunc
  251. func Test_changing_cmdheight()
  252. CheckScreendump
  253. let lines =<< trim END
  254. set cmdheight=1 laststatus=2
  255. func EchoOne()
  256. set laststatus=2 cmdheight=1
  257. echo 'foo'
  258. echo 'bar'
  259. set cmdheight=2
  260. endfunc
  261. func EchoTwo()
  262. set laststatus=2
  263. set cmdheight=5
  264. echo 'foo'
  265. echo 'bar'
  266. set cmdheight=1
  267. endfunc
  268. END
  269. call writefile(lines, 'XTest_cmdheight', 'D')
  270. let buf = RunVimInTerminal('-S XTest_cmdheight', {'rows': 8})
  271. call term_sendkeys(buf, ":resize -3\<CR>")
  272. call VerifyScreenDump(buf, 'Test_changing_cmdheight_1', {})
  273. " :resize now also changes 'cmdheight' accordingly
  274. call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
  275. call VerifyScreenDump(buf, 'Test_changing_cmdheight_2', {})
  276. " using more space moves the status line up
  277. call term_sendkeys(buf, ":set cmdheight+=1\<CR>")
  278. call VerifyScreenDump(buf, 'Test_changing_cmdheight_3', {})
  279. " reducing cmdheight moves status line down
  280. call term_sendkeys(buf, ":set cmdheight-=3\<CR>")
  281. call VerifyScreenDump(buf, 'Test_changing_cmdheight_4', {})
  282. " reducing window size and then setting cmdheight
  283. call term_sendkeys(buf, ":resize -1\<CR>")
  284. call term_sendkeys(buf, ":set cmdheight=1\<CR>")
  285. call VerifyScreenDump(buf, 'Test_changing_cmdheight_5', {})
  286. " setting 'cmdheight' works after outputting two messages
  287. call term_sendkeys(buf, ":call EchoTwo()\<CR>")
  288. call VerifyScreenDump(buf, 'Test_changing_cmdheight_6', {})
  289. " increasing 'cmdheight' doesn't clear the messages that need hit-enter
  290. call term_sendkeys(buf, ":call EchoOne()\<CR>")
  291. call VerifyScreenDump(buf, 'Test_changing_cmdheight_7', {})
  292. " window commands do not reduce 'cmdheight' to value lower than :set by user
  293. call term_sendkeys(buf, "\<CR>:wincmd _\<CR>")
  294. call VerifyScreenDump(buf, 'Test_changing_cmdheight_8', {})
  295. " clean up
  296. call StopVimInTerminal(buf)
  297. endfunc
  298. func Test_cmdheight_tabline()
  299. CheckScreendump
  300. let buf = RunVimInTerminal('-c "set ls=2" -c "set stal=2" -c "set cmdheight=1"', {'rows': 6})
  301. call VerifyScreenDump(buf, 'Test_cmdheight_tabline_1', {})
  302. " clean up
  303. call StopVimInTerminal(buf)
  304. endfunc
  305. func Test_map_completion()
  306. call feedkeys(":map <unique> <si\<Tab>\<Home>\"\<CR>", 'xt')
  307. call assert_equal('"map <unique> <silent>', getreg(':'))
  308. call feedkeys(":map <script> <un\<Tab>\<Home>\"\<CR>", 'xt')
  309. call assert_equal('"map <script> <unique>', getreg(':'))
  310. call feedkeys(":map <expr> <sc\<Tab>\<Home>\"\<CR>", 'xt')
  311. call assert_equal('"map <expr> <script>', getreg(':'))
  312. call feedkeys(":map <buffer> <e\<Tab>\<Home>\"\<CR>", 'xt')
  313. call assert_equal('"map <buffer> <expr>', getreg(':'))
  314. call feedkeys(":map <nowait> <b\<Tab>\<Home>\"\<CR>", 'xt')
  315. call assert_equal('"map <nowait> <buffer>', getreg(':'))
  316. call feedkeys(":map <special> <no\<Tab>\<Home>\"\<CR>", 'xt')
  317. call assert_equal('"map <special> <nowait>', getreg(':'))
  318. call feedkeys(":map <silent> <sp\<Tab>\<Home>\"\<CR>", 'xt')
  319. call assert_equal('"map <silent> <special>', getreg(':'))
  320. map <Middle>x middle
  321. map ,f commaf
  322. map ,g commaf
  323. map <Left> left
  324. map <A-Left>x shiftleft
  325. call feedkeys(":map ,\<Tab>\<Home>\"\<CR>", 'xt')
  326. call assert_equal('"map ,f', getreg(':'))
  327. call feedkeys(":map ,\<Tab>\<Tab>\<Home>\"\<CR>", 'xt')
  328. call assert_equal('"map ,g', getreg(':'))
  329. call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
  330. call assert_equal('"map <Left>', getreg(':'))
  331. call feedkeys(":map <A-Left>\<Tab>\<Home>\"\<CR>", 'xt')
  332. call assert_equal("\"map <A-Left>\<Tab>", getreg(':'))
  333. call feedkeys(":map <M-Left>\<Tab>\<Home>\"\<CR>", 'xt')
  334. call assert_equal("\"map <M-Left>x", getreg(':'))
  335. unmap ,f
  336. unmap ,g
  337. unmap <Left>
  338. unmap <A-Left>x
  339. set cpo-=< cpo-=k
  340. map <Left> left
  341. call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
  342. call assert_equal('"map <Left>', getreg(':'))
  343. call feedkeys(":map <M\<Tab>\<Home>\"\<CR>", 'xt')
  344. call assert_equal("\"map <M\<Tab>", getreg(':'))
  345. call feedkeys(":map \<C-V>\<C-V><M\<Tab>\<Home>\"\<CR>", 'xt')
  346. call assert_equal("\"map \<C-V><Middle>x", getreg(':'))
  347. unmap <Left>
  348. " set cpo+=<
  349. map <Left> left
  350. exe "set t_k6=\<Esc>[17~"
  351. call feedkeys(":map \<Esc>[17~x f6x\<CR>", 'xt')
  352. call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
  353. call assert_equal('"map <Left>', getreg(':'))
  354. if !has('gui_running')
  355. call feedkeys(":map \<Esc>[17~\<Tab>\<Home>\"\<CR>", 'xt')
  356. " call assert_equal("\"map <F6>x", getreg(':'))
  357. endif
  358. unmap <Left>
  359. call feedkeys(":unmap \<Esc>[17~x\<CR>", 'xt')
  360. set cpo-=<
  361. set cpo+=B
  362. map <Left> left
  363. call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
  364. call assert_equal('"map <Left>', getreg(':'))
  365. unmap <Left>
  366. set cpo-=B
  367. " set cpo+=k
  368. map <Left> left
  369. call feedkeys(":map <L\<Tab>\<Home>\"\<CR>", 'xt')
  370. call assert_equal('"map <Left>', getreg(':'))
  371. unmap <Left>
  372. set cpo-=k
  373. call assert_fails('call feedkeys(":map \\\\%(\<Tab>\<Home>\"\<CR>", "xt")', 'E53:')
  374. unmap <Middle>x
  375. set cpo&vim
  376. endfunc
  377. func Test_match_completion()
  378. hi Aardig ctermfg=green
  379. " call feedkeys(":match \<Tab>\<Home>\"\<CR>", 'xt')
  380. call feedkeys(":match A\<Tab>\<Home>\"\<CR>", 'xt')
  381. call assert_equal('"match Aardig', @:)
  382. call feedkeys(":match \<S-Tab>\<Home>\"\<CR>", 'xt')
  383. call assert_equal('"match none', @:)
  384. call feedkeys(":match | chist\<Tab>\<C-B>\"\<CR>", 'xt')
  385. call assert_equal('"match | chistory', @:)
  386. endfunc
  387. func Test_highlight_completion()
  388. hi Aardig ctermfg=green
  389. " call feedkeys(":hi \<Tab>\<Home>\"\<CR>", 'xt')
  390. call feedkeys(":hi A\<Tab>\<Home>\"\<CR>", 'xt')
  391. call assert_equal('"hi Aardig', getreg(':'))
  392. " call feedkeys(":hi default \<Tab>\<Home>\"\<CR>", 'xt')
  393. call feedkeys(":hi default A\<Tab>\<Home>\"\<CR>", 'xt')
  394. call assert_equal('"hi default Aardig', getreg(':'))
  395. call feedkeys(":hi clear Aa\<Tab>\<Home>\"\<CR>", 'xt')
  396. call assert_equal('"hi clear Aardig', getreg(':'))
  397. call feedkeys(":hi li\<S-Tab>\<Home>\"\<CR>", 'xt')
  398. call assert_equal('"hi link', getreg(':'))
  399. call feedkeys(":hi d\<S-Tab>\<Home>\"\<CR>", 'xt')
  400. call assert_equal('"hi default', getreg(':'))
  401. call feedkeys(":hi c\<S-Tab>\<Home>\"\<CR>", 'xt')
  402. call assert_equal('"hi clear', getreg(':'))
  403. " A cleared group does not show up in completions.
  404. hi Anders ctermfg=green
  405. call assert_equal(['Aardig', 'Added', 'Anders'], getcompletion('A', 'highlight'))
  406. hi clear Aardig
  407. call assert_equal(['Added', 'Anders'], getcompletion('A', 'highlight'))
  408. hi clear Anders
  409. call assert_equal(['Added'], getcompletion('A', 'highlight'))
  410. endfunc
  411. func Test_getcompletion()
  412. let groupcount = len(getcompletion('', 'event'))
  413. call assert_true(groupcount > 0)
  414. let matchcount = len('File'->getcompletion('event'))
  415. call assert_true(matchcount > 0)
  416. call assert_true(groupcount > matchcount)
  417. if has('menu')
  418. source $VIMRUNTIME/menu.vim
  419. let matchcount = len(getcompletion('', 'menu'))
  420. call assert_true(matchcount > 0)
  421. call assert_equal(['File.'], getcompletion('File', 'menu'))
  422. call assert_true(matchcount > 0)
  423. let matchcount = len(getcompletion('File.', 'menu'))
  424. call assert_true(matchcount > 0)
  425. source $VIMRUNTIME/delmenu.vim
  426. endif
  427. let l = getcompletion('v:n', 'var')
  428. call assert_true(index(l, 'v:null') >= 0)
  429. let l = getcompletion('v:notexists', 'var')
  430. call assert_equal([], l)
  431. args a.c b.c
  432. let l = getcompletion('', 'arglist')
  433. call assert_equal(['a.c', 'b.c'], l)
  434. let l = getcompletion('a.', 'buffer')
  435. call assert_equal(['a.c'], l)
  436. %argdelete
  437. let l = getcompletion('', 'augroup')
  438. call assert_true(index(l, 'END') >= 0)
  439. let l = getcompletion('blahblah', 'augroup')
  440. call assert_equal([], l)
  441. " let l = getcompletion('', 'behave')
  442. " call assert_true(index(l, 'mswin') >= 0)
  443. " let l = getcompletion('not', 'behave')
  444. " call assert_equal([], l)
  445. let l = getcompletion('', 'color')
  446. call assert_true(index(l, 'default') >= 0)
  447. let l = getcompletion('dirty', 'color')
  448. call assert_equal([], l)
  449. let l = getcompletion('', 'command')
  450. call assert_true(index(l, 'sleep') >= 0)
  451. let l = getcompletion('awake', 'command')
  452. call assert_equal([], l)
  453. let l = getcompletion('', 'dir')
  454. call assert_true(index(l, 'sautest/') >= 0)
  455. let l = getcompletion('NoMatch', 'dir')
  456. call assert_equal([], l)
  457. if glob('~/*') !=# ''
  458. let l = getcompletion('~/', 'dir')
  459. call assert_true(l[0][0] ==# '~')
  460. endif
  461. let l = getcompletion('exe', 'expression')
  462. call assert_true(index(l, 'executable(') >= 0)
  463. let l = getcompletion('kill', 'expression')
  464. call assert_equal([], l)
  465. let l = getcompletion('', 'filetypecmd')
  466. call assert_equal(["indent", "off", "on", "plugin"], l)
  467. let l = getcompletion('not', 'filetypecmd')
  468. call assert_equal([], l)
  469. let l = getcompletion('o', 'filetypecmd')
  470. call assert_equal(['off', 'on'], l)
  471. let l = getcompletion('tag', 'function')
  472. call assert_true(index(l, 'taglist(') >= 0)
  473. let l = getcompletion('paint', 'function')
  474. call assert_equal([], l)
  475. let Flambda = {-> 'hello'}
  476. let l = getcompletion('', 'function')
  477. let l = filter(l, {i, v -> v =~ 'lambda'})
  478. call assert_equal(0, len(l))
  479. let l = getcompletion('run', 'file')
  480. call assert_true(index(l, 'runtest.vim') >= 0)
  481. let l = getcompletion('walk', 'file')
  482. call assert_equal([], l)
  483. set wildignore=*.vim
  484. let l = getcompletion('run', 'file', 1)
  485. call assert_true(index(l, 'runtest.vim') < 0)
  486. set wildignore&
  487. " Directory name with space character
  488. call mkdir('Xdir with space')
  489. call assert_equal(['Xdir with space/'], getcompletion('Xdir\ w', 'shellcmd'))
  490. call assert_equal(['./Xdir with space/'], getcompletion('./Xdir', 'shellcmd'))
  491. call delete('Xdir with space', 'd')
  492. let l = getcompletion('ha', 'filetype')
  493. call assert_true(index(l, 'hamster') >= 0)
  494. let l = getcompletion('horse', 'filetype')
  495. call assert_equal([], l)
  496. if has('keymap')
  497. let l = getcompletion('acc', 'keymap')
  498. call assert_true(index(l, 'accents') >= 0)
  499. let l = getcompletion('nullkeymap', 'keymap')
  500. call assert_equal([], l)
  501. endif
  502. let l = getcompletion('z', 'syntax')
  503. call assert_true(index(l, 'zimbu') >= 0)
  504. let l = getcompletion('emacs', 'syntax')
  505. call assert_equal([], l)
  506. let l = getcompletion('jikes', 'compiler')
  507. call assert_true(index(l, 'jikes') >= 0)
  508. let l = getcompletion('break', 'compiler')
  509. call assert_equal([], l)
  510. let l = getcompletion('last', 'help')
  511. call assert_true(index(l, ':tablast') >= 0)
  512. let l = getcompletion('giveup', 'help')
  513. call assert_equal([], l)
  514. let l = getcompletion('time', 'option')
  515. call assert_true(index(l, 'timeoutlen') >= 0)
  516. let l = getcompletion('space', 'option')
  517. call assert_equal([], l)
  518. let l = getcompletion('er', 'highlight')
  519. call assert_true(index(l, 'ErrorMsg') >= 0)
  520. let l = getcompletion('dark', 'highlight')
  521. call assert_equal([], l)
  522. let l = getcompletion('', 'messages')
  523. call assert_true(index(l, 'clear') >= 0)
  524. let l = getcompletion('not', 'messages')
  525. call assert_equal([], l)
  526. let l = getcompletion('', 'mapclear')
  527. call assert_true(index(l, '<buffer>') >= 0)
  528. let l = getcompletion('not', 'mapclear')
  529. call assert_equal([], l)
  530. let l = getcompletion('.', 'shellcmd')
  531. call assert_equal(['./', '../'], filter(l, 'v:val =~ "\\./"'))
  532. call assert_equal(-1, match(l[2:], '^\.\.\?/$'))
  533. let root = has('win32') ? 'C:\\' : '/'
  534. let l = getcompletion(root, 'shellcmd')
  535. let expected = map(filter(glob(root . '*', 0, 1),
  536. \ 'isdirectory(v:val) || executable(v:val)'), 'isdirectory(v:val) ? v:val . ''/'' : v:val')
  537. call assert_equal(expected, l)
  538. if has('cscope')
  539. let l = getcompletion('', 'cscope')
  540. let cmds = ['add', 'find', 'help', 'kill', 'reset', 'show']
  541. call assert_equal(cmds, l)
  542. " using cmdline completion must not change the result
  543. call feedkeys(":cscope find \<c-d>\<c-c>", 'xt')
  544. let l = getcompletion('', 'cscope')
  545. call assert_equal(cmds, l)
  546. let keys = ['a', 'c', 'd', 'e', 'f', 'g', 'i', 's', 't']
  547. let l = getcompletion('find ', 'cscope')
  548. call assert_equal(keys, l)
  549. endif
  550. if has('signs')
  551. sign define Testing linehl=Comment
  552. let l = getcompletion('', 'sign')
  553. let cmds = ['define', 'jump', 'list', 'place', 'undefine', 'unplace']
  554. call assert_equal(cmds, l)
  555. " using cmdline completion must not change the result
  556. call feedkeys(":sign list \<c-d>\<c-c>", 'xt')
  557. let l = getcompletion('', 'sign')
  558. call assert_equal(cmds, l)
  559. let l = getcompletion('list ', 'sign')
  560. call assert_equal(['Testing'], l)
  561. let l = getcompletion('de*', 'sign')
  562. call assert_equal(['define'], l)
  563. let l = getcompletion('p?', 'sign')
  564. call assert_equal(['place'], l)
  565. let l = getcompletion('j.', 'sign')
  566. call assert_equal(['jump'], l)
  567. endif
  568. " Command line completion tests
  569. let l = getcompletion('cd ', 'cmdline')
  570. call assert_true(index(l, 'samples/') >= 0)
  571. let l = getcompletion('cd NoMatch', 'cmdline')
  572. call assert_equal([], l)
  573. let l = getcompletion('let v:n', 'cmdline')
  574. call assert_true(index(l, 'v:null') >= 0)
  575. let l = getcompletion('let v:notexists', 'cmdline')
  576. call assert_equal([], l)
  577. let l = getcompletion('call tag', 'cmdline')
  578. call assert_true(index(l, 'taglist(') >= 0)
  579. let l = getcompletion('call paint', 'cmdline')
  580. call assert_equal([], l)
  581. let l = getcompletion('autocmd BufEnter * map <bu', 'cmdline')
  582. call assert_equal(['<buffer>'], l)
  583. func T(a, c, p)
  584. let g:cmdline_compl_params = [a:a, a:c, a:p]
  585. return "oneA\noneB\noneC"
  586. endfunc
  587. command -nargs=1 -complete=custom,T MyCmd
  588. let l = getcompletion('MyCmd ', 'cmdline')
  589. call assert_equal(['oneA', 'oneB', 'oneC'], l)
  590. call assert_equal(['', 'MyCmd ', 6], g:cmdline_compl_params)
  591. delcommand MyCmd
  592. delfunc T
  593. unlet g:cmdline_compl_params
  594. " For others test if the name is recognized.
  595. let names = ['buffer', 'environment', 'file_in_path', 'dir_in_path', 'mapping', 'tag',
  596. \ 'tag_listfiles', 'user']
  597. if has('cmdline_hist')
  598. call add(names, 'history')
  599. endif
  600. if has('gettext')
  601. call add(names, 'locale')
  602. endif
  603. if has('profile')
  604. call add(names, 'syntime')
  605. endif
  606. set tags=Xtags
  607. call writefile(["!_TAG_FILE_ENCODING\tutf-8\t//", "word\tfile\tcmd"], 'Xtags')
  608. for name in names
  609. let matchcount = len(getcompletion('', name))
  610. call assert_true(matchcount >= 0, 'No matches for ' . name)
  611. endfor
  612. call delete('Xtags')
  613. set tags&
  614. edit a~b
  615. enew
  616. call assert_equal(['a~b'], getcompletion('a~', 'buffer'))
  617. bw a~b
  618. if has('unix')
  619. edit Xtest\
  620. enew
  621. call assert_equal(['Xtest\'], getcompletion('Xtest\', 'buffer'))
  622. bw Xtest\
  623. endif
  624. call assert_fails("call getcompletion('\\\\@!\\\\@=', 'buffer')", 'E866:')
  625. call assert_fails('call getcompletion("", "burp")', 'E475:')
  626. call assert_fails('call getcompletion("abc", [])', 'E1174:')
  627. endfunc
  628. " Test for getcompletion() with "fuzzy" in 'wildoptions'
  629. func Test_getcompletion_wildoptions()
  630. let save_wildoptions = &wildoptions
  631. set wildoptions&
  632. let l = getcompletion('space', 'option')
  633. call assert_equal([], l)
  634. let l = getcompletion('ier', 'command')
  635. call assert_equal([], l)
  636. set wildoptions=fuzzy
  637. let l = getcompletion('space', 'option')
  638. call assert_true(index(l, 'backspace') >= 0)
  639. let l = getcompletion('ier', 'command')
  640. call assert_true(index(l, 'compiler') >= 0)
  641. let &wildoptions = save_wildoptions
  642. endfunc
  643. func Test_fullcommand()
  644. let tests = {
  645. \ '': '',
  646. \ ':': '',
  647. \ ':::': '',
  648. \ ':::5': '',
  649. \ 'not_a_cmd': '',
  650. \ 'Check': '',
  651. \ 'syntax': 'syntax',
  652. \ ':syntax': 'syntax',
  653. \ '::::syntax': 'syntax',
  654. \ 'sy': 'syntax',
  655. \ 'syn': 'syntax',
  656. \ 'synt': 'syntax',
  657. \ ':sy': 'syntax',
  658. \ '::::sy': 'syntax',
  659. \ 'match': 'match',
  660. \ '2match': 'match',
  661. \ '3match': 'match',
  662. \ 'aboveleft': 'aboveleft',
  663. \ 'abo': 'aboveleft',
  664. \ 's': 'substitute',
  665. \ '5s': 'substitute',
  666. \ ':5s': 'substitute',
  667. \ "'<,'>s": 'substitute',
  668. \ ":'<,'>s": 'substitute',
  669. \ 'CheckLin': 'CheckLinux',
  670. \ 'CheckLinux': 'CheckLinux',
  671. \ }
  672. for [in, want] in items(tests)
  673. call assert_equal(want, fullcommand(in))
  674. endfor
  675. call assert_equal('', fullcommand(v:_null_string))
  676. call assert_equal('syntax', 'syn'->fullcommand())
  677. command -buffer BufferLocalCommand :
  678. command GlobalCommand :
  679. call assert_equal('GlobalCommand', fullcommand('GlobalCom'))
  680. call assert_equal('BufferLocalCommand', fullcommand('BufferL'))
  681. delcommand BufferLocalCommand
  682. delcommand GlobalCommand
  683. endfunc
  684. func Test_shellcmd_completion()
  685. let save_path = $PATH
  686. call mkdir('Xpathdir/Xpathsubdir', 'pR')
  687. call writefile([''], 'Xpathdir/Xfile.exe')
  688. call setfperm('Xpathdir/Xfile.exe', 'rwx------')
  689. " Set PATH to example directory without trailing slash.
  690. let $PATH = getcwd() . '/Xpathdir'
  691. " Test for the ":!<TAB>" case. Previously, this would include subdirs of
  692. " dirs in the PATH, even though they won't be executed. We check that only
  693. " subdirs of the PWD and executables from the PATH are included in the
  694. " suggestions.
  695. let actual = getcompletion('X', 'shellcmd')
  696. let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val) && v:val[0] == "X"'), 'v:val . "/"')
  697. call insert(expected, 'Xfile.exe')
  698. call assert_equal(expected, actual)
  699. let $PATH = save_path
  700. endfunc
  701. func Test_expand_star_star()
  702. call mkdir('a/b/c', 'pR')
  703. call writefile(['asdfasdf'], 'a/b/c/fileXname')
  704. call feedkeys(":find a/**/fileXname\<Tab>\<CR>", 'xt')
  705. call assert_equal('find a/b/c/fileXname', @:)
  706. bwipe!
  707. endfunc
  708. func Test_cmdline_paste()
  709. let @a = "def"
  710. call feedkeys(":abc \<C-R>a ghi\<C-B>\"\<CR>", 'tx')
  711. call assert_equal('"abc def ghi', @:)
  712. new
  713. call setline(1, 'asdf.x /tmp/some verylongword a;b-c*d ')
  714. call feedkeys(":aaa \<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
  715. call assert_equal('"aaa asdf bbb', @:)
  716. call feedkeys("ft:aaa \<C-R>\<C-F> bbb\<C-B>\"\<CR>", 'tx')
  717. call assert_equal('"aaa /tmp/some bbb', @:)
  718. call feedkeys(":aaa \<C-R>\<C-L> bbb\<C-B>\"\<CR>", 'tx')
  719. call assert_equal('"aaa '.getline(1).' bbb', @:)
  720. set incsearch
  721. call feedkeys("fy:aaa veryl\<C-R>\<C-W> bbb\<C-B>\"\<CR>", 'tx')
  722. call assert_equal('"aaa verylongword bbb', @:)
  723. call feedkeys("f;:aaa \<C-R>\<C-A> bbb\<C-B>\"\<CR>", 'tx')
  724. call assert_equal('"aaa a;b-c*d bbb', @:)
  725. call feedkeys(":\<C-\>etoupper(getline(1))\<CR>\<C-B>\"\<CR>", 'tx')
  726. call assert_equal('"ASDF.X /TMP/SOME VERYLONGWORD A;B-C*D ', @:)
  727. bwipe!
  728. " Error while typing a command used to cause that it was not executed
  729. " in the end.
  730. new
  731. try
  732. call feedkeys(":file \<C-R>%Xtestfile\<CR>", 'tx')
  733. catch /^Vim\%((\a\+)\)\=:E32/
  734. " ignore error E32
  735. endtry
  736. call assert_equal("Xtestfile", bufname("%"))
  737. " Try to paste an invalid register using <C-R>
  738. call feedkeys(":\"one\<C-R>\<C-X>two\<CR>", 'xt')
  739. call assert_equal('"onetwo', @:)
  740. " Test for pasting register containing CTRL-H using CTRL-R and CTRL-R CTRL-R
  741. let @a = "xy\<C-H>z"
  742. call feedkeys(":\"\<C-R>a\<CR>", 'xt')
  743. call assert_equal('"xz', @:)
  744. call feedkeys(":\"\<C-R>\<C-R>a\<CR>", 'xt')
  745. call assert_equal("\"xy\<C-H>z", @:)
  746. call feedkeys(":\"\<C-R>\<C-O>a\<CR>", 'xt')
  747. call assert_equal("\"xy\<C-H>z", @:)
  748. " Test for pasting register containing CTRL-V using CTRL-R and CTRL-R CTRL-R
  749. let @a = "xy\<C-V>z"
  750. call feedkeys(":\"\<C-R>=@a\<CR>\<cr>", 'xt')
  751. call assert_equal('"xyz', @:)
  752. call feedkeys(":\"\<C-R>\<C-R>=@a\<CR>\<cr>", 'xt')
  753. call assert_equal("\"xy\<C-V>z", @:)
  754. call assert_beeps('call feedkeys(":\<C-R>=\<C-R>=\<Esc>", "xt")')
  755. bwipe!
  756. endfunc
  757. func Test_cmdline_remove_char()
  758. let encoding_save = &encoding
  759. " for e in ['utf8', 'latin1']
  760. for e in ['utf8']
  761. exe 'set encoding=' . e
  762. call feedkeys(":abc def\<S-Left>\<Del>\<C-B>\"\<CR>", 'tx')
  763. call assert_equal('"abc ef', @:, e)
  764. call feedkeys(":abc def\<S-Left>\<BS>\<C-B>\"\<CR>", 'tx')
  765. call assert_equal('"abcdef', @:)
  766. call feedkeys(":abc def ghi\<S-Left>\<C-W>\<C-B>\"\<CR>", 'tx')
  767. call assert_equal('"abc ghi', @:, e)
  768. call feedkeys(":abc def\<S-Left>\<C-U>\<C-B>\"\<CR>", 'tx')
  769. call assert_equal('"def', @:, e)
  770. " This was going before the start in latin1.
  771. call feedkeys(": \<C-W>\<CR>", 'tx')
  772. endfor
  773. let &encoding = encoding_save
  774. endfunc
  775. func Test_cmdline_del_utf8()
  776. let @s = '⒌'
  777. call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
  778. call assert_equal('",,', @:)
  779. let @s = 'a̳'
  780. call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
  781. call assert_equal('",,', @:)
  782. let @s = 'β̳'
  783. call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
  784. call assert_equal('",,', @:)
  785. if has('arabic')
  786. let @s = 'لا'
  787. call feedkeys(":\"\<C-R>s,,\<C-B>\<Right>\<Del>\<CR>", 'tx')
  788. call assert_equal('",,', @:)
  789. endif
  790. endfunc
  791. func Test_cmdline_keymap_ctrl_hat()
  792. CheckFeature keymap
  793. set keymap=esperanto
  794. call feedkeys(":\"Jxauxdo \<C-^>Jxauxdo \<C-^>Jxauxdo\<CR>", 'tx')
  795. call assert_equal('"Jxauxdo Ĵaŭdo Jxauxdo', @:)
  796. set keymap=
  797. endfunc
  798. func Test_illegal_address1()
  799. new
  800. 2;'(
  801. 2;')
  802. quit
  803. endfunc
  804. func Test_illegal_address2()
  805. call writefile(['c', 'x', ' x', '.', '1;y'], 'Xtest.vim')
  806. new
  807. source Xtest.vim
  808. " Trigger calling validate_cursor()
  809. diffsp Xtest.vim
  810. quit!
  811. bwipe!
  812. call delete('Xtest.vim')
  813. endfunc
  814. func Test_mark_from_line_zero()
  815. " this was reading past the end of the first (empty) line
  816. new
  817. norm oxxxx
  818. call assert_fails("0;'(", 'E20:')
  819. bwipe!
  820. endfunc
  821. func Test_cmdline_complete_wildoptions()
  822. help
  823. call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
  824. let a = join(sort(split(@:)),' ')
  825. set wildoptions=tagfile
  826. call feedkeys(":tag /\<c-a>\<c-b>\"\<cr>", 'tx')
  827. let b = join(sort(split(@:)),' ')
  828. call assert_equal(a, b)
  829. bw!
  830. endfunc
  831. func Test_cmdline_complete_user_cmd()
  832. command! -complete=color -nargs=1 Foo :
  833. call feedkeys(":Foo \<Tab>\<Home>\"\<cr>", 'tx')
  834. call assert_equal('"Foo blue', @:)
  835. call feedkeys(":Foo b\<Tab>\<Home>\"\<cr>", 'tx')
  836. call assert_equal('"Foo blue', @:)
  837. call feedkeys(":Foo a b\<Tab>\<Home>\"\<cr>", 'tx')
  838. call assert_equal('"Foo a blue', @:)
  839. call feedkeys(":Foo b\\\<Tab>\<Home>\"\<cr>", 'tx')
  840. call assert_equal('"Foo b\', @:)
  841. call feedkeys(":Foo b\\x\<Tab>\<Home>\"\<cr>", 'tx')
  842. call assert_equal('"Foo b\x', @:)
  843. delcommand Foo
  844. redraw
  845. call assert_equal('~', Screenline(&lines - 1))
  846. command! FooOne :
  847. command! FooTwo :
  848. set nowildmenu
  849. call feedkeys(":Foo\<Tab>\<Home>\"\<cr>", 'tx')
  850. call assert_equal('"FooOne', @:)
  851. call assert_equal('~', Screenline(&lines - 1))
  852. call feedkeys(":Foo\<S-Tab>\<Home>\"\<cr>", 'tx')
  853. call assert_equal('"FooTwo', @:)
  854. call assert_equal('~', Screenline(&lines - 1))
  855. delcommand FooOne
  856. delcommand FooTwo
  857. set wildmenu&
  858. endfunc
  859. func Test_complete_user_cmd()
  860. command FooBar echo 'global'
  861. command -buffer FooBar echo 'local'
  862. call feedkeys(":Foo\<C-A>\<Home>\"\<CR>", 'tx')
  863. call assert_equal('"FooBar', @:)
  864. delcommand -buffer FooBar
  865. delcommand FooBar
  866. endfunc
  867. func s:ScriptLocalFunction()
  868. echo 'yes'
  869. endfunc
  870. func Test_cmdline_complete_user_func()
  871. call feedkeys(":func Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
  872. call assert_match('"func Test_cmdline_complete_user_', @:)
  873. call feedkeys(":func s:ScriptL\<Tab>\<Home>\"\<cr>", 'tx')
  874. call assert_match('"func <SNR>\d\+_ScriptLocalFunction', @:)
  875. " g: prefix also works
  876. call feedkeys(":echo g:Test_cmdline_complete_user_f\<Tab>\<Home>\"\<cr>", 'tx')
  877. call assert_match('"echo g:Test_cmdline_complete_user_func', @:)
  878. " using g: prefix does not result in just "g:" matches from a lambda
  879. let Fx = { a -> a }
  880. call feedkeys(":echo g:\<Tab>\<Home>\"\<cr>", 'tx')
  881. call assert_match('"echo g:[A-Z]', @:)
  882. " existence of script-local dict function does not break user function name
  883. " completion
  884. function s:a_dict_func() dict
  885. endfunction
  886. call feedkeys(":call Test_cmdline_complete_user\<Tab>\<Home>\"\<cr>", 'tx')
  887. call assert_match('"call Test_cmdline_complete_user_', @:)
  888. delfunction s:a_dict_func
  889. endfunc
  890. func Test_cmdline_complete_user_names()
  891. if has('unix') && executable('whoami')
  892. let whoami = systemlist('whoami')[0]
  893. let first_letter = whoami[0]
  894. if len(first_letter) > 0
  895. " Trying completion of :e ~x where x is the first letter of
  896. " the user name should complete to at least the user name.
  897. call feedkeys(':e ~' . first_letter . "\<c-a>\<c-B>\"\<cr>", 'tx')
  898. call assert_match('^"e \~.*\<' . whoami . '\>', @:)
  899. endif
  900. elseif has('win32')
  901. " Just in case: check that the system has an Administrator account.
  902. let names = system('net user')
  903. if names =~ 'Administrator'
  904. " Trying completion of :e ~A should complete to Administrator.
  905. " There could be other names starting with "A" before Administrator.
  906. call feedkeys(':e ~A' . "\<c-a>\<c-B>\"\<cr>", 'tx')
  907. call assert_match('^"e \~.*Administrator', @:)
  908. endif
  909. else
  910. throw 'Skipped: does not work on this platform'
  911. endif
  912. endfunc
  913. func Test_cmdline_complete_shellcmdline()
  914. CheckExecutable whoami
  915. command -nargs=1 -complete=shellcmdline MyCmd
  916. call feedkeys(":MyCmd whoam\<C-A>\<C-B>\"\<CR>", 'tx')
  917. call assert_match('^".*\<whoami\>', @:)
  918. let l = getcompletion('whoam', 'shellcmdline')
  919. call assert_match('\<whoami\>', join(l, ' '))
  920. delcommand MyCmd
  921. endfunc
  922. func Test_cmdline_complete_bang()
  923. CheckExecutable whoami
  924. call feedkeys(":!whoam\<C-A>\<C-B>\"\<CR>", 'tx')
  925. call assert_match('^".*\<whoami\>', @:)
  926. endfunc
  927. func Test_cmdline_complete_languages()
  928. let lang = substitute(execute('language time'), '.*"\(.*\)"$', '\1', '')
  929. call assert_equal(lang, v:lc_time)
  930. let lang = substitute(execute('language ctype'), '.*"\(.*\)"$', '\1', '')
  931. call assert_equal(lang, v:ctype)
  932. let lang = substitute(execute('language collate'), '.*"\(.*\)"$', '\1', '')
  933. call assert_equal(lang, v:collate)
  934. let lang = substitute(execute('language messages'), '.*"\(.*\)"$', '\1', '')
  935. call assert_equal(lang, v:lang)
  936. call feedkeys(":language \<c-a>\<c-b>\"\<cr>", 'tx')
  937. call assert_match('^"language .*\<collate\>.*\<ctype\>.*\<messages\>.*\<time\>', @:)
  938. if has('unix')
  939. " TODO: these tests don't work on Windows. lang appears to be 'C'
  940. " but C does not appear in the completion. Why?
  941. call assert_match('^"language .*\<' . lang . '\>', @:)
  942. call feedkeys(":language messages \<c-a>\<c-b>\"\<cr>", 'tx')
  943. call assert_match('^"language .*\<' . lang . '\>', @:)
  944. call feedkeys(":language ctype \<c-a>\<c-b>\"\<cr>", 'tx')
  945. call assert_match('^"language .*\<' . lang . '\>', @:)
  946. call feedkeys(":language time \<c-a>\<c-b>\"\<cr>", 'tx')
  947. call assert_match('^"language .*\<' . lang . '\>', @:)
  948. call feedkeys(":language collate \<c-a>\<c-b>\"\<cr>", 'tx')
  949. call assert_match('^"language .*\<' . lang . '\>', @:)
  950. endif
  951. endfunc
  952. func Test_cmdline_complete_env_variable()
  953. let $X_VIM_TEST_COMPLETE_ENV = 'foo'
  954. call feedkeys(":edit $X_VIM_TEST_COMPLETE_E\<C-A>\<C-B>\"\<CR>", 'tx')
  955. call assert_match('"edit $X_VIM_TEST_COMPLETE_ENV', @:)
  956. unlet $X_VIM_TEST_COMPLETE_ENV
  957. endfunc
  958. func Test_cmdline_complete_expression()
  959. let g:SomeVar = 'blah'
  960. for cmd in ['exe', 'echo', 'echon', 'echomsg']
  961. call feedkeys(":" .. cmd .. " SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
  962. call assert_match('"' .. cmd .. ' SomeVar', @:)
  963. call feedkeys(":" .. cmd .. " foo SomeV\<Tab>\<C-B>\"\<CR>", 'tx')
  964. call assert_match('"' .. cmd .. ' foo SomeVar', @:)
  965. endfor
  966. unlet g:SomeVar
  967. endfunc
  968. func Test_cmdline_complete_argopt()
  969. " completion for ++opt=arg for file commands
  970. call assert_equal('fileformat=', getcompletion('edit ++', 'cmdline')[0])
  971. call assert_equal('encoding=', getcompletion('read ++e', 'cmdline')[0])
  972. call assert_equal('edit', getcompletion('read ++bin ++edi', 'cmdline')[0])
  973. call assert_equal(['fileformat='], getcompletion('edit ++ff', 'cmdline'))
  974. " Test ++ff in the middle of the cmdline
  975. call feedkeys(":edit ++ff zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'xt')
  976. call assert_equal("\"edit ++fileformat= zz", @:)
  977. call assert_equal('dos', getcompletion('write ++ff=d', 'cmdline')[0])
  978. call assert_equal('mac', getcompletion('args ++fileformat=m', 'cmdline')[0])
  979. call assert_equal('utf-8', getcompletion('split ++enc=ut*-8', 'cmdline')[0])
  980. call assert_equal('latin1', getcompletion('tabedit ++encoding=lati', 'cmdline')[0])
  981. call assert_equal('keep', getcompletion('edit ++bad=k', 'cmdline')[0])
  982. call assert_equal([], getcompletion('edit ++bogus=', 'cmdline'))
  983. " completion should skip the ++opt and continue
  984. call writefile([], 'Xaaaaa.txt', 'D')
  985. call feedkeys(":split ++enc=latin1 Xaaa\<C-A>\<C-B>\"\<CR>", 'xt')
  986. call assert_equal('"split ++enc=latin1 Xaaaaa.txt', @:)
  987. if has('terminal')
  988. " completion for terminal's [options]
  989. call assert_equal('close', getcompletion('terminal ++cl*e', 'cmdline')[0])
  990. call assert_equal('hidden', getcompletion('terminal ++open ++hidd', 'cmdline')[0])
  991. call assert_equal('term', getcompletion('terminal ++kill=ter', 'cmdline')[0])
  992. call assert_equal([], getcompletion('terminal ++bogus=', 'cmdline'))
  993. " :terminal completion should skip the ++opt when considering what is the
  994. " first option, which is a list of shell commands, unlike second option
  995. " onwards.
  996. let first_param = getcompletion('terminal ', 'cmdline')
  997. let second_param = getcompletion('terminal foo ', 'cmdline')
  998. let skipped_opt_param = getcompletion('terminal ++close ', 'cmdline')
  999. call assert_equal(first_param, skipped_opt_param)
  1000. call assert_notequal(first_param, second_param)
  1001. endif
  1002. endfunc
  1003. " Unique function name for completion below
  1004. func s:WeirdFunc()
  1005. echo 'weird'
  1006. endfunc
  1007. " Test for various command-line completion
  1008. func Test_cmdline_complete_various()
  1009. " completion for a command starting with a comment
  1010. call feedkeys(": :|\"\<C-A>\<C-B>\"\<CR>", 'xt')
  1011. call assert_equal("\" :|\"\<C-A>", @:)
  1012. " completion for a range followed by a comment
  1013. call feedkeys(":1,2\"\<C-A>\<C-B>\"\<CR>", 'xt')
  1014. call assert_equal("\"1,2\"\<C-A>", @:)
  1015. " completion for :k command
  1016. call feedkeys(":ka\<C-A>\<C-B>\"\<CR>", 'xt')
  1017. call assert_equal("\"ka\<C-A>", @:)
  1018. " completion for short version of the :s command
  1019. call feedkeys(":sI \<C-A>\<C-B>\"\<CR>", 'xt')
  1020. call assert_equal("\"sI \<C-A>", @:)
  1021. " completion for :write command
  1022. call mkdir('Xcwdir')
  1023. call writefile(['one'], 'Xcwdir/Xfile1')
  1024. let save_cwd = getcwd()
  1025. cd Xcwdir
  1026. call feedkeys(":w >> \<C-A>\<C-B>\"\<CR>", 'xt')
  1027. call assert_equal("\"w >> Xfile1", @:)
  1028. call chdir(save_cwd)
  1029. call delete('Xcwdir', 'rf')
  1030. " completion for :w ! and :r ! commands
  1031. call feedkeys(":w !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
  1032. call assert_equal("\"w !invalid_xyz_cmd", @:)
  1033. call feedkeys(":r !invalid_xyz_cmd\<C-A>\<C-B>\"\<CR>", 'xt')
  1034. call assert_equal("\"r !invalid_xyz_cmd", @:)
  1035. " completion for :>> and :<< commands
  1036. call feedkeys(":>>>\<C-A>\<C-B>\"\<CR>", 'xt')
  1037. call assert_equal("\">>>\<C-A>", @:)
  1038. call feedkeys(":<<<\<C-A>\<C-B>\"\<CR>", 'xt')
  1039. call assert_equal("\"<<<\<C-A>", @:)
  1040. " completion for command with +cmd argument
  1041. call feedkeys(":buffer +/pat Xabc\<C-A>\<C-B>\"\<CR>", 'xt')
  1042. call assert_equal("\"buffer +/pat Xabc", @:)
  1043. call feedkeys(":buffer +/pat\<C-A>\<C-B>\"\<CR>", 'xt')
  1044. call assert_equal("\"buffer +/pat\<C-A>", @:)
  1045. " completion for a command with a trailing comment
  1046. call feedkeys(":ls \" comment\<C-A>\<C-B>\"\<CR>", 'xt')
  1047. call assert_equal("\"ls \" comment\<C-A>", @:)
  1048. " completion for a command with a trailing command
  1049. call feedkeys(":ls | ls\<C-A>\<C-B>\"\<CR>", 'xt')
  1050. call assert_equal("\"ls | ls", @:)
  1051. " completion for a command with an CTRL-V escaped argument
  1052. call feedkeys(":ls \<C-V>\<C-V>a\<C-A>\<C-B>\"\<CR>", 'xt')
  1053. call assert_equal("\"ls \<C-V>a\<C-A>", @:)
  1054. " completion for a command that doesn't take additional arguments
  1055. call feedkeys(":all abc\<C-A>\<C-B>\"\<CR>", 'xt')
  1056. call assert_equal("\"all abc\<C-A>", @:)
  1057. " completion for :wincmd with :horizontal modifier
  1058. call feedkeys(":horizontal wincm\<C-A>\<C-B>\"\<CR>", 'xt')
  1059. call assert_equal("\"horizontal wincmd", @:)
  1060. " completion for a command with a command modifier
  1061. call feedkeys(":topleft new\<C-A>\<C-B>\"\<CR>", 'xt')
  1062. call assert_equal("\"topleft new", @:)
  1063. " completion for the :match command
  1064. call feedkeys(":match Search /pat/\<C-A>\<C-B>\"\<CR>", 'xt')
  1065. call assert_equal("\"match Search /pat/\<C-A>", @:)
  1066. " completion for the :doautocmd command
  1067. call feedkeys(":doautocmd User MyCmd a.c\<C-A>\<C-B>\"\<CR>", 'xt')
  1068. call assert_equal("\"doautocmd User MyCmd a.c\<C-A>", @:)
  1069. " completion of autocmd group after comma
  1070. call feedkeys(":doautocmd BufNew,BufEn\<C-A>\<C-B>\"\<CR>", 'xt')
  1071. call assert_equal("\"doautocmd BufNew,BufEnter", @:)
  1072. " completion of file name in :doautocmd
  1073. call writefile([], 'Xvarfile1')
  1074. call writefile([], 'Xvarfile2')
  1075. call feedkeys(":doautocmd BufEnter Xvarfi\<C-A>\<C-B>\"\<CR>", 'xt')
  1076. call assert_equal("\"doautocmd BufEnter Xvarfile1 Xvarfile2", @:)
  1077. call delete('Xvarfile1')
  1078. call delete('Xvarfile2')
  1079. " completion for the :augroup command
  1080. augroup XTest.test
  1081. augroup END
  1082. call feedkeys(":augroup X\<C-A>\<C-B>\"\<CR>", 'xt')
  1083. call assert_equal("\"augroup XTest.test", @:)
  1084. call feedkeys(":au X\<C-A>\<C-B>\"\<CR>", 'xt')
  1085. call assert_equal("\"au XTest.test", @:)
  1086. augroup! XTest.test
  1087. " completion for the :unlet command
  1088. call feedkeys(":unlet one two\<C-A>\<C-B>\"\<CR>", 'xt')
  1089. call assert_equal("\"unlet one two", @:)
  1090. " completion for the :buffer command with curlies
  1091. " FIXME: what should happen on MS-Windows?
  1092. if !has('win32')
  1093. edit \{someFile}
  1094. call feedkeys(":buf someFile\<C-A>\<C-B>\"\<CR>", 'xt')
  1095. call assert_equal("\"buf {someFile}", @:)
  1096. bwipe {someFile}
  1097. endif
  1098. " completion for the :bdelete command
  1099. call feedkeys(":bdel a b c\<C-A>\<C-B>\"\<CR>", 'xt')
  1100. call assert_equal("\"bdel a b c", @:)
  1101. " completion for the :mapclear command
  1102. call feedkeys(":mapclear \<C-A>\<C-B>\"\<CR>", 'xt')
  1103. call assert_equal("\"mapclear <buffer>", @:)
  1104. " completion for user defined commands with menu names
  1105. menu Test.foo :ls<CR>
  1106. com -nargs=* -complete=menu MyCmd
  1107. call feedkeys(":MyCmd Te\<C-A>\<C-B>\"\<CR>", 'xt')
  1108. call assert_equal('"MyCmd Test.', @:)
  1109. delcom MyCmd
  1110. unmenu Test
  1111. " completion for user defined commands with mappings
  1112. mapclear
  1113. map <F3> :ls<CR>
  1114. com -nargs=* -complete=mapping MyCmd
  1115. call feedkeys(":MyCmd <F\<C-A>\<C-B>\"\<CR>", 'xt')
  1116. call assert_equal('"MyCmd <F3> <F4>', @:)
  1117. mapclear
  1118. delcom MyCmd
  1119. " Prepare for path completion
  1120. call mkdir('Xa b c', 'D')
  1121. defer delete('Xcomma,foobar.txt')
  1122. call writefile([], 'Xcomma,foobar.txt')
  1123. " completion for :set path= with multiple backslashes
  1124. call feedkeys(':set path=Xa\\\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
  1125. call assert_equal('"set path=Xa\\\ b\\\ c/', @:)
  1126. set path&
  1127. " completion for :set dir= with a backslash
  1128. call feedkeys(':set dir=Xa\ b' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
  1129. call assert_equal('"set dir=Xa\ b\ c/', @:)
  1130. set dir&
  1131. " completion for :set tags= / set dictionary= with escaped commas
  1132. if has('win32')
  1133. " In Windows backslashes are rounded up, so both '\,' and '\\,' escape to
  1134. " '\,'
  1135. call feedkeys(':set dictionary=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
  1136. call assert_equal('"set dictionary=Xcomma\,foobar.txt', @:)
  1137. call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
  1138. call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
  1139. call feedkeys(':set tags=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
  1140. call assert_equal('"set tags=Xcomma\\\,foo', @:) " Didn't find a match
  1141. " completion for :set dictionary= with escaped commas (same behavior, but
  1142. " different internal code path from 'set tags=' for escaping the output)
  1143. call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
  1144. call assert_equal('"set tags=Xcomma\,foobar.txt', @:)
  1145. else
  1146. " In other platforms, backslashes are rounded down (since '\,' itself will
  1147. " be escaped into ','). As a result '\\,' and '\\\,' escape to '\,'.
  1148. call feedkeys(':set tags=Xcomma\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
  1149. call assert_equal('"set tags=Xcomma\,foo', @:) " Didn't find a match
  1150. call feedkeys(':set tags=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
  1151. call assert_equal('"set tags=Xcomma\\,foobar.txt', @:)
  1152. call feedkeys(':set dictionary=Xcomma\\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
  1153. call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
  1154. " completion for :set dictionary= with escaped commas (same behavior, but
  1155. " different internal code path from 'set tags=' for escaping the output)
  1156. call feedkeys(':set dictionary=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
  1157. call assert_equal('"set dictionary=Xcomma\\,foobar.txt', @:)
  1158. endif
  1159. set tags&
  1160. set dictionary&
  1161. " completion for :set makeprg= with no escaped commas
  1162. call feedkeys(':set makeprg=Xcomma,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
  1163. call assert_equal('"set makeprg=Xcomma,foobar.txt', @:)
  1164. if !has('win32')
  1165. " Cannot create file with backslash in file name in Windows, so only test
  1166. " this elsewhere.
  1167. defer delete('Xcomma\,fooslash.txt')
  1168. call writefile([], 'Xcomma\,fooslash.txt')
  1169. call feedkeys(':set makeprg=Xcomma\\,foo' .. "\<C-A>\<C-B>\"\<CR>", 'xt')
  1170. call assert_equal('"set makeprg=Xcomma\\,fooslash.txt', @:)
  1171. endif
  1172. set makeprg&
  1173. " completion for the :py3 commands
  1174. call feedkeys(":py3\<C-A>\<C-B>\"\<CR>", 'xt')
  1175. call assert_equal('"py3 py3do py3file', @:)
  1176. " redir @" is not the start of a comment. So complete after that
  1177. call feedkeys(":redir @\" | cwin\t\<C-B>\"\<CR>", 'xt')
  1178. call assert_equal('"redir @" | cwindow', @:)
  1179. " completion after a backtick
  1180. call feedkeys(":e `a1b2c\t\<C-B>\"\<CR>", 'xt')
  1181. call assert_equal('"e `a1b2c', @:)
  1182. " completion for :language command with an invalid argument
  1183. call feedkeys(":language dummy \t\<C-B>\"\<CR>", 'xt')
  1184. call assert_equal("\"language dummy \t", @:)
  1185. " completion for commands after a :global command
  1186. call feedkeys(":g/a\\xb/clearj\t\<C-B>\"\<CR>", 'xt')
  1187. call assert_equal('"g/a\xb/clearjumps', @:)
  1188. " completion with ambiguous user defined commands
  1189. com TCmd1 echo 'TCmd1'
  1190. com TCmd2 echo 'TCmd2'
  1191. call feedkeys(":TCmd \t\<C-B>\"\<CR>", 'xt')
  1192. call assert_equal('"TCmd ', @:)
  1193. delcom TCmd1
  1194. delcom TCmd2
  1195. " completion after a range followed by a pipe (|) character
  1196. call feedkeys(":1,10 | chist\t\<C-B>\"\<CR>", 'xt')
  1197. call assert_equal('"1,10 | chistory', @:)
  1198. " completion after a :global command
  1199. call feedkeys(":g/a/chist\t\<C-B>\"\<CR>", 'xt')
  1200. call assert_equal('"g/a/chistory', @:)
  1201. call feedkeys(":g/a\\/chist\t\<C-B>\"\<CR>", 'xt')
  1202. call assert_equal("\"g/a\\/chist\t", @:)
  1203. " use <Esc> as the 'wildchar' for completion
  1204. set wildchar=<Esc>
  1205. call feedkeys(":g/a\\xb/clearj\<Esc>\<C-B>\"\<CR>", 'xt')
  1206. call assert_equal('"g/a\xb/clearjumps', @:)
  1207. " pressing <esc> twice should cancel the command
  1208. call feedkeys(":chist\<Esc>\<Esc>", 'xt')
  1209. call assert_equal('"g/a\xb/clearjumps', @:)
  1210. set wildchar&
  1211. if has('unix')
  1212. " should be able to complete a file name that starts with a '~'.
  1213. call writefile([], '~Xtest')
  1214. call feedkeys(":e \\~X\<Tab>\<C-B>\"\<CR>", 'xt')
  1215. call assert_equal('"e \~Xtest', @:)
  1216. call delete('~Xtest')
  1217. " should be able to complete a file name that has a '*'
  1218. call writefile([], 'Xx*Yy')
  1219. call feedkeys(":e Xx\*\<Tab>\<C-B>\"\<CR>", 'xt')
  1220. call assert_equal('"e Xx\*Yy', @:)
  1221. call delete('Xx*Yy')
  1222. " use a literal star
  1223. call feedkeys(":e \\*\<Tab>\<C-B>\"\<CR>", 'xt')
  1224. call assert_equal('"e \*', @:)
  1225. endif
  1226. call feedkeys(":py3f\<Tab>\<C-B>\"\<CR>", 'xt')
  1227. call assert_equal('"py3file', @:)
  1228. endfunc
  1229. " Test that expanding a pattern doesn't interfere with cmdline completion.
  1230. func Test_expand_during_cmdline_completion()
  1231. func ExpandStuff()
  1232. badd <script>:p:h/README.*
  1233. call assert_equal(expand('<script>:p:h') .. '/README.txt', bufname('$'))
  1234. $bwipe
  1235. call assert_equal('README.txt', expand('README.*'))
  1236. call assert_equal(['README.txt'], getcompletion('README.*', 'file'))
  1237. endfunc
  1238. augroup test_CmdlineChanged
  1239. autocmd!
  1240. autocmd CmdlineChanged * call ExpandStuff()
  1241. augroup END
  1242. call feedkeys(":sign \<Tab>\<Tab>\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
  1243. call assert_equal('"sign place', @:)
  1244. augroup test_CmdlineChanged
  1245. au!
  1246. augroup END
  1247. augroup! test_CmdlineChanged
  1248. delfunc ExpandStuff
  1249. endfunc
  1250. " Test for 'wildignorecase'
  1251. func Test_cmdline_wildignorecase()
  1252. CheckUnix
  1253. call writefile([], 'XTEST')
  1254. set wildignorecase
  1255. call feedkeys(":e xt\<Tab>\<C-B>\"\<CR>", 'xt')
  1256. call assert_equal('"e XTEST', @:)
  1257. call assert_equal(['XTEST'], getcompletion('xt', 'file'))
  1258. let g:Sline = ''
  1259. call feedkeys(":e xt\<C-d>\<F4>\<C-B>\"\<CR>", 'xt')
  1260. call assert_equal('"e xt', @:)
  1261. call assert_equal('XTEST', g:Sline)
  1262. set wildignorecase&
  1263. call delete('XTEST')
  1264. endfunc
  1265. func Test_cmdline_write_alternatefile()
  1266. new
  1267. call setline('.', ['one', 'two'])
  1268. f foo.txt
  1269. new
  1270. f #-A
  1271. call assert_equal('foo.txt-A', expand('%'))
  1272. f #<-B.txt
  1273. call assert_equal('foo-B.txt', expand('%'))
  1274. f %<
  1275. call assert_equal('foo-B', expand('%'))
  1276. new
  1277. call assert_fails('f #<', 'E95')
  1278. bw!
  1279. f foo-B.txt
  1280. f %<-A
  1281. call assert_equal('foo-B-A', expand('%'))
  1282. bw!
  1283. bw!
  1284. endfunc
  1285. func Test_cmdline_expand_cur_alt_file()
  1286. enew
  1287. file http://some.com/file.txt
  1288. call feedkeys(":e %\<Tab>\<C-B>\"\<CR>", 'xt')
  1289. call assert_equal('"e http://some.com/file.txt', @:)
  1290. edit another
  1291. call feedkeys(":e #\<Tab>\<C-B>\"\<CR>", 'xt')
  1292. call assert_equal('"e http://some.com/file.txt', @:)
  1293. bwipe
  1294. bwipe http://some.com/file.txt
  1295. endfunc
  1296. " using a leading backslash here
  1297. set cpo+=C
  1298. func Test_cmdline_search_range()
  1299. new
  1300. call setline(1, ['a', 'b', 'c', 'd'])
  1301. /d
  1302. 1,\/s/b/B/
  1303. call assert_equal('B', getline(2))
  1304. /a
  1305. $
  1306. \?,4s/c/C/
  1307. call assert_equal('C', getline(3))
  1308. call setline(1, ['a', 'b', 'c', 'd'])
  1309. %s/c/c/
  1310. 1,\&s/b/B/
  1311. call assert_equal('B', getline(2))
  1312. let @/ = 'apple'
  1313. call assert_fails('\/print', ['E486:.*apple'])
  1314. bwipe!
  1315. endfunc
  1316. " Test for the tick mark (') in an excmd range
  1317. func Test_tick_mark_in_range()
  1318. " If only the tick is passed as a range and no command is specified, there
  1319. " should not be an error
  1320. call feedkeys(":'\<CR>", 'xt')
  1321. call assert_equal("'", @:)
  1322. call assert_fails("',print", 'E78:')
  1323. endfunc
  1324. " Test for using a line number followed by a search pattern as range
  1325. func Test_lnum_and_pattern_as_range()
  1326. new
  1327. call setline(1, ['foo 1', 'foo 2', 'foo 3'])
  1328. let @" = ''
  1329. 2/foo/yank
  1330. call assert_equal("foo 3\n", @")
  1331. call assert_equal(1, line('.'))
  1332. close!
  1333. endfunc
  1334. " Tests for getcmdline(), getcmdpos() and getcmdtype()
  1335. func Check_cmdline(cmdtype)
  1336. call assert_equal('MyCmd a', getcmdline())
  1337. call assert_equal(8, getcmdpos())
  1338. call assert_equal(a:cmdtype, getcmdtype())
  1339. return ''
  1340. endfunc
  1341. set cpo&
  1342. func Test_getcmdtype_getcmdprompt()
  1343. call feedkeys(":MyCmd a\<C-R>=Check_cmdline(':')\<CR>\<Esc>", "xt")
  1344. let cmdtype = ''
  1345. debuggreedy
  1346. call feedkeys(":debug echo 'test'\<CR>", "t")
  1347. call feedkeys("let cmdtype = \<C-R>=string(getcmdtype())\<CR>\<CR>", "t")
  1348. call feedkeys("cont\<CR>", "xt")
  1349. 0debuggreedy
  1350. call assert_equal('>', cmdtype)
  1351. call feedkeys("/MyCmd a\<C-R>=Check_cmdline('/')\<CR>\<Esc>", "xt")
  1352. call feedkeys("?MyCmd a\<C-R>=Check_cmdline('?')\<CR>\<Esc>", "xt")
  1353. call feedkeys(":call input('Answer?')\<CR>", "t")
  1354. call feedkeys("MyCmd a\<C-R>=Check_cmdline('@')\<CR>\<C-C>", "xt")
  1355. call feedkeys(":insert\<CR>MyCmd a\<C-R>=Check_cmdline('-')\<CR>\<Esc>", "xt")
  1356. cnoremap <expr> <F6> Check_cmdline('=')
  1357. call feedkeys("a\<C-R>=MyCmd a\<F6>\<Esc>\<Esc>", "xt")
  1358. cunmap <F6>
  1359. call assert_equal('', getcmdline())
  1360. call assert_equal('', getcmdprompt())
  1361. augroup test_CmdlineEnter
  1362. autocmd!
  1363. autocmd CmdlineEnter * let g:cmdprompt=getcmdprompt()
  1364. augroup END
  1365. call feedkeys(":call input('Answer?')\<CR>a\<CR>\<ESC>", "xt")
  1366. call assert_equal('Answer?', g:cmdprompt)
  1367. call assert_equal('', getcmdprompt())
  1368. call feedkeys(":\<CR>\<ESC>", "xt")
  1369. call assert_equal('', g:cmdprompt)
  1370. call assert_equal('', getcmdprompt())
  1371. let str = "C" .. repeat("c", 1023) .. "xyz"
  1372. call feedkeys(":call input('" .. str .. "')\<CR>\<CR>\<ESC>", "xt")
  1373. call assert_equal(str, g:cmdprompt)
  1374. call feedkeys(':call input("Msg1\nMessage2\nAns?")' .. "\<CR>b\<CR>\<ESC>", "xt")
  1375. call assert_equal('Ans?', g:cmdprompt)
  1376. call assert_equal('', getcmdprompt())
  1377. augroup test_CmdlineEnter
  1378. au!
  1379. augroup END
  1380. augroup! test_CmdlineEnter
  1381. endfunc
  1382. func Test_getcmdwintype()
  1383. call feedkeys("q/:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
  1384. call assert_equal('/', a)
  1385. call feedkeys("q?:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
  1386. call assert_equal('?', a)
  1387. call feedkeys("q::let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
  1388. call assert_equal(':', a)
  1389. call feedkeys(":\<C-F>:let a = getcmdwintype()\<CR>:q\<CR>", 'x!')
  1390. call assert_equal(':', a)
  1391. call assert_equal('', getcmdwintype())
  1392. endfunc
  1393. func Test_getcmdwin_autocmd()
  1394. let s:seq = []
  1395. augroup CmdWin
  1396. au WinEnter * call add(s:seq, 'WinEnter ' .. win_getid())
  1397. au WinLeave * call add(s:seq, 'WinLeave ' .. win_getid())
  1398. au BufEnter * call add(s:seq, 'BufEnter ' .. bufnr())
  1399. au BufLeave * call add(s:seq, 'BufLeave ' .. bufnr())
  1400. au CmdWinEnter * call add(s:seq, 'CmdWinEnter ' .. win_getid())
  1401. au CmdWinLeave * call add(s:seq, 'CmdWinLeave ' .. win_getid())
  1402. let org_winid = win_getid()
  1403. let org_bufnr = bufnr()
  1404. call feedkeys("q::let a = getcmdwintype()\<CR>:let s:cmd_winid = win_getid()\<CR>:let s:cmd_bufnr = bufnr()\<CR>:q\<CR>", 'x!')
  1405. call assert_equal(':', a)
  1406. call assert_equal([
  1407. \ 'WinLeave ' .. org_winid,
  1408. \ 'WinEnter ' .. s:cmd_winid,
  1409. \ 'BufLeave ' .. org_bufnr,
  1410. \ 'BufEnter ' .. s:cmd_bufnr,
  1411. \ 'CmdWinEnter ' .. s:cmd_winid,
  1412. \ 'CmdWinLeave ' .. s:cmd_winid,
  1413. \ 'BufLeave ' .. s:cmd_bufnr,
  1414. \ 'WinLeave ' .. s:cmd_winid,
  1415. \ 'WinEnter ' .. org_winid,
  1416. \ 'BufEnter ' .. org_bufnr,
  1417. \ ], s:seq)
  1418. au!
  1419. augroup END
  1420. endfunc
  1421. func Test_verbosefile()
  1422. set verbosefile=Xlog
  1423. echomsg 'foo'
  1424. echomsg 'bar'
  1425. set verbosefile=
  1426. let log = readfile('Xlog')
  1427. call assert_match("foo\nbar", join(log, "\n"))
  1428. call delete('Xlog')
  1429. call mkdir('Xdir')
  1430. if !has('win32') " FIXME: no error on Windows, libuv bug?
  1431. call assert_fails('set verbosefile=Xdir', ['E484:.*Xdir', 'E474:'])
  1432. endif
  1433. call delete('Xdir', 'd')
  1434. endfunc
  1435. func Test_verbose_option()
  1436. " See test/functional/legacy/cmdline_spec.lua
  1437. CheckScreendump
  1438. let lines =<< trim [SCRIPT]
  1439. command DoSomething echo 'hello' |set ts=4 |let v = '123' |echo v
  1440. call feedkeys("\r", 't') " for the hit-enter prompt
  1441. set verbose=20
  1442. [SCRIPT]
  1443. call writefile(lines, 'XTest_verbose')
  1444. let buf = RunVimInTerminal('-S XTest_verbose', {'rows': 12})
  1445. call TermWait(buf, 50)
  1446. call term_sendkeys(buf, ":DoSomething\<CR>")
  1447. call VerifyScreenDump(buf, 'Test_verbose_option_1', {})
  1448. " clean up
  1449. call StopVimInTerminal(buf)
  1450. call delete('XTest_verbose')
  1451. endfunc
  1452. func Test_setcmdpos()
  1453. func InsertTextAtPos(text, pos)
  1454. call assert_equal(0, setcmdpos(a:pos))
  1455. return a:text
  1456. endfunc
  1457. " setcmdpos() with position in the middle of the command line.
  1458. call feedkeys(":\"12\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
  1459. call assert_equal('"1ab2', @:)
  1460. call feedkeys(":\"12\<C-R>\<C-R>=InsertTextAtPos('a', 3)\<CR>b\<CR>", 'xt')
  1461. call assert_equal('"1b2a', @:)
  1462. " setcmdpos() with position beyond the end of the command line.
  1463. call feedkeys(":\"12\<C-B>\<C-R>=InsertTextAtPos('a', 10)\<CR>b\<CR>", 'xt')
  1464. call assert_equal('"12ab', @:)
  1465. " setcmdpos() returns 1 when not editing the command line.
  1466. call assert_equal(1, 3->setcmdpos())
  1467. endfunc
  1468. func Test_cmdline_overstrike()
  1469. " Nvim: only utf8 is supported.
  1470. let encodings = ['utf8']
  1471. let encoding_save = &encoding
  1472. for e in encodings
  1473. exe 'set encoding=' . e
  1474. " Test overstrike in the middle of the command line.
  1475. call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
  1476. call assert_equal('"0ab1cd4', @:, e)
  1477. " Test overstrike going beyond end of command line.
  1478. call feedkeys(":\"01234\<home>\<right>\<right>ab\<right>\<insert>cdefgh\<enter>", 'xt')
  1479. call assert_equal('"0ab1cdefgh', @:, e)
  1480. " Test toggling insert/overstrike a few times.
  1481. call feedkeys(":\"01234\<home>\<right>ab\<right>\<insert>cd\<right>\<insert>ef\<enter>", 'xt')
  1482. call assert_equal('"ab0cd3ef4', @:, e)
  1483. endfor
  1484. " Test overstrike with multi-byte characters.
  1485. call feedkeys(":\"テキストエディタ\<home>\<right>\<right>ab\<right>\<insert>cd\<enter>", 'xt')
  1486. call assert_equal('"テabキcdエディタ', @:, e)
  1487. let &encoding = encoding_save
  1488. endfunc
  1489. func Test_cmdwin_bug()
  1490. let winid = win_getid()
  1491. sp
  1492. try
  1493. call feedkeys("q::call win_gotoid(" .. winid .. ")\<CR>:q\<CR>", 'x!')
  1494. catch /^Vim\%((\a\+)\)\=:E11/
  1495. endtry
  1496. bw!
  1497. endfunc
  1498. func Test_cmdwin_restore()
  1499. CheckScreendump
  1500. let lines =<< trim [SCRIPT]
  1501. call setline(1, range(30))
  1502. 2split
  1503. [SCRIPT]
  1504. call writefile(lines, 'XTest_restore')
  1505. let buf = RunVimInTerminal('-S XTest_restore', {'rows': 12})
  1506. call TermWait(buf, 50)
  1507. call term_sendkeys(buf, "q:")
  1508. call VerifyScreenDump(buf, 'Test_cmdwin_restore_1', {})
  1509. " normal restore
  1510. call term_sendkeys(buf, ":q\<CR>")
  1511. call VerifyScreenDump(buf, 'Test_cmdwin_restore_2', {})
  1512. " restore after setting 'lines' with one window
  1513. call term_sendkeys(buf, ":close\<CR>")
  1514. call term_sendkeys(buf, "q:")
  1515. call term_sendkeys(buf, ":set lines=18\<CR>")
  1516. call term_sendkeys(buf, ":q\<CR>")
  1517. call VerifyScreenDump(buf, 'Test_cmdwin_restore_3', {})
  1518. " clean up
  1519. call StopVimInTerminal(buf)
  1520. call delete('XTest_restore')
  1521. endfunc
  1522. func Test_cmdwin_no_terminal()
  1523. CheckFeature cmdwin
  1524. CheckFeature terminal
  1525. CheckNotMSWindows
  1526. let buf = RunVimInTerminal('', {'rows': 12})
  1527. call TermWait(buf, 50)
  1528. call term_sendkeys(buf, ":set cmdheight=2\<CR>")
  1529. call term_sendkeys(buf, "q:")
  1530. call term_sendkeys(buf, ":let buf = term_start(['/bin/echo'], #{hidden: 1})\<CR>")
  1531. call VerifyScreenDump(buf, 'Test_cmdwin_no_terminal', {})
  1532. call term_sendkeys(buf, ":q\<CR>")
  1533. call StopVimInTerminal(buf)
  1534. endfunc
  1535. func Test_buffers_lastused()
  1536. " check that buffers are sorted by time when wildmode has lastused
  1537. edit bufc " oldest
  1538. sleep 1200m
  1539. enew
  1540. edit bufa " middle
  1541. sleep 1200m
  1542. enew
  1543. edit bufb " newest
  1544. enew
  1545. call assert_equal(['bufc', 'bufa', 'bufb'],
  1546. \ getcompletion('', 'buffer'))
  1547. let save_wildmode = &wildmode
  1548. set wildmode=full:lastused
  1549. let cap = "\<c-r>=execute('let X=getcmdline()')\<cr>"
  1550. call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
  1551. call assert_equal('b bufb', X)
  1552. call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
  1553. call assert_equal('b bufa', X)
  1554. call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
  1555. call assert_equal('b bufc', X)
  1556. enew
  1557. sleep 1200m
  1558. edit other
  1559. call feedkeys(":b \<tab>" .. cap .. "\<esc>", 'xt')
  1560. call assert_equal('b bufb', X)
  1561. call feedkeys(":b \<tab>\<tab>" .. cap .. "\<esc>", 'xt')
  1562. call assert_equal('b bufa', X)
  1563. call feedkeys(":b \<tab>\<tab>\<tab>" .. cap .. "\<esc>", 'xt')
  1564. call assert_equal('b bufc', X)
  1565. enew
  1566. let &wildmode = save_wildmode
  1567. bwipeout bufa
  1568. bwipeout bufb
  1569. bwipeout bufc
  1570. endfunc
  1571. func Test_cmdwin_feedkeys()
  1572. " This should not generate E488
  1573. call feedkeys("q:\<CR>", 'x')
  1574. " Using feedkeys with q: only should automatically close the cmd window
  1575. call feedkeys('q:', 'xt')
  1576. call assert_equal(1, winnr('$'))
  1577. call assert_equal('', getcmdwintype())
  1578. endfunc
  1579. " Tests for the issues fixed in 7.4.441.
  1580. " When 'cedit' is set to Ctrl-C, opening the command window hangs Vim
  1581. func Test_cmdwin_cedit()
  1582. exe "set cedit=\<C-c>"
  1583. normal! :
  1584. call assert_equal(1, winnr('$'))
  1585. let g:cmd_wintype = ''
  1586. func CmdWinType()
  1587. let g:cmd_wintype = getcmdwintype()
  1588. let g:wintype = win_gettype()
  1589. return ''
  1590. endfunc
  1591. call feedkeys("\<C-c>a\<C-R>=CmdWinType()\<CR>\<CR>")
  1592. echo input('')
  1593. call assert_equal('@', g:cmd_wintype)
  1594. call assert_equal('command', g:wintype)
  1595. set cedit&vim
  1596. delfunc CmdWinType
  1597. endfunc
  1598. " Test for CmdwinEnter autocmd
  1599. func Test_cmdwin_autocmd()
  1600. CheckFeature cmdwin
  1601. augroup CmdWin
  1602. au!
  1603. autocmd BufLeave * if &buftype == '' | update | endif
  1604. autocmd CmdwinEnter * startinsert
  1605. augroup END
  1606. call assert_fails('call feedkeys("q:xyz\<CR>", "xt")', 'E492:')
  1607. call assert_equal('xyz', @:)
  1608. augroup CmdWin
  1609. au!
  1610. augroup END
  1611. augroup! CmdWin
  1612. endfunc
  1613. func Test_cmdlineclear_tabenter()
  1614. " See test/functional/legacy/cmdline_spec.lua
  1615. CheckScreendump
  1616. let lines =<< trim [SCRIPT]
  1617. call setline(1, range(30))
  1618. [SCRIPT]
  1619. call writefile(lines, 'XtestCmdlineClearTabenter')
  1620. let buf = RunVimInTerminal('-S XtestCmdlineClearTabenter', #{rows: 10})
  1621. call TermWait(buf, 25)
  1622. " in one tab make the command line higher with CTRL-W -
  1623. call term_sendkeys(buf, ":tabnew\<cr>\<C-w>-\<C-w>-gtgt")
  1624. call VerifyScreenDump(buf, 'Test_cmdlineclear_tabenter', {})
  1625. call StopVimInTerminal(buf)
  1626. call delete('XtestCmdlineClearTabenter')
  1627. endfunc
  1628. " Test for expanding special keywords in cmdline
  1629. func Test_cmdline_expand_special()
  1630. new
  1631. %bwipe!
  1632. call assert_fails('e #', 'E194:')
  1633. call assert_fails('e <afile>', 'E495:')
  1634. call assert_fails('e <abuf>', 'E496:')
  1635. call assert_fails('e <amatch>', 'E497:')
  1636. call writefile([], 'Xfile.cpp')
  1637. call writefile([], 'Xfile.java')
  1638. new Xfile.cpp
  1639. call feedkeys(":e %:r\<C-A>\<C-B>\"\<CR>", 'xt')
  1640. call assert_equal('"e Xfile.cpp Xfile.java', @:)
  1641. close
  1642. call delete('Xfile.cpp')
  1643. call delete('Xfile.java')
  1644. endfunc
  1645. func Test_cmdwin_jump_to_win()
  1646. call assert_fails('call feedkeys("q:\<C-W>\<C-W>\<CR>", "xt")', 'E11:')
  1647. new
  1648. set modified
  1649. call assert_fails('call feedkeys("q/:qall\<CR>", "xt")', ['E37:', 'E162:'])
  1650. close!
  1651. call feedkeys("q/:close\<CR>", "xt")
  1652. call assert_equal(1, winnr('$'))
  1653. call feedkeys("q/:exit\<CR>", "xt")
  1654. call assert_equal(1, winnr('$'))
  1655. " opening command window twice should fail
  1656. call assert_beeps('call feedkeys("q:q:\<CR>\<CR>", "xt")')
  1657. call assert_equal(1, winnr('$'))
  1658. endfunc
  1659. func Test_cmdwin_tabpage()
  1660. tabedit
  1661. call assert_fails("silent norm q/g :I\<Esc>", 'E11:')
  1662. tabclose!
  1663. endfunc
  1664. func Test_cmdwin_interrupted_more_prompt()
  1665. CheckScreendump
  1666. " aborting the :smile output caused the cmdline window to use the current
  1667. " buffer.
  1668. let lines =<< trim [SCRIPT]
  1669. au WinNew * smile
  1670. [SCRIPT]
  1671. call writefile(lines, 'XTest_cmdwin')
  1672. let buf = RunVimInTerminal('-S XTest_cmdwin', {'rows': 18})
  1673. " open cmdwin
  1674. call term_sendkeys(buf, "q:")
  1675. call WaitForAssert({-> assert_match('-- More --', term_getline(buf, 18))})
  1676. " quit more prompt for :smile command
  1677. call term_sendkeys(buf, "q")
  1678. call WaitForAssert({-> assert_match('^$', term_getline(buf, 18))})
  1679. " execute a simple command
  1680. call term_sendkeys(buf, "aecho 'done'\<CR>")
  1681. call VerifyScreenDump(buf, 'Test_cmdwin_interrupted', {})
  1682. " clean up
  1683. call StopVimInTerminal(buf)
  1684. call delete('XTest_cmdwin')
  1685. endfunc
  1686. " Test for backtick expression in the command line
  1687. func Test_cmd_backtick()
  1688. CheckNotMSWindows " FIXME: see #19297
  1689. %argd
  1690. argadd `=['a', 'b', 'c']`
  1691. call assert_equal(['a', 'b', 'c'], argv())
  1692. %argd
  1693. argadd `echo abc def`
  1694. call assert_equal(['abc def'], argv())
  1695. %argd
  1696. endfunc
  1697. " Test for the :! command
  1698. func Test_cmd_bang()
  1699. CheckUnix
  1700. let lines =<< trim [SCRIPT]
  1701. " Test for no previous command
  1702. call assert_fails('!!', 'E34:')
  1703. set nomore
  1704. " Test for cmdline expansion with :!
  1705. call setline(1, 'foo!')
  1706. silent !echo <cWORD> > Xfile.out
  1707. call assert_equal(['foo!'], readfile('Xfile.out'))
  1708. " Test for using previous command
  1709. silent !echo \! !
  1710. call assert_equal(['! echo foo!'], readfile('Xfile.out'))
  1711. call writefile(v:errors, 'Xresult')
  1712. call delete('Xfile.out')
  1713. qall!
  1714. [SCRIPT]
  1715. call writefile(lines, 'Xscript')
  1716. if RunVim([], [], '--clean -S Xscript')
  1717. call assert_equal([], readfile('Xresult'))
  1718. endif
  1719. call delete('Xscript')
  1720. call delete('Xresult')
  1721. endfunc
  1722. " Test error: "E135: *Filter* Autocommands must not change current buffer"
  1723. func Test_cmd_bang_E135()
  1724. new
  1725. call setline(1, ['a', 'b', 'c', 'd'])
  1726. augroup test_cmd_filter_E135
  1727. au!
  1728. autocmd FilterReadPost * help
  1729. augroup END
  1730. call assert_fails('2,3!echo "x"', 'E135:')
  1731. augroup test_cmd_filter_E135
  1732. au!
  1733. augroup END
  1734. augroup! test_cmd_filter_E135
  1735. %bwipe!
  1736. endfunc
  1737. func Test_cmd_bang_args()
  1738. new
  1739. :.!
  1740. call assert_equal(0, v:shell_error)
  1741. " Note that below there is one space char after the '!'. This caused a
  1742. " shell error in the past, see https://github.com/vim/vim/issues/11495.
  1743. :.!
  1744. call assert_equal(0, v:shell_error)
  1745. bwipe!
  1746. CheckUnix
  1747. :.!pwd
  1748. call assert_equal(0, v:shell_error)
  1749. :.! pwd
  1750. call assert_equal(0, v:shell_error)
  1751. " Note there is one space after 'pwd'.
  1752. :.! pwd
  1753. call assert_equal(0, v:shell_error)
  1754. " Note there are two spaces after 'pwd'.
  1755. :.! pwd
  1756. call assert_equal(0, v:shell_error)
  1757. :.!ls ~
  1758. call assert_equal(0, v:shell_error)
  1759. " Note there is one space char after '~'.
  1760. :.!ls ~
  1761. call assert_equal(0, v:shell_error)
  1762. " Note there are two spaces after '~'.
  1763. :.!ls ~
  1764. call assert_equal(0, v:shell_error)
  1765. :.!echo "foo"
  1766. call assert_equal(getline('.'), "foo")
  1767. :.!echo "foo "
  1768. call assert_equal(getline('.'), "foo ")
  1769. :.!echo " foo "
  1770. call assert_equal(getline('.'), " foo ")
  1771. :.!echo " foo "
  1772. call assert_equal(getline('.'), " foo ")
  1773. %bwipe!
  1774. endfunc
  1775. " Test for using ~ for home directory in cmdline completion matches
  1776. func Test_cmdline_expand_home()
  1777. call mkdir('Xexpdir')
  1778. call writefile([], 'Xexpdir/Xfile1')
  1779. call writefile([], 'Xexpdir/Xfile2')
  1780. cd Xexpdir
  1781. let save_HOME = $HOME
  1782. let $HOME = getcwd()
  1783. call feedkeys(":e ~/\<C-A>\<C-B>\"\<CR>", 'xt')
  1784. call assert_equal('"e ~/Xfile1 ~/Xfile2', @:)
  1785. let $HOME = save_HOME
  1786. cd ..
  1787. call delete('Xexpdir', 'rf')
  1788. endfunc
  1789. " Test for using CTRL-\ CTRL-G in the command line to go back to normal mode
  1790. " or insert mode (when 'insertmode' is set)
  1791. func Test_cmdline_ctrl_g()
  1792. new
  1793. call setline(1, 'abc')
  1794. call cursor(1, 3)
  1795. " If command line is entered from insert mode, using C-\ C-G should back to
  1796. " insert mode
  1797. call feedkeys("i\<C-O>:\<C-\>\<C-G>xy", 'xt')
  1798. call assert_equal('abxyc', getline(1))
  1799. call assert_equal(4, col('.'))
  1800. " If command line is entered in 'insertmode', using C-\ C-G should back to
  1801. " 'insertmode'
  1802. " call feedkeys(":set im\<cr>\<C-L>:\<C-\>\<C-G>12\<C-L>:set noim\<cr>", 'xt')
  1803. " call assert_equal('ab12xyc', getline(1))
  1804. close!
  1805. endfunc
  1806. " Test for 'wildmode'
  1807. func Wildmode_tests()
  1808. func T(a, c, p)
  1809. return "oneA\noneB\noneC"
  1810. endfunc
  1811. command -nargs=1 -complete=custom,T MyCmd
  1812. set nowildmenu
  1813. set wildmode=full,list
  1814. let g:Sline = ''
  1815. call feedkeys(":MyCmd \t\t\<F4>\<C-B>\"\<CR>", 'xt')
  1816. call assert_equal('oneA oneB oneC', g:Sline)
  1817. call assert_equal('"MyCmd oneA', @:)
  1818. set wildmode=longest,full
  1819. call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
  1820. call assert_equal('"MyCmd one', @:)
  1821. call feedkeys(":MyCmd o\t\t\t\t\<C-B>\"\<CR>", 'xt')
  1822. call assert_equal('"MyCmd oneC', @:)
  1823. set wildmode=longest
  1824. call feedkeys(":MyCmd one\t\t\<C-B>\"\<CR>", 'xt')
  1825. call assert_equal('"MyCmd one', @:)
  1826. set wildmode=list:longest
  1827. let g:Sline = ''
  1828. call feedkeys(":MyCmd \t\<F4>\<C-B>\"\<CR>", 'xt')
  1829. call assert_equal('oneA oneB oneC', g:Sline)
  1830. call assert_equal('"MyCmd one', @:)
  1831. set wildmode=""
  1832. call feedkeys(":MyCmd \t\t\<C-B>\"\<CR>", 'xt')
  1833. call assert_equal('"MyCmd oneA', @:)
  1834. " Test for wildmode=longest with 'fileignorecase' set
  1835. set wildmode=longest
  1836. set fileignorecase
  1837. argadd AAA AAAA AAAAA
  1838. call feedkeys(":buffer a\t\<C-B>\"\<CR>", 'xt')
  1839. call assert_equal('"buffer AAA', @:)
  1840. set fileignorecase&
  1841. " Test for listing files with wildmode=list
  1842. set wildmode=list
  1843. let g:Sline = ''
  1844. call feedkeys(":b A\t\t\<F4>\<C-B>\"\<CR>", 'xt')
  1845. call assert_equal('AAA AAAA AAAAA', g:Sline)
  1846. call assert_equal('"b A', @:)
  1847. " When 'wildmenu' is not set, 'noselect' completes first item
  1848. set wildmode=noselect
  1849. call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
  1850. call assert_equal('"MyCmd oneA', @:)
  1851. " When 'noselect' is present, do not complete first <tab>.
  1852. set wildmenu
  1853. set wildmode=noselect
  1854. call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
  1855. call assert_equal('"MyCmd o', @:)
  1856. call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt')
  1857. call assert_equal('"MyCmd o', @:)
  1858. call feedkeys(":MyCmd o\t\t\<C-Y>\<C-B>\"\<CR>", 'xt')
  1859. call assert_equal('"MyCmd o', @:)
  1860. " When 'full' is present, complete after first <tab>.
  1861. set wildmode=noselect,full
  1862. call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
  1863. call assert_equal('"MyCmd o', @:)
  1864. call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt')
  1865. call assert_equal('"MyCmd oneA', @:)
  1866. call feedkeys(":MyCmd o\t\t\t\<C-B>\"\<CR>", 'xt')
  1867. call assert_equal('"MyCmd oneB', @:)
  1868. call feedkeys(":MyCmd o\t\t\t\<C-Y>\<C-B>\"\<CR>", 'xt')
  1869. call assert_equal('"MyCmd oneB', @:)
  1870. " 'noselect' has no effect when 'longest' is present.
  1871. set wildmode=noselect:longest
  1872. call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
  1873. call assert_equal('"MyCmd one', @:)
  1874. " Complete 'noselect' value in 'wildmode' option
  1875. set wildmode&
  1876. call feedkeys(":set wildmode=n\t\<C-B>\"\<CR>", 'xt')
  1877. call assert_equal('"set wildmode=noselect', @:)
  1878. call feedkeys(":set wildmode=\t\t\t\t\t\<C-B>\"\<CR>", 'xt')
  1879. call assert_equal('"set wildmode=noselect', @:)
  1880. " when using longest completion match, matches shorter than the argument
  1881. " should be ignored (happens with :help)
  1882. set wildmode=longest,full
  1883. call feedkeys(":help a*\t\<C-B>\"\<CR>", 'xt')
  1884. call assert_equal('"help a', @:)
  1885. " non existing file
  1886. call feedkeys(":e a1b2y3z4\t\<C-B>\"\<CR>", 'xt')
  1887. call assert_equal('"e a1b2y3z4', @:)
  1888. " Test for longest file name completion with 'fileignorecase'
  1889. " On MS-Windows, file names are case insensitive.
  1890. if has('unix')
  1891. call writefile([], 'XTESTfoo', 'D')
  1892. call writefile([], 'Xtestbar', 'D')
  1893. set nofileignorecase
  1894. call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
  1895. call assert_equal('"e XTESTfoo', @:)
  1896. call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
  1897. call assert_equal('"e Xtestbar', @:)
  1898. set fileignorecase
  1899. call feedkeys(":e XT\<Tab>\<C-B>\"\<CR>", 'xt')
  1900. call assert_equal('"e Xtest', @:)
  1901. call feedkeys(":e Xt\<Tab>\<C-B>\"\<CR>", 'xt')
  1902. call assert_equal('"e Xtest', @:)
  1903. set fileignorecase&
  1904. endif
  1905. " If 'noselect' is present, single item menu should not insert item
  1906. func! T(a, c, p)
  1907. return "oneA"
  1908. endfunc
  1909. command! -nargs=1 -complete=custom,T MyCmd
  1910. set wildmode=noselect,full
  1911. call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
  1912. call assert_equal('"MyCmd o', @:)
  1913. call feedkeys(":MyCmd o\t\t\<C-B>\"\<CR>", 'xt')
  1914. call assert_equal('"MyCmd oneA', @:)
  1915. " 'nowildmenu' should make 'noselect' ineffective
  1916. set nowildmenu
  1917. call feedkeys(":MyCmd o\t\<C-B>\"\<CR>", 'xt')
  1918. call assert_equal('"MyCmd oneA', @:)
  1919. %argdelete
  1920. delcommand MyCmd
  1921. delfunc T
  1922. set wildmode&
  1923. %bwipe!
  1924. endfunc
  1925. func Test_wildmode()
  1926. " Test with utf-8 encoding
  1927. call Wildmode_tests()
  1928. " Test with latin1 encoding
  1929. let save_encoding = &encoding
  1930. " set encoding=latin1
  1931. " call Wildmode_tests()
  1932. let &encoding = save_encoding
  1933. endfunc
  1934. func Test_custom_complete_autoload()
  1935. call mkdir('Xcustdir/autoload', 'p')
  1936. let save_rtp = &rtp
  1937. exe 'set rtp=' .. getcwd() .. '/Xcustdir'
  1938. let lines =<< trim END
  1939. func vim8#Complete(a, c, p)
  1940. return "oneA\noneB\noneC"
  1941. endfunc
  1942. END
  1943. call writefile(lines, 'Xcustdir/autoload/vim8.vim')
  1944. command -nargs=1 -complete=custom,vim8#Complete MyCmd
  1945. set nowildmenu
  1946. set wildmode=full,list
  1947. call feedkeys(":MyCmd \<C-A>\<C-B>\"\<CR>", 'xt')
  1948. call assert_equal('"MyCmd oneA oneB oneC', @:)
  1949. let &rtp = save_rtp
  1950. set wildmode& wildmenu&
  1951. delcommand MyCmd
  1952. call delete('Xcustdir', 'rf')
  1953. endfunc
  1954. " Test for interrupting the command-line completion
  1955. func Test_interrupt_compl()
  1956. func F(lead, cmdl, p)
  1957. if a:lead =~ 'tw'
  1958. call interrupt()
  1959. return
  1960. endif
  1961. return "one\ntwo\nthree"
  1962. endfunc
  1963. command -nargs=1 -complete=custom,F Tcmd
  1964. set nowildmenu
  1965. set wildmode=full
  1966. let interrupted = 0
  1967. try
  1968. call feedkeys(":Tcmd tw\<Tab>\<C-B>\"\<CR>", 'xt')
  1969. catch /^Vim:Interrupt$/
  1970. let interrupted = 1
  1971. endtry
  1972. call assert_equal(1, interrupted)
  1973. let interrupted = 0
  1974. try
  1975. call feedkeys(":Tcmd tw\<C-d>\<C-B>\"\<CR>", 'xt')
  1976. catch /^Vim:Interrupt$/
  1977. let interrupted = 1
  1978. endtry
  1979. call assert_equal(1, interrupted)
  1980. delcommand Tcmd
  1981. delfunc F
  1982. set wildmode&
  1983. endfunc
  1984. " Test for moving the cursor on the : command line
  1985. func Test_cmdline_edit()
  1986. let str = ":one two\<C-U>"
  1987. let str ..= "one two\<C-W>\<C-W>"
  1988. let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
  1989. let str ..= "\<Left>five\<Right>"
  1990. let str ..= "\<Home>two "
  1991. let str ..= "\<C-Left>one "
  1992. let str ..= "\<C-Right> three"
  1993. let str ..= "\<End>\<S-Left>four "
  1994. let str ..= "\<S-Right> six"
  1995. let str ..= "\<C-B>\"\<C-E> seven\<CR>"
  1996. call feedkeys(str, 'xt')
  1997. call assert_equal("\"one two three four five six seven", @:)
  1998. endfunc
  1999. " Test for moving the cursor on the / command line in 'rightleft' mode
  2000. func Test_cmdline_edit_rightleft()
  2001. CheckFeature rightleft
  2002. set rightleft
  2003. set rightleftcmd=search
  2004. let str = "/one two\<C-U>"
  2005. let str ..= "one two\<C-W>\<C-W>"
  2006. let str ..= "four\<BS>\<C-H>\<Del>\<kDel>"
  2007. let str ..= "\<Right>five\<Left>"
  2008. let str ..= "\<Home>two "
  2009. let str ..= "\<C-Right>one "
  2010. let str ..= "\<C-Left> three"
  2011. let str ..= "\<End>\<S-Right>four "
  2012. let str ..= "\<S-Left> six"
  2013. let str ..= "\<C-B>\"\<C-E> seven\<CR>"
  2014. call assert_fails("call feedkeys(str, 'xt')", 'E486:')
  2015. call assert_equal("\"one two three four five six seven", @/)
  2016. set rightleftcmd&
  2017. set rightleft&
  2018. endfunc
  2019. " Test for using <C-\>e in the command line to evaluate an expression
  2020. func Test_cmdline_expr()
  2021. " Evaluate an expression from the beginning of a command line
  2022. call feedkeys(":abc\<C-B>\<C-\>e\"\\\"hello\"\<CR>\<CR>", 'xt')
  2023. call assert_equal('"hello', @:)
  2024. " Use an invalid expression for <C-\>e
  2025. call assert_beeps('call feedkeys(":\<C-\>einvalid\<CR>", "tx")')
  2026. " Insert literal <CTRL-\> in the command line
  2027. call feedkeys(":\"e \<C-\>\<C-Y>\<CR>", 'xt')
  2028. call assert_equal("\"e \<C-\>\<C-Y>", @:)
  2029. endfunc
  2030. " This was making the insert position negative
  2031. func Test_cmdline_expr_register()
  2032. exe "sil! norm! ?\<C-\>e0\<C-R>0\<Esc>?\<C-\>e0\<CR>"
  2033. endfunc
  2034. " Test for 'imcmdline' and 'imsearch'
  2035. " This test doesn't actually test the input method functionality.
  2036. func Test_cmdline_inputmethod()
  2037. throw 'Skipped: Nvim does not allow setting the value of a hidden option'
  2038. new
  2039. call setline(1, ['', 'abc', ''])
  2040. set imcmdline
  2041. call feedkeys(":\"abc\<CR>", 'xt')
  2042. call assert_equal("\"abc", @:)
  2043. call feedkeys(":\"\<C-^>abc\<C-^>\<CR>", 'xt')
  2044. call assert_equal("\"abc", @:)
  2045. call feedkeys("/abc\<CR>", 'xt')
  2046. call assert_equal([2, 1], [line('.'), col('.')])
  2047. call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
  2048. call assert_equal([2, 1], [line('.'), col('.')])
  2049. " set imsearch=2
  2050. call cursor(1, 1)
  2051. call feedkeys("/abc\<CR>", 'xt')
  2052. call assert_equal([2, 1], [line('.'), col('.')])
  2053. call cursor(1, 1)
  2054. call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
  2055. call assert_equal([2, 1], [line('.'), col('.')])
  2056. set imdisable
  2057. call feedkeys("/\<C-^>abc\<C-^>\<CR>", 'xt')
  2058. call assert_equal([2, 1], [line('.'), col('.')])
  2059. set imdisable&
  2060. set imsearch&
  2061. set imcmdline&
  2062. %bwipe!
  2063. endfunc
  2064. " Test for recursively getting multiple command line inputs
  2065. func Test_cmdwin_multi_input()
  2066. call feedkeys(":\<C-R>=input('P: ')\<CR>\"cyan\<CR>\<CR>", 'xt')
  2067. call assert_equal('"cyan', @:)
  2068. endfunc
  2069. " Test for using CTRL-_ in the command line with 'allowrevins'
  2070. func Test_cmdline_revins()
  2071. CheckNotMSWindows
  2072. CheckFeature rightleft
  2073. call feedkeys(":\"abc\<c-_>\<cr>", 'xt')
  2074. call assert_equal("\"abc\<c-_>", @:)
  2075. set allowrevins
  2076. call feedkeys(":\"abc\<c-_>xyz\<c-_>\<CR>", 'xt')
  2077. " call assert_equal('"abcñèæ', @:)
  2078. call assert_equal('"abcxyz', @:)
  2079. set allowrevins&
  2080. endfunc
  2081. " Test for typing UTF-8 composing characters in the command line
  2082. func Test_cmdline_composing_chars()
  2083. call feedkeys(":\"\<C-V>u3046\<C-V>u3099\<CR>", 'xt')
  2084. call assert_equal('"ゔ', @:)
  2085. endfunc
  2086. " Test for normal mode commands not supported in the cmd window
  2087. func Test_cmdwin_blocked_commands()
  2088. call assert_fails('call feedkeys("q:\<C-T>\<CR>", "xt")', 'E11:')
  2089. call assert_fails('call feedkeys("q:\<C-]>\<CR>", "xt")', 'E11:')
  2090. call assert_fails('call feedkeys("q:\<C-^>\<CR>", "xt")', 'E11:')
  2091. call assert_fails('call feedkeys("q:Q\<CR>", "xt")', 'E11:')
  2092. call assert_fails('call feedkeys("q:Z\<CR>", "xt")', 'E11:')
  2093. call assert_fails('call feedkeys("q:\<F1>\<CR>", "xt")', 'E11:')
  2094. call assert_fails('call feedkeys("q:\<C-W>s\<CR>", "xt")', 'E11:')
  2095. call assert_fails('call feedkeys("q:\<C-W>v\<CR>", "xt")', 'E11:')
  2096. call assert_fails('call feedkeys("q:\<C-W>^\<CR>", "xt")', 'E11:')
  2097. call assert_fails('call feedkeys("q:\<C-W>n\<CR>", "xt")', 'E11:')
  2098. call assert_fails('call feedkeys("q:\<C-W>z\<CR>", "xt")', 'E11:')
  2099. call assert_fails('call feedkeys("q:\<C-W>o\<CR>", "xt")', 'E11:')
  2100. call assert_fails('call feedkeys("q:\<C-W>w\<CR>", "xt")', 'E11:')
  2101. call assert_fails('call feedkeys("q:\<C-W>j\<CR>", "xt")', 'E11:')
  2102. call assert_fails('call feedkeys("q:\<C-W>k\<CR>", "xt")', 'E11:')
  2103. call assert_fails('call feedkeys("q:\<C-W>h\<CR>", "xt")', 'E11:')
  2104. call assert_fails('call feedkeys("q:\<C-W>l\<CR>", "xt")', 'E11:')
  2105. call assert_fails('call feedkeys("q:\<C-W>T\<CR>", "xt")', 'E11:')
  2106. call assert_fails('call feedkeys("q:\<C-W>x\<CR>", "xt")', 'E11:')
  2107. call assert_fails('call feedkeys("q:\<C-W>r\<CR>", "xt")', 'E11:')
  2108. call assert_fails('call feedkeys("q:\<C-W>R\<CR>", "xt")', 'E11:')
  2109. call assert_fails('call feedkeys("q:\<C-W>K\<CR>", "xt")', 'E11:')
  2110. call assert_fails('call feedkeys("q:\<C-W>}\<CR>", "xt")', 'E11:')
  2111. call assert_fails('call feedkeys("q:\<C-W>]\<CR>", "xt")', 'E11:')
  2112. call assert_fails('call feedkeys("q:\<C-W>f\<CR>", "xt")', 'E11:')
  2113. call assert_fails('call feedkeys("q:\<C-W>d\<CR>", "xt")', 'E11:')
  2114. call assert_fails('call feedkeys("q:\<C-W>g\<CR>", "xt")', 'E11:')
  2115. endfunc
  2116. " Close the Cmd-line window in insert mode using CTRL-C
  2117. func Test_cmdwin_insert_mode_close()
  2118. %bw!
  2119. let s = ''
  2120. exe "normal q:a\<C-C>let s='Hello'\<CR>"
  2121. call assert_equal('Hello', s)
  2122. call assert_equal(1, winnr('$'))
  2123. endfunc
  2124. " test that ";" works to find a match at the start of the first line
  2125. func Test_zero_line_search()
  2126. new
  2127. call setline(1, ["1, pattern", "2, ", "3, pattern"])
  2128. call cursor(1,1)
  2129. 0;/pattern/d
  2130. call assert_equal(["2, ", "3, pattern"], getline(1,'$'))
  2131. q!
  2132. endfunc
  2133. func Test_read_shellcmd()
  2134. CheckUnix
  2135. if executable('ls')
  2136. " There should be ls in the $PATH
  2137. call feedkeys(":r! l\<c-a>\<c-b>\"\<cr>", 'tx')
  2138. call assert_match('^"r! .*\<ls\>', @:)
  2139. endif
  2140. if executable('rm')
  2141. call feedkeys(":r! ++enc=utf-8 r\<c-a>\<c-b>\"\<cr>", 'tx')
  2142. call assert_notmatch('^"r!.*\<runtest.vim\>', @:)
  2143. call assert_match('^"r!.*\<rm\>', @:)
  2144. call feedkeys(":r ++enc=utf-8 !rm\<c-a>\<c-b>\"\<cr>", 'tx')
  2145. call assert_notmatch('^"r.*\<runtest.vim\>', @:)
  2146. call assert_match('^"r ++enc\S\+ !.*\<rm\>', @:)
  2147. endif
  2148. endfunc
  2149. " Test for going up and down the directory tree using 'wildmenu'
  2150. func Test_wildmenu_dirstack()
  2151. CheckUnix
  2152. %bw!
  2153. call mkdir('Xdir1/dir2/dir3/dir4', 'p')
  2154. call writefile([], 'Xdir1/file1_1.txt')
  2155. call writefile([], 'Xdir1/file1_2.txt')
  2156. call writefile([], 'Xdir1/dir2/file2_1.txt')
  2157. call writefile([], 'Xdir1/dir2/file2_2.txt')
  2158. call writefile([], 'Xdir1/dir2/dir3/file3_1.txt')
  2159. call writefile([], 'Xdir1/dir2/dir3/file3_2.txt')
  2160. call writefile([], 'Xdir1/dir2/dir3/dir4/file4_1.txt')
  2161. call writefile([], 'Xdir1/dir2/dir3/dir4/file4_2.txt')
  2162. set wildmenu
  2163. cd Xdir1/dir2/dir3/dir4
  2164. call feedkeys(":e \<Tab>\<C-B>\"\<CR>", 'xt')
  2165. call assert_equal('"e file4_1.txt', @:)
  2166. call feedkeys(":e \<Tab>\<Up>\<C-B>\"\<CR>", 'xt')
  2167. call assert_equal('"e ../dir4/', @:)
  2168. call feedkeys(":e \<Tab>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
  2169. call assert_equal('"e ../../dir3/', @:)
  2170. call feedkeys(":e \<Tab>\<Up>\<Up>\<Up>\<C-B>\"\<CR>", 'xt')
  2171. call assert_equal('"e ../../../dir2/', @:)
  2172. call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<C-B>\"\<CR>", 'xt')
  2173. call assert_equal('"e ../../dir3/dir4/', @:)
  2174. call feedkeys(":e \<Tab>\<Up>\<Up>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
  2175. call assert_equal('"e ../../dir3/dir4/file4_1.txt', @:)
  2176. cd -
  2177. call feedkeys(":e Xdir1/\<Tab>\<Down>\<Down>\<Down>\<C-B>\"\<CR>", 'xt')
  2178. call assert_equal('"e Xdir1/dir2/dir3/dir4/file4_1.txt', @:)
  2179. call delete('Xdir1', 'rf')
  2180. set wildmenu&
  2181. endfunc
  2182. " Test for recalling newer or older cmdline from history with <Up>, <Down>,
  2183. " <S-Up>, <S-Down>, <PageUp>, <PageDown>, <kPageUp>, <kPageDown>, <C-p>, or
  2184. " <C-n>.
  2185. func Test_recalling_cmdline()
  2186. CheckFeature cmdline_hist
  2187. let g:cmdlines = []
  2188. cnoremap <Plug>(save-cmdline) <Cmd>let g:cmdlines += [getcmdline()]<CR>
  2189. let histories = [
  2190. \ #{name: 'cmd', enter: ':', exit: "\<Esc>"},
  2191. \ #{name: 'search', enter: '/', exit: "\<Esc>"},
  2192. \ #{name: 'expr', enter: ":\<C-r>=", exit: "\<Esc>\<Esc>"},
  2193. \ #{name: 'input', enter: ":call input('')\<CR>", exit: "\<CR>"},
  2194. "\ TODO: {'name': 'debug', ...}
  2195. \]
  2196. let keypairs = [
  2197. \ #{older: "\<Up>", newer: "\<Down>", prefixmatch: v:true},
  2198. \ #{older: "\<S-Up>", newer: "\<S-Down>", prefixmatch: v:false},
  2199. \ #{older: "\<PageUp>", newer: "\<PageDown>", prefixmatch: v:false},
  2200. \ #{older: "\<kPageUp>", newer: "\<kPageDown>", prefixmatch: v:false},
  2201. \ #{older: "\<C-p>", newer: "\<C-n>", prefixmatch: v:false},
  2202. \]
  2203. let prefix = 'vi'
  2204. for h in histories
  2205. call histadd(h.name, 'vim')
  2206. call histadd(h.name, 'virtue')
  2207. call histadd(h.name, 'Virgo')
  2208. call histadd(h.name, 'vogue')
  2209. call histadd(h.name, 'emacs')
  2210. for k in keypairs
  2211. let g:cmdlines = []
  2212. let keyseqs = h.enter
  2213. \ .. prefix
  2214. \ .. repeat(k.older .. "\<Plug>(save-cmdline)", 2)
  2215. \ .. repeat(k.newer .. "\<Plug>(save-cmdline)", 2)
  2216. \ .. h.exit
  2217. call feedkeys(keyseqs, 'xt')
  2218. call histdel(h.name, -1) " delete the history added by feedkeys above
  2219. let expect = k.prefixmatch
  2220. \ ? ['virtue', 'vim', 'virtue', prefix]
  2221. \ : ['emacs', 'vogue', 'emacs', prefix]
  2222. call assert_equal(expect, g:cmdlines)
  2223. endfor
  2224. endfor
  2225. unlet g:cmdlines
  2226. cunmap <Plug>(save-cmdline)
  2227. endfunc
  2228. func Test_cmd_map_cmdlineChanged()
  2229. let g:log = []
  2230. cnoremap <F1> l<Cmd><CR>s
  2231. augroup test_CmdlineChanged
  2232. autocmd!
  2233. autocmd CmdlineChanged : let g:log += [getcmdline()]
  2234. augroup END
  2235. call feedkeys(":\<F1>\<CR>", 'xt')
  2236. call assert_equal(['l', 'ls'], g:log)
  2237. let @b = 'b'
  2238. cnoremap <F1> a<C-R>b
  2239. let g:log = []
  2240. call feedkeys(":\<F1>\<CR>", 'xt')
  2241. call assert_equal(['a', 'ab'], g:log)
  2242. unlet g:log
  2243. cunmap <F1>
  2244. augroup test_CmdlineChanged
  2245. autocmd!
  2246. augroup END
  2247. augroup! test_CmdlineChanged
  2248. endfunc
  2249. " Test for the 'suffixes' option
  2250. func Test_suffixes_opt()
  2251. call writefile([], 'Xsuffile')
  2252. call writefile([], 'Xsuffile.c')
  2253. call writefile([], 'Xsuffile.o')
  2254. set suffixes=
  2255. call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
  2256. call assert_equal('"e Xsuffile Xsuffile.c Xsuffile.o', @:)
  2257. call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
  2258. call assert_equal('"e Xsuffile.c', @:)
  2259. set suffixes=.c
  2260. call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
  2261. call assert_equal('"e Xsuffile Xsuffile.o Xsuffile.c', @:)
  2262. call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
  2263. call assert_equal('"e Xsuffile.o', @:)
  2264. set suffixes=,,
  2265. call feedkeys(":e Xsuffi*\<C-A>\<C-B>\"\<CR>", 'xt')
  2266. call assert_equal('"e Xsuffile.c Xsuffile.o Xsuffile', @:)
  2267. call feedkeys(":e Xsuffi*\<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
  2268. call assert_equal('"e Xsuffile.o', @:)
  2269. set suffixes&
  2270. " Test for getcompletion() with different patterns
  2271. call assert_equal(['Xsuffile', 'Xsuffile.c', 'Xsuffile.o'], getcompletion('Xsuffile', 'file'))
  2272. call assert_equal(['Xsuffile'], getcompletion('Xsuffile$', 'file'))
  2273. call delete('Xsuffile')
  2274. call delete('Xsuffile.c')
  2275. call delete('Xsuffile.o')
  2276. endfunc
  2277. " Test for using a popup menu for the command line completion matches
  2278. " (wildoptions=pum)
  2279. func Test_wildmenu_pum()
  2280. CheckRunVimInTerminal
  2281. let commands =<< trim [CODE]
  2282. set wildmenu
  2283. set wildoptions=pum
  2284. set shm+=I
  2285. set noruler
  2286. set noshowcmd
  2287. func CmdCompl(a, b, c)
  2288. return repeat(['aaaa'], 120)
  2289. endfunc
  2290. command -nargs=* -complete=customlist,CmdCompl Tcmd
  2291. func MyStatusLine() abort
  2292. return 'status'
  2293. endfunc
  2294. func SetupStatusline()
  2295. set statusline=%!MyStatusLine()
  2296. set laststatus=2
  2297. endfunc
  2298. func MyTabLine()
  2299. return 'my tab line'
  2300. endfunc
  2301. func SetupTabline()
  2302. set statusline=
  2303. set tabline=%!MyTabLine()
  2304. set showtabline=2
  2305. endfunc
  2306. func DoFeedKeys()
  2307. let &wildcharm = char2nr("\t")
  2308. call feedkeys(":edit $VIMRUNTIME/\<Tab>\<Left>\<C-U>ab\<Tab>")
  2309. endfunc
  2310. [CODE]
  2311. call writefile(commands, 'Xtest', 'D')
  2312. let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
  2313. call term_sendkeys(buf, ":sign \<Tab>")
  2314. call VerifyScreenDump(buf, 'Test_wildmenu_pum_01', {})
  2315. " going down the popup menu using <Down>
  2316. call term_sendkeys(buf, "\<Down>\<Down>")
  2317. call VerifyScreenDump(buf, 'Test_wildmenu_pum_02', {})
  2318. " going down the popup menu using <C-N>
  2319. call term_sendkeys(buf, "\<C-N>")
  2320. call VerifyScreenDump(buf, 'Test_wildmenu_pum_03', {})
  2321. " going up the popup menu using <C-P>
  2322. call term_sendkeys(buf, "\<C-P>")
  2323. call VerifyScreenDump(buf, 'Test_wildmenu_pum_04', {})
  2324. " going up the popup menu using <Up>
  2325. call term_sendkeys(buf, "\<Up>")
  2326. call VerifyScreenDump(buf, 'Test_wildmenu_pum_05', {})
  2327. " pressing <C-E> should end completion and go back to the original match
  2328. call term_sendkeys(buf, "\<C-E>")
  2329. call VerifyScreenDump(buf, 'Test_wildmenu_pum_06', {})
  2330. " pressing <C-Y> should select the current match and end completion
  2331. call term_sendkeys(buf, "\<Tab>\<C-P>\<C-P>\<C-Y>")
  2332. call VerifyScreenDump(buf, 'Test_wildmenu_pum_07', {})
  2333. " With 'wildmode' set to 'longest,full', completing a match should display
  2334. " the longest match, the wildmenu should not be displayed.
  2335. call term_sendkeys(buf, ":\<C-U>set wildmode=longest,full\<CR>")
  2336. call TermWait(buf)
  2337. call term_sendkeys(buf, ":sign u\<Tab>")
  2338. call VerifyScreenDump(buf, 'Test_wildmenu_pum_08', {})
  2339. " pressing <Tab> should display the wildmenu
  2340. call term_sendkeys(buf, "\<Tab>")
  2341. call VerifyScreenDump(buf, 'Test_wildmenu_pum_09', {})
  2342. " pressing <Tab> second time should select the next entry in the menu
  2343. call term_sendkeys(buf, "\<Tab>")
  2344. call VerifyScreenDump(buf, 'Test_wildmenu_pum_10', {})
  2345. call term_sendkeys(buf, ":\<C-U>set wildmode=full\<CR>")
  2346. " showing popup menu in different columns in the cmdline
  2347. call term_sendkeys(buf, ":sign define \<Tab>")
  2348. call VerifyScreenDump(buf, 'Test_wildmenu_pum_11', {})
  2349. call term_sendkeys(buf, " \<Tab>")
  2350. call VerifyScreenDump(buf, 'Test_wildmenu_pum_12', {})
  2351. call term_sendkeys(buf, " \<Tab>")
  2352. call VerifyScreenDump(buf, 'Test_wildmenu_pum_13', {})
  2353. " Directory name completion
  2354. call mkdir('Xnamedir/XdirA/XdirB', 'pR')
  2355. call writefile([], 'Xnamedir/XfileA')
  2356. call writefile([], 'Xnamedir/XdirA/XfileB')
  2357. call writefile([], 'Xnamedir/XdirA/XdirB/XfileC')
  2358. call term_sendkeys(buf, "\<C-U>e Xnamedi\<Tab>\<Tab>")
  2359. call VerifyScreenDump(buf, 'Test_wildmenu_pum_14', {})
  2360. " Pressing <Right> on a directory name should go into that directory
  2361. call term_sendkeys(buf, "\<Right>")
  2362. call VerifyScreenDump(buf, 'Test_wildmenu_pum_15', {})
  2363. " Pressing <Left> on a directory name should go to the parent directory
  2364. call term_sendkeys(buf, "\<Left>")
  2365. call VerifyScreenDump(buf, 'Test_wildmenu_pum_16', {})
  2366. " Pressing <C-A> when the popup menu is displayed should list all the
  2367. " matches but the popup menu should still remain
  2368. call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-A>")
  2369. call VerifyScreenDump(buf, 'Test_wildmenu_pum_17', {})
  2370. " Pressing <C-D> when the popup menu is displayed should remove the popup
  2371. " menu
  2372. call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-D>")
  2373. call VerifyScreenDump(buf, 'Test_wildmenu_pum_18', {})
  2374. " Pressing <S-Tab> should open the popup menu with the last entry selected
  2375. call term_sendkeys(buf, "\<C-U>\<CR>:sign \<S-Tab>\<C-P>")
  2376. call VerifyScreenDump(buf, 'Test_wildmenu_pum_19', {})
  2377. " Pressing <Esc> should close the popup menu and cancel the cmd line
  2378. call term_sendkeys(buf, "\<C-U>\<CR>:sign \<Tab>\<Esc>")
  2379. call VerifyScreenDump(buf, 'Test_wildmenu_pum_20', {})
  2380. " Typing a character when the popup is open, should close the popup
  2381. call term_sendkeys(buf, ":sign \<Tab>x")
  2382. call VerifyScreenDump(buf, 'Test_wildmenu_pum_21', {})
  2383. " When the popup is open, entering the cmdline window should close the popup
  2384. call term_sendkeys(buf, "\<C-U>sign \<Tab>\<C-F>")
  2385. call VerifyScreenDump(buf, 'Test_wildmenu_pum_22', {})
  2386. call term_sendkeys(buf, ":q\<CR>")
  2387. " After the last popup menu item, <C-N> should show the original string
  2388. call term_sendkeys(buf, ":sign u\<Tab>\<C-N>\<C-N>")
  2389. call VerifyScreenDump(buf, 'Test_wildmenu_pum_23', {})
  2390. " Use the popup menu for the command name
  2391. call term_sendkeys(buf, "\<C-U>bu\<Tab>")
  2392. call VerifyScreenDump(buf, 'Test_wildmenu_pum_24', {})
  2393. " Pressing the left arrow should remove the popup menu
  2394. call term_sendkeys(buf, "\<Left>\<Left>")
  2395. call VerifyScreenDump(buf, 'Test_wildmenu_pum_25', {})
  2396. " Pressing <BS> should remove the popup menu and erase the last character
  2397. call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<BS>")
  2398. call VerifyScreenDump(buf, 'Test_wildmenu_pum_26', {})
  2399. " Pressing <C-W> should remove the popup menu and erase the previous word
  2400. call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-W>")
  2401. call VerifyScreenDump(buf, 'Test_wildmenu_pum_27', {})
  2402. " Pressing <C-U> should remove the popup menu and erase the entire line
  2403. call term_sendkeys(buf, "\<C-E>\<C-U>sign \<Tab>\<C-U>")
  2404. call VerifyScreenDump(buf, 'Test_wildmenu_pum_28', {})
  2405. " Using <C-E> to cancel the popup menu and then pressing <Up> should recall
  2406. " the cmdline from history
  2407. call term_sendkeys(buf, "sign xyz\<Esc>:sign \<Tab>\<C-E>\<Up>")
  2408. call VerifyScreenDump(buf, 'Test_wildmenu_pum_29', {})
  2409. " Check "list" still works
  2410. call term_sendkeys(buf, "\<C-U>set wildmode=longest,list\<CR>")
  2411. call term_sendkeys(buf, ":cn\<Tab>")
  2412. call VerifyScreenDump(buf, 'Test_wildmenu_pum_30', {})
  2413. call term_sendkeys(buf, "s")
  2414. call VerifyScreenDump(buf, 'Test_wildmenu_pum_31', {})
  2415. " Tests a directory name contained full-width characters.
  2416. call mkdir('Xnamedir/あいう', 'p')
  2417. call writefile([], 'Xnamedir/あいう/abc')
  2418. call writefile([], 'Xnamedir/あいう/xyz')
  2419. call writefile([], 'Xnamedir/あいう/123')
  2420. call term_sendkeys(buf, "\<C-U>set wildmode&\<CR>")
  2421. call term_sendkeys(buf, ":\<C-U>e Xnamedir/あいう/\<Tab>")
  2422. call VerifyScreenDump(buf, 'Test_wildmenu_pum_32', {})
  2423. " Pressing <C-A> when the popup menu is displayed should list all the
  2424. " matches and pressing a key after that should remove the popup menu
  2425. call term_sendkeys(buf, "\<C-U>set wildmode=full\<CR>")
  2426. call term_sendkeys(buf, ":sign \<Tab>\<C-A>x")
  2427. call VerifyScreenDump(buf, 'Test_wildmenu_pum_33', {})
  2428. " Pressing <C-A> when the popup menu is displayed should list all the
  2429. " matches and pressing <Left> after that should move the cursor
  2430. call term_sendkeys(buf, "\<C-U>abc\<Esc>")
  2431. call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<Left>")
  2432. call VerifyScreenDump(buf, 'Test_wildmenu_pum_34', {})
  2433. " When <C-A> displays a lot of matches (screen scrolls), all the matches
  2434. " should be displayed correctly on the screen.
  2435. call term_sendkeys(buf, "\<End>\<C-U>Tcmd \<Tab>\<C-A>\<Left>\<Left>")
  2436. call VerifyScreenDump(buf, 'Test_wildmenu_pum_35', {})
  2437. " After using <C-A> to expand all the filename matches, pressing <Up>
  2438. " should not open the popup menu again.
  2439. call term_sendkeys(buf, "\<C-E>\<C-U>:cd Xnamedir/XdirA\<CR>")
  2440. call term_sendkeys(buf, ":e \<Tab>\<C-A>\<Up>")
  2441. call VerifyScreenDump(buf, 'Test_wildmenu_pum_36', {})
  2442. call term_sendkeys(buf, "\<C-E>\<C-U>:cd -\<CR>")
  2443. " After using <C-A> to expand all the matches, pressing <S-Tab> used to
  2444. " crash Vim
  2445. call term_sendkeys(buf, ":sign \<Tab>\<C-A>\<S-Tab>")
  2446. call VerifyScreenDump(buf, 'Test_wildmenu_pum_37', {})
  2447. " After removing the pum the command line is redrawn
  2448. call term_sendkeys(buf, ":edit foo\<CR>")
  2449. call term_sendkeys(buf, ":edit bar\<CR>")
  2450. call term_sendkeys(buf, ":ls\<CR>")
  2451. call term_sendkeys(buf, ":com\<Tab> ")
  2452. call VerifyScreenDump(buf, 'Test_wildmenu_pum_38', {})
  2453. call term_sendkeys(buf, "\<C-U>\<CR>")
  2454. " Esc still works to abort the command when 'statusline' is set
  2455. call term_sendkeys(buf, ":call SetupStatusline()\<CR>")
  2456. call term_sendkeys(buf, ":si\<Tab>")
  2457. call term_sendkeys(buf, "\<Esc>")
  2458. call VerifyScreenDump(buf, 'Test_wildmenu_pum_39', {})
  2459. " Esc still works to abort the command when 'tabline' is set
  2460. call term_sendkeys(buf, ":call SetupTabline()\<CR>")
  2461. call term_sendkeys(buf, ":si\<Tab>")
  2462. call term_sendkeys(buf, "\<Esc>")
  2463. call VerifyScreenDump(buf, 'Test_wildmenu_pum_40', {})
  2464. " popup is cleared also when 'lazyredraw' is set
  2465. call term_sendkeys(buf, ":set showtabline=1 laststatus=1 lazyredraw\<CR>")
  2466. call term_sendkeys(buf, ":call DoFeedKeys()\<CR>")
  2467. call VerifyScreenDump(buf, 'Test_wildmenu_pum_41', {})
  2468. call term_sendkeys(buf, "\<Esc>")
  2469. " Pressing <PageDown> should scroll the menu downward
  2470. call term_sendkeys(buf, ":sign \<Tab>\<PageDown>")
  2471. call VerifyScreenDump(buf, 'Test_wildmenu_pum_42', {})
  2472. call term_sendkeys(buf, "\<PageDown>")
  2473. call VerifyScreenDump(buf, 'Test_wildmenu_pum_43', {})
  2474. call term_sendkeys(buf, "\<PageDown>")
  2475. call VerifyScreenDump(buf, 'Test_wildmenu_pum_44', {})
  2476. call term_sendkeys(buf, "\<PageDown>")
  2477. call VerifyScreenDump(buf, 'Test_wildmenu_pum_45', {})
  2478. call term_sendkeys(buf, "\<C-U>sign \<Tab>\<Down>\<Down>\<PageDown>")
  2479. call VerifyScreenDump(buf, 'Test_wildmenu_pum_46', {})
  2480. " Pressing <PageUp> should scroll the menu upward
  2481. call term_sendkeys(buf, "\<C-U>sign \<Tab>\<PageUp>")
  2482. call VerifyScreenDump(buf, 'Test_wildmenu_pum_47', {})
  2483. call term_sendkeys(buf, "\<PageUp>")
  2484. call VerifyScreenDump(buf, 'Test_wildmenu_pum_48', {})
  2485. call term_sendkeys(buf, "\<PageUp>")
  2486. call VerifyScreenDump(buf, 'Test_wildmenu_pum_49', {})
  2487. call term_sendkeys(buf, "\<PageUp>")
  2488. call VerifyScreenDump(buf, 'Test_wildmenu_pum_50', {})
  2489. " pressing <C-E> to end completion should work in middle of the line too
  2490. call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>")
  2491. call VerifyScreenDump(buf, 'Test_wildmenu_pum_51', {})
  2492. call term_sendkeys(buf, "\<C-E>")
  2493. call VerifyScreenDump(buf, 'Test_wildmenu_pum_52', {})
  2494. " pressing <C-Y> should select the current match and end completion
  2495. call term_sendkeys(buf, "\<Esc>:set wildchazz\<Left>\<Left>\<Tab>\<C-Y>")
  2496. call VerifyScreenDump(buf, 'Test_wildmenu_pum_53', {})
  2497. call term_sendkeys(buf, "\<C-U>\<CR>")
  2498. call StopVimInTerminal(buf)
  2499. endfunc
  2500. " Test for wildmenumode() with the cmdline popup menu
  2501. func Test_wildmenumode_with_pum()
  2502. set wildmenu
  2503. set wildoptions=pum
  2504. cnoremap <expr> <F2> wildmenumode()
  2505. call feedkeys(":sign \<Tab>\<F2>\<F2>\<C-B>\"\<CR>", 'xt')
  2506. call assert_equal('"sign define10', @:)
  2507. call feedkeys(":sign \<Tab>\<C-A>\<F2>\<C-B>\"\<CR>", 'xt')
  2508. call assert_equal('"sign define jump list place undefine unplace0', @:)
  2509. call feedkeys(":sign \<Tab>\<C-E>\<F2>\<C-B>\"\<CR>", 'xt')
  2510. call assert_equal('"sign 0', @:)
  2511. call feedkeys(":sign \<Tab>\<C-Y>\<F2>\<C-B>\"\<CR>", 'xt')
  2512. call assert_equal('"sign define0', @:)
  2513. set nowildmenu wildoptions&
  2514. cunmap <F2>
  2515. endfunc
  2516. " Test for opening the cmdline completion popup menu from the terminal window.
  2517. " The popup menu should be positioned correctly over the status line of the
  2518. " bottom-most window.
  2519. func Test_wildmenu_pum_from_terminal()
  2520. CheckRunVimInTerminal
  2521. let python = PythonProg()
  2522. call CheckPython(python)
  2523. %bw!
  2524. let cmds = ['set wildmenu wildoptions=pum']
  2525. let pcmd = python .. ' -c "import sys; sys.stdout.write(sys.stdin.read())"'
  2526. call add(cmds, "call term_start('" .. pcmd .. "')")
  2527. call writefile(cmds, 'Xtest', 'D')
  2528. let buf = RunVimInTerminal('-S Xtest', #{rows: 10})
  2529. call term_sendkeys(buf, "\r\r\r")
  2530. call term_wait(buf)
  2531. call term_sendkeys(buf, "\<C-W>:sign \<Tab>")
  2532. call term_wait(buf)
  2533. call VerifyScreenDump(buf, 'Test_wildmenu_pum_term_01', {})
  2534. call term_wait(buf)
  2535. call StopVimInTerminal(buf)
  2536. endfunc
  2537. func Test_wildmenu_pum_odd_wildchar()
  2538. CheckRunVimInTerminal
  2539. " Test odd wildchar interactions with pum. Make sure they behave properly
  2540. " and don't lead to memory corruption due to improperly cleaned up memory.
  2541. let lines =<< trim END
  2542. set wildoptions=pum
  2543. set wildchar=<C-E>
  2544. END
  2545. call writefile(lines, 'XwildmenuTest', 'D')
  2546. let buf = RunVimInTerminal('-S XwildmenuTest', #{rows: 10})
  2547. call term_sendkeys(buf, ":\<C-E>")
  2548. call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
  2549. " <C-E> being a wildchar takes priority over its original functionality
  2550. call term_sendkeys(buf, "\<C-E>")
  2551. call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_2', {})
  2552. call term_sendkeys(buf, "\<Esc>")
  2553. call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
  2554. " Escape key can be wildchar too. Double-<Esc> is hard-coded to escape
  2555. " command-line, and we need to make sure to clean up properly.
  2556. call term_sendkeys(buf, ":set wildchar=<Esc>\<CR>")
  2557. call term_sendkeys(buf, ":\<Esc>")
  2558. call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
  2559. call term_sendkeys(buf, "\<Esc>")
  2560. call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
  2561. " <C-\> can also be wildchar. <C-\><C-N> however will still escape cmdline
  2562. " and we again need to make sure we clean up properly.
  2563. call term_sendkeys(buf, ":set wildchar=<C-\\>\<CR>")
  2564. call term_sendkeys(buf, ":\<C-\>\<C-\>")
  2565. call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_1', {})
  2566. call term_sendkeys(buf, "\<C-N>")
  2567. call VerifyScreenDump(buf, 'Test_wildmenu_pum_odd_wildchar_3', {})
  2568. call StopVimInTerminal(buf)
  2569. endfunc
  2570. " Test that 'rightleft' should not affect cmdline completion popup menu.
  2571. func Test_wildmenu_pum_rightleft()
  2572. CheckFeature rightleft
  2573. CheckScreendump
  2574. let lines =<< trim END
  2575. set wildoptions=pum
  2576. set rightleft
  2577. END
  2578. call writefile(lines, 'Xwildmenu_pum_rl', 'D')
  2579. let buf = RunVimInTerminal('-S Xwildmenu_pum_rl', #{rows: 10, cols: 50})
  2580. call term_sendkeys(buf, ":sign \<Tab>")
  2581. call VerifyScreenDump(buf, 'Test_wildmenu_pum_rl', {})
  2582. call StopVimInTerminal(buf)
  2583. endfunc
  2584. " Test highlighting when pattern matches non-first character of item
  2585. func Test_wildmenu_pum_hl_nonfirst()
  2586. CheckScreendump
  2587. let lines =<< trim END
  2588. set wildoptions=pum wildchar=<tab> wildmode=noselect,full
  2589. hi PmenuMatchSel ctermfg=6 ctermbg=7
  2590. hi PmenuMatch ctermfg=4 ctermbg=225
  2591. func T(a, c, p)
  2592. return ["oneA", "o neBneB", "aoneC"]
  2593. endfunc
  2594. command -nargs=1 -complete=customlist,T MyCmd
  2595. END
  2596. call writefile(lines, 'Xwildmenu_pum_hl_nonf', 'D')
  2597. let buf = RunVimInTerminal('-S Xwildmenu_pum_hl_nonf', #{rows: 10, cols: 50})
  2598. call term_sendkeys(buf, ":MyCmd ne\<tab>")
  2599. call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_nonf', {})
  2600. call term_sendkeys(buf, "\<Esc>")
  2601. call StopVimInTerminal(buf)
  2602. endfunc
  2603. " Test highlighting matched text in cmdline completion popup menu.
  2604. func Test_wildmenu_pum_hl_match()
  2605. CheckScreendump
  2606. let lines =<< trim END
  2607. set wildoptions=pum,fuzzy
  2608. hi PmenuMatchSel ctermfg=6 ctermbg=7
  2609. hi PmenuMatch ctermfg=4 ctermbg=225
  2610. END
  2611. call writefile(lines, 'Xwildmenu_pum_hl', 'D')
  2612. let buf = RunVimInTerminal('-S Xwildmenu_pum_hl', #{rows: 10, cols: 50})
  2613. call term_sendkeys(buf, ":sign plc\<Tab>")
  2614. call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_1', {})
  2615. call term_sendkeys(buf, "\<Tab>")
  2616. call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_2', {})
  2617. call term_sendkeys(buf, "\<Tab>")
  2618. call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_3', {})
  2619. call term_sendkeys(buf, "\<Esc>:set wildoptions-=fuzzy\<CR>")
  2620. call TermWait(buf)
  2621. call term_sendkeys(buf, ":sign un\<Tab>")
  2622. call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_4', {})
  2623. call term_sendkeys(buf, "\<Tab>")
  2624. call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_5', {})
  2625. call term_sendkeys(buf, "\<Tab>")
  2626. call VerifyScreenDump(buf, 'Test_wildmenu_pum_hl_match_6', {})
  2627. call term_sendkeys(buf, "\<Esc>")
  2628. call StopVimInTerminal(buf)
  2629. endfunc
  2630. " Test for completion after a :substitute command followed by a pipe (|)
  2631. " character
  2632. func Test_cmdline_complete_substitute()
  2633. call feedkeys(":s | \t\<C-B>\"\<CR>", 'xt')
  2634. call assert_equal("\"s | \t", @:)
  2635. call feedkeys(":s/ | \t\<C-B>\"\<CR>", 'xt')
  2636. call assert_equal("\"s/ | \t", @:)
  2637. call feedkeys(":s/one | \t\<C-B>\"\<CR>", 'xt')
  2638. call assert_equal("\"s/one | \t", @:)
  2639. call feedkeys(":s/one/ | \t\<C-B>\"\<CR>", 'xt')
  2640. call assert_equal("\"s/one/ | \t", @:)
  2641. call feedkeys(":s/one/two | \t\<C-B>\"\<CR>", 'xt')
  2642. call assert_equal("\"s/one/two | \t", @:)
  2643. call feedkeys(":s/one/two/ | chist\t\<C-B>\"\<CR>", 'xt')
  2644. call assert_equal('"s/one/two/ | chistory', @:)
  2645. call feedkeys(":s/one/two/g \t\<C-B>\"\<CR>", 'xt')
  2646. call assert_equal("\"s/one/two/g \t", @:)
  2647. call feedkeys(":s/one/two/g | chist\t\<C-B>\"\<CR>", 'xt')
  2648. call assert_equal("\"s/one/two/g | chistory", @:)
  2649. call feedkeys(":s/one/t\\/ | \t\<C-B>\"\<CR>", 'xt')
  2650. call assert_equal("\"s/one/t\\/ | \t", @:)
  2651. call feedkeys(":s/one/t\"o/ | chist\t\<C-B>\"\<CR>", 'xt')
  2652. call assert_equal('"s/one/t"o/ | chistory', @:)
  2653. call feedkeys(":s/one/t|o/ | chist\t\<C-B>\"\<CR>", 'xt')
  2654. call assert_equal('"s/one/t|o/ | chistory', @:)
  2655. call feedkeys(":&\t\<C-B>\"\<CR>", 'xt')
  2656. call assert_equal("\"&\t", @:)
  2657. endfunc
  2658. " Test for the :dlist command completion
  2659. func Test_cmdline_complete_dlist()
  2660. call feedkeys(":dlist 10 /pat/ a\<C-A>\<C-B>\"\<CR>", 'xt')
  2661. call assert_equal("\"dlist 10 /pat/ a\<C-A>", @:)
  2662. call feedkeys(":dlist 10 /pat/ \t\<C-B>\"\<CR>", 'xt')
  2663. call assert_equal("\"dlist 10 /pat/ \t", @:)
  2664. call feedkeys(":dlist 10 /pa\\t/\t\<C-B>\"\<CR>", 'xt')
  2665. call assert_equal("\"dlist 10 /pa\\t/\t", @:)
  2666. call feedkeys(":dlist 10 /pat\\\t\<C-B>\"\<CR>", 'xt')
  2667. call assert_equal("\"dlist 10 /pat\\\t", @:)
  2668. call feedkeys(":dlist 10 /pat/ | chist\<Tab>\<C-B>\"\<CR>", 'xt')
  2669. call assert_equal("\"dlist 10 /pat/ | chistory", @:)
  2670. endfunc
  2671. " argument list (only for :argdel) fuzzy completion
  2672. func Test_fuzzy_completion_arglist()
  2673. argadd change.py count.py charge.py
  2674. set wildoptions&
  2675. call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
  2676. call assert_equal('"argdel cge', @:)
  2677. set wildoptions=fuzzy
  2678. call feedkeys(":argdel cge\<C-A>\<C-B>\"\<CR>", 'tx')
  2679. call assert_equal('"argdel change.py charge.py', @:)
  2680. %argdelete
  2681. set wildoptions&
  2682. endfunc
  2683. " autocmd group name fuzzy completion
  2684. func Test_fuzzy_completion_autocmd()
  2685. set wildoptions&
  2686. augroup MyFuzzyGroup
  2687. augroup END
  2688. call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
  2689. call assert_equal('"augroup mfg', @:)
  2690. call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
  2691. call assert_equal('"augroup MyFuzzyGroup', @:)
  2692. set wildoptions=fuzzy
  2693. call feedkeys(":augroup mfg\<Tab>\<C-B>\"\<CR>", 'tx')
  2694. call assert_equal('"augroup MyFuzzyGroup', @:)
  2695. call feedkeys(":augroup My*p\<Tab>\<C-B>\"\<CR>", 'tx')
  2696. call assert_equal('"augroup My*p', @:)
  2697. augroup! MyFuzzyGroup
  2698. set wildoptions&
  2699. endfunc
  2700. " buffer name fuzzy completion
  2701. func Test_fuzzy_completion_bufname()
  2702. set wildoptions&
  2703. " Use a long name to reduce the risk of matching a random directory name
  2704. edit SomeRandomFileWithLetters.txt
  2705. enew
  2706. call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
  2707. call assert_equal('"b SRFWL', @:)
  2708. call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
  2709. call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
  2710. set wildoptions=fuzzy
  2711. call feedkeys(":b SRFWL\<Tab>\<C-B>\"\<CR>", 'tx')
  2712. call assert_equal('"b SomeRandomFileWithLetters.txt', @:)
  2713. call feedkeys(":b S*FileWithLetters.txt\<Tab>\<C-B>\"\<CR>", 'tx')
  2714. call assert_equal('"b S*FileWithLetters.txt', @:)
  2715. %bw!
  2716. set wildoptions&
  2717. endfunc
  2718. " buffer name (full path) fuzzy completion
  2719. func Test_fuzzy_completion_bufname_fullpath()
  2720. CheckUnix
  2721. set wildoptions&
  2722. call mkdir('Xcmd/Xstate/Xfile.js', 'p')
  2723. edit Xcmd/Xstate/Xfile.js
  2724. cd Xcmd/Xstate
  2725. enew
  2726. call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
  2727. call assert_equal('"b CmdStateFile', @:)
  2728. set wildoptions=fuzzy
  2729. call feedkeys(":b CmdStateFile\<Tab>\<C-B>\"\<CR>", 'tx')
  2730. call assert_match('Xcmd/Xstate/Xfile.js$', @:)
  2731. cd -
  2732. call delete('Xcmd', 'rf')
  2733. set wildoptions&
  2734. endfunc
  2735. " :behave suboptions fuzzy completion
  2736. func Test_fuzzy_completion_behave()
  2737. throw 'Skipped: Nvim removed :behave'
  2738. set wildoptions&
  2739. call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
  2740. call assert_equal('"behave xm', @:)
  2741. call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
  2742. call assert_equal('"behave xterm', @:)
  2743. set wildoptions=fuzzy
  2744. call feedkeys(":behave xm\<Tab>\<C-B>\"\<CR>", 'tx')
  2745. call assert_equal('"behave xterm', @:)
  2746. call feedkeys(":behave xt*m\<Tab>\<C-B>\"\<CR>", 'tx')
  2747. call assert_equal('"behave xt*m', @:)
  2748. let g:Sline = ''
  2749. call feedkeys(":behave win\<C-D>\<F4>\<C-B>\"\<CR>", 'tx')
  2750. call assert_equal('mswin', g:Sline)
  2751. call assert_equal('"behave win', @:)
  2752. set wildoptions&
  2753. endfunc
  2754. " :filetype suboptions completion
  2755. func Test_completion_filetypecmd()
  2756. set wildoptions&
  2757. call feedkeys(":filetype \<C-A>\<C-B>\"\<CR>", 'tx')
  2758. call assert_equal('"filetype indent off on plugin', @:)
  2759. call feedkeys(":filetype plugin \<C-A>\<C-B>\"\<CR>", 'tx')
  2760. call assert_equal('"filetype plugin indent off on', @:)
  2761. call feedkeys(":filetype indent \<C-A>\<C-B>\"\<CR>", 'tx')
  2762. call assert_equal('"filetype indent off on plugin', @:)
  2763. call feedkeys(":filetype i\<C-A>\<C-B>\"\<CR>", 'tx')
  2764. call assert_equal('"filetype indent', @:)
  2765. call feedkeys(":filetype p\<C-A>\<C-B>\"\<CR>", 'tx')
  2766. call assert_equal('"filetype plugin', @:)
  2767. call feedkeys(":filetype o\<C-A>\<C-B>\"\<CR>", 'tx')
  2768. call assert_equal('"filetype off on', @:)
  2769. call feedkeys(":filetype indent of\<C-A>\<C-B>\"\<CR>", 'tx')
  2770. call assert_equal('"filetype indent off', @:)
  2771. set wildoptions&
  2772. endfunc
  2773. " " colorscheme name fuzzy completion - NOT supported
  2774. " func Test_fuzzy_completion_colorscheme()
  2775. " endfunc
  2776. " built-in command name fuzzy completion
  2777. func Test_fuzzy_completion_cmdname()
  2778. set wildoptions&
  2779. call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
  2780. call assert_equal('"sbwin', @:)
  2781. call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
  2782. call assert_equal('"sbrewind', @:)
  2783. set wildoptions=fuzzy
  2784. call feedkeys(":sbwin\<Tab>\<C-B>\"\<CR>", 'tx')
  2785. call assert_equal('"sbrewind', @:)
  2786. call feedkeys(":sbr*d\<Tab>\<C-B>\"\<CR>", 'tx')
  2787. call assert_equal('"sbr*d', @:)
  2788. set wildoptions&
  2789. endfunc
  2790. " " compiler name fuzzy completion - NOT supported
  2791. " func Test_fuzzy_completion_compiler()
  2792. " endfunc
  2793. " :cscope suboptions fuzzy completion
  2794. func Test_fuzzy_completion_cscope()
  2795. CheckFeature cscope
  2796. set wildoptions&
  2797. call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
  2798. call assert_equal('"cscope ret', @:)
  2799. call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
  2800. call assert_equal('"cscope reset', @:)
  2801. set wildoptions=fuzzy
  2802. call feedkeys(":cscope ret\<Tab>\<C-B>\"\<CR>", 'tx')
  2803. call assert_equal('"cscope reset', @:)
  2804. call feedkeys(":cscope re*t\<Tab>\<C-B>\"\<CR>", 'tx')
  2805. call assert_equal('"cscope re*t', @:)
  2806. set wildoptions&
  2807. endfunc
  2808. " :diffget/:diffput buffer name fuzzy completion
  2809. func Test_fuzzy_completion_diff()
  2810. new SomeBuffer
  2811. diffthis
  2812. new OtherBuffer
  2813. diffthis
  2814. set wildoptions&
  2815. call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
  2816. call assert_equal('"diffget sbuf', @:)
  2817. call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
  2818. call assert_equal('"diffput sbuf', @:)
  2819. set wildoptions=fuzzy
  2820. call feedkeys(":diffget sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
  2821. call assert_equal('"diffget SomeBuffer', @:)
  2822. call feedkeys(":diffput sbuf\<Tab>\<C-B>\"\<CR>", 'tx')
  2823. call assert_equal('"diffput SomeBuffer', @:)
  2824. %bw!
  2825. set wildoptions&
  2826. endfunc
  2827. " " directory name fuzzy completion - NOT supported
  2828. " func Test_fuzzy_completion_dirname()
  2829. " endfunc
  2830. " environment variable name fuzzy completion
  2831. func Test_fuzzy_completion_env()
  2832. set wildoptions&
  2833. call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
  2834. call assert_equal('"echo $VUT', @:)
  2835. set wildoptions=fuzzy
  2836. call feedkeys(":echo $VUT\<Tab>\<C-B>\"\<CR>", 'tx')
  2837. call assert_equal('"echo $VIMRUNTIME', @:)
  2838. set wildoptions&
  2839. endfunc
  2840. " autocmd event fuzzy completion
  2841. func Test_fuzzy_completion_autocmd_event()
  2842. set wildoptions&
  2843. call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
  2844. call assert_equal('"autocmd BWout', @:)
  2845. set wildoptions=fuzzy
  2846. call feedkeys(":autocmd BWout\<Tab>\<C-B>\"\<CR>", 'tx')
  2847. call assert_equal('"autocmd BufWipeout', @:)
  2848. set wildoptions&
  2849. endfunc
  2850. " vim expression fuzzy completion
  2851. func Test_fuzzy_completion_expr()
  2852. let g:PerPlaceCount = 10
  2853. set wildoptions&
  2854. call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
  2855. call assert_equal('"let c = ppc', @:)
  2856. set wildoptions=fuzzy
  2857. call feedkeys(":let c = ppc\<Tab>\<C-B>\"\<CR>", 'tx')
  2858. call assert_equal('"let c = PerPlaceCount', @:)
  2859. set wildoptions&
  2860. endfunc
  2861. " " file name fuzzy completion - NOT supported
  2862. " func Test_fuzzy_completion_filename()
  2863. " endfunc
  2864. " " files in path fuzzy completion - NOT supported
  2865. " func Test_fuzzy_completion_filesinpath()
  2866. " endfunc
  2867. " " filetype name fuzzy completion - NOT supported
  2868. " func Test_fuzzy_completion_filetype()
  2869. " endfunc
  2870. " user defined function name completion
  2871. func Test_fuzzy_completion_userdefined_func()
  2872. set wildoptions&
  2873. call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
  2874. call assert_equal('"call Test_f_u_f', @:)
  2875. set wildoptions=fuzzy
  2876. call feedkeys(":call Test_f_u_f\<Tab>\<C-B>\"\<CR>", 'tx')
  2877. call assert_equal('"call Test_fuzzy_completion_userdefined_func()', @:)
  2878. set wildoptions&
  2879. endfunc
  2880. " <SNR> functions should be sorted to the end
  2881. func Test_fuzzy_completion_userdefined_snr_func()
  2882. func s:Sendmail()
  2883. endfunc
  2884. func SendSomemail()
  2885. endfunc
  2886. func S1e2n3dmail()
  2887. endfunc
  2888. set wildoptions=fuzzy
  2889. call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
  2890. call assert_equal('"call SendSomemail() S1e2n3dmail() '
  2891. \ .. expand("<SID>") .. 'Sendmail()', @:)
  2892. set wildoptions&
  2893. delfunc s:Sendmail
  2894. delfunc SendSomemail
  2895. delfunc S1e2n3dmail
  2896. endfunc
  2897. " user defined command name completion
  2898. func Test_fuzzy_completion_userdefined_cmd()
  2899. set wildoptions&
  2900. call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
  2901. call assert_equal('"MsFeat', @:)
  2902. set wildoptions=fuzzy
  2903. call feedkeys(":MsFeat\<Tab>\<C-B>\"\<CR>", 'tx')
  2904. call assert_equal('"MissingFeature', @:)
  2905. set wildoptions&
  2906. endfunc
  2907. " " :help tag fuzzy completion - NOT supported
  2908. " func Test_fuzzy_completion_helptag()
  2909. " endfunc
  2910. " highlight group name fuzzy completion
  2911. func Test_fuzzy_completion_hlgroup()
  2912. set wildoptions&
  2913. call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
  2914. call assert_equal('"highlight SKey', @:)
  2915. call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
  2916. call assert_equal('"highlight SpecialKey', @:)
  2917. set wildoptions=fuzzy
  2918. call feedkeys(":highlight SKey\<Tab>\<C-B>\"\<CR>", 'tx')
  2919. call assert_equal('"highlight SpecialKey', @:)
  2920. call feedkeys(":highlight Sp*Key\<Tab>\<C-B>\"\<CR>", 'tx')
  2921. call assert_equal('"highlight Sp*Key', @:)
  2922. set wildoptions&
  2923. endfunc
  2924. " :history suboptions fuzzy completion
  2925. func Test_fuzzy_completion_history()
  2926. set wildoptions&
  2927. call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
  2928. call assert_equal('"history dg', @:)
  2929. call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
  2930. call assert_equal('"history search', @:)
  2931. set wildoptions=fuzzy
  2932. call feedkeys(":history dg\<Tab>\<C-B>\"\<CR>", 'tx')
  2933. call assert_equal('"history debug', @:)
  2934. call feedkeys(":history se*h\<Tab>\<C-B>\"\<CR>", 'tx')
  2935. call assert_equal('"history se*h', @:)
  2936. set wildoptions&
  2937. endfunc
  2938. " :language locale name fuzzy completion
  2939. func Test_fuzzy_completion_lang()
  2940. CheckUnix
  2941. set wildoptions&
  2942. call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
  2943. call assert_equal('"lang psx', @:)
  2944. set wildoptions=fuzzy
  2945. call feedkeys(":lang psx\<Tab>\<C-B>\"\<CR>", 'tx')
  2946. call assert_equal('"lang POSIX', @:)
  2947. set wildoptions&
  2948. endfunc
  2949. " :mapclear buffer argument fuzzy completion
  2950. func Test_fuzzy_completion_mapclear()
  2951. set wildoptions&
  2952. call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
  2953. call assert_equal('"mapclear buf', @:)
  2954. set wildoptions=fuzzy
  2955. call feedkeys(":mapclear buf\<Tab>\<C-B>\"\<CR>", 'tx')
  2956. call assert_equal('"mapclear <buffer>', @:)
  2957. set wildoptions&
  2958. endfunc
  2959. " map name fuzzy completion
  2960. func Test_fuzzy_completion_mapname()
  2961. " test regex completion works
  2962. set wildoptions=fuzzy
  2963. call feedkeys(":cnoremap <ex\<Tab> <esc> \<Tab>\<C-B>\"\<CR>", 'tx')
  2964. call assert_equal("\"cnoremap <expr> <esc> \<Tab>", @:)
  2965. nmap <plug>MyLongMap :p<CR>
  2966. call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
  2967. call assert_equal("\"nmap <Plug>MyLongMap", @:)
  2968. call feedkeys(":nmap MLM \<Tab>\<C-B>\"\<CR>", 'tx')
  2969. call assert_equal("\"nmap MLM \t", @:)
  2970. call feedkeys(":nmap <F2> one two \<Tab>\<C-B>\"\<CR>", 'tx')
  2971. call assert_equal("\"nmap <F2> one two \t", @:)
  2972. " duplicate entries should be removed
  2973. vmap <plug>MyLongMap :<C-U>#<CR>
  2974. call feedkeys(":nmap MLM\<Tab>\<C-B>\"\<CR>", 'tx')
  2975. call assert_equal("\"nmap <Plug>MyLongMap", @:)
  2976. nunmap <plug>MyLongMap
  2977. vunmap <plug>MyLongMap
  2978. call feedkeys(":nmap ABC\<Tab>\<C-B>\"\<CR>", 'tx')
  2979. call assert_equal("\"nmap ABC\t", @:)
  2980. " results should be sorted by best match
  2981. nmap <Plug>format :
  2982. nmap <Plug>goformat :
  2983. nmap <Plug>TestFOrmat :
  2984. nmap <Plug>fendoff :
  2985. nmap <Plug>state :
  2986. nmap <Plug>FendingOff :
  2987. call feedkeys(":nmap <Plug>fo\<C-A>\<C-B>\"\<CR>", 'tx')
  2988. call assert_equal("\"nmap <Plug>format <Plug>TestFOrmat <Plug>FendingOff <Plug>goformat <Plug>fendoff", @:)
  2989. nunmap <Plug>format
  2990. nunmap <Plug>goformat
  2991. nunmap <Plug>TestFOrmat
  2992. nunmap <Plug>fendoff
  2993. nunmap <Plug>state
  2994. nunmap <Plug>FendingOff
  2995. set wildoptions&
  2996. endfunc
  2997. " abbreviation fuzzy completion
  2998. func Test_fuzzy_completion_abbr()
  2999. set wildoptions=fuzzy
  3000. call feedkeys(":iabbr wait\<Tab>\<C-B>\"\<CR>", 'tx')
  3001. call assert_equal("\"iabbr <nowait>", @:)
  3002. iabbr WaitForCompletion WFC
  3003. call feedkeys(":iabbr fcl\<Tab>\<C-B>\"\<CR>", 'tx')
  3004. call assert_equal("\"iabbr WaitForCompletion", @:)
  3005. call feedkeys(":iabbr a1z\<Tab>\<C-B>\"\<CR>", 'tx')
  3006. call assert_equal("\"iabbr a1z\t", @:)
  3007. iunabbrev WaitForCompletion
  3008. set wildoptions&
  3009. endfunc
  3010. " menu name fuzzy completion
  3011. func Test_fuzzy_completion_menu()
  3012. CheckFeature menu
  3013. source $VIMRUNTIME/menu.vim
  3014. set wildoptions&
  3015. call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
  3016. call assert_equal('"menu pup', @:)
  3017. set wildoptions=fuzzy
  3018. call feedkeys(":menu pup\<Tab>\<C-B>\"\<CR>", 'tx')
  3019. call assert_equal('"menu PopUp.', @:)
  3020. set wildoptions&
  3021. source $VIMRUNTIME/delmenu.vim
  3022. endfunc
  3023. " :messages suboptions fuzzy completion
  3024. func Test_fuzzy_completion_messages()
  3025. set wildoptions&
  3026. call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
  3027. call assert_equal('"messages clr', @:)
  3028. set wildoptions=fuzzy
  3029. call feedkeys(":messages clr\<Tab>\<C-B>\"\<CR>", 'tx')
  3030. call assert_equal('"messages clear', @:)
  3031. set wildoptions&
  3032. endfunc
  3033. " :set option name fuzzy completion
  3034. func Test_fuzzy_completion_option()
  3035. set wildoptions&
  3036. call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
  3037. call assert_equal('"set brkopt', @:)
  3038. set wildoptions=fuzzy
  3039. call feedkeys(":set brkopt\<Tab>\<C-B>\"\<CR>", 'tx')
  3040. call assert_equal('"set breakindentopt', @:)
  3041. set wildoptions&
  3042. call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
  3043. call assert_equal('"set fixendofline', @:)
  3044. set wildoptions=fuzzy
  3045. call feedkeys(":set fixeol\<Tab>\<C-B>\"\<CR>", 'tx')
  3046. call assert_equal('"set fixendofline', @:)
  3047. set wildoptions&
  3048. endfunc
  3049. " :set <term_option>
  3050. func Test_fuzzy_completion_term_option()
  3051. throw 'Skipped: Nvim does not support term options'
  3052. set wildoptions&
  3053. call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
  3054. call assert_equal('"set t_EC', @:)
  3055. call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
  3056. call assert_equal('"set <t_EC>', @:)
  3057. set wildoptions=fuzzy
  3058. call feedkeys(":set t_E\<Tab>\<C-B>\"\<CR>", 'tx')
  3059. call assert_equal('"set t_EC', @:)
  3060. call feedkeys(":set <t_E\<Tab>\<C-B>\"\<CR>", 'tx')
  3061. call assert_equal('"set <t_EC>', @:)
  3062. set wildoptions&
  3063. endfunc
  3064. " " :packadd directory name fuzzy completion - NOT supported
  3065. " func Test_fuzzy_completion_packadd()
  3066. " endfunc
  3067. " " shell command name fuzzy completion - NOT supported
  3068. " func Test_fuzzy_completion_shellcmd()
  3069. " endfunc
  3070. " :sign suboptions fuzzy completion
  3071. func Test_fuzzy_completion_sign()
  3072. set wildoptions&
  3073. call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
  3074. call assert_equal('"sign ufe', @:)
  3075. set wildoptions=fuzzy
  3076. call feedkeys(":sign ufe\<Tab>\<C-B>\"\<CR>", 'tx')
  3077. call assert_equal('"sign undefine', @:)
  3078. set wildoptions&
  3079. endfunc
  3080. " :syntax suboptions fuzzy completion
  3081. func Test_fuzzy_completion_syntax_cmd()
  3082. set wildoptions&
  3083. call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
  3084. call assert_equal('"syntax kwd', @:)
  3085. set wildoptions=fuzzy
  3086. call feedkeys(":syntax kwd\<Tab>\<C-B>\"\<CR>", 'tx')
  3087. call assert_equal('"syntax keyword', @:)
  3088. set wildoptions&
  3089. endfunc
  3090. " syntax group name fuzzy completion
  3091. func Test_fuzzy_completion_syntax_group()
  3092. set wildoptions&
  3093. call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
  3094. call assert_equal('"syntax list mpar', @:)
  3095. set wildoptions=fuzzy
  3096. call feedkeys(":syntax list mpar\<Tab>\<C-B>\"\<CR>", 'tx')
  3097. " Fuzzy match prefers NvimParenthesis over MatchParen
  3098. " call assert_equal('"syntax list MatchParen', @:)
  3099. call assert_equal('"syntax list NvimParenthesis', @:)
  3100. set wildoptions&
  3101. endfunc
  3102. " :syntime suboptions fuzzy completion
  3103. func Test_fuzzy_completion_syntime()
  3104. CheckFeature profile
  3105. set wildoptions&
  3106. call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
  3107. call assert_equal('"syntime clr', @:)
  3108. set wildoptions=fuzzy
  3109. call feedkeys(":syntime clr\<Tab>\<C-B>\"\<CR>", 'tx')
  3110. call assert_equal('"syntime clear', @:)
  3111. set wildoptions&
  3112. endfunc
  3113. " " tag name fuzzy completion - NOT supported
  3114. " func Test_fuzzy_completion_tagname()
  3115. " endfunc
  3116. " " tag name and file fuzzy completion - NOT supported
  3117. " func Test_fuzzy_completion_tagfile()
  3118. " endfunc
  3119. " " user names fuzzy completion - how to test this functionality?
  3120. " func Test_fuzzy_completion_username()
  3121. " endfunc
  3122. " user defined variable name fuzzy completion
  3123. func Test_fuzzy_completion_userdefined_var()
  3124. let g:SomeVariable=10
  3125. set wildoptions&
  3126. call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
  3127. call assert_equal('"let SVar', @:)
  3128. set wildoptions=fuzzy
  3129. call feedkeys(":let SVar\<Tab>\<C-B>\"\<CR>", 'tx')
  3130. call assert_equal('"let SomeVariable', @:)
  3131. set wildoptions&
  3132. endfunc
  3133. " Test for sorting the results by the best match
  3134. func Test_fuzzy_completion_cmd_sort_results()
  3135. %bw!
  3136. command T123format :
  3137. command T123goformat :
  3138. command T123TestFOrmat :
  3139. command T123fendoff :
  3140. command T123state :
  3141. command T123FendingOff :
  3142. set wildoptions=fuzzy
  3143. call feedkeys(":T123fo\<C-A>\<C-B>\"\<CR>", 'tx')
  3144. call assert_equal('"T123format T123TestFOrmat T123FendingOff T123goformat T123fendoff', @:)
  3145. delcommand T123format
  3146. delcommand T123goformat
  3147. delcommand T123TestFOrmat
  3148. delcommand T123fendoff
  3149. delcommand T123state
  3150. delcommand T123FendingOff
  3151. %bw
  3152. set wildoptions&
  3153. endfunc
  3154. " Test for fuzzy completion of a command with lower case letters and a number
  3155. func Test_fuzzy_completion_cmd_alnum()
  3156. command Foo2Bar :
  3157. set wildoptions=fuzzy
  3158. call feedkeys(":foo2\<Tab>\<C-B>\"\<CR>", 'tx')
  3159. call assert_equal('"Foo2Bar', @:)
  3160. call feedkeys(":foo\<Tab>\<C-B>\"\<CR>", 'tx')
  3161. call assert_equal('"Foo2Bar', @:)
  3162. call feedkeys(":bar\<Tab>\<C-B>\"\<CR>", 'tx')
  3163. call assert_equal('"Foo2Bar', @:)
  3164. delcommand Foo2Bar
  3165. set wildoptions&
  3166. endfunc
  3167. " Test for command completion for a command starting with 'k'
  3168. func Test_fuzzy_completion_cmd_k()
  3169. command KillKillKill :
  3170. set wildoptions&
  3171. call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
  3172. call assert_equal("\"killkill\<Tab>", @:)
  3173. set wildoptions=fuzzy
  3174. call feedkeys(":killkill\<Tab>\<C-B>\"\<CR>", 'tx')
  3175. call assert_equal('"KillKillKill', @:)
  3176. delcom KillKillKill
  3177. set wildoptions&
  3178. endfunc
  3179. " Test for fuzzy completion for user defined custom completion function
  3180. func Test_fuzzy_completion_custom_func()
  3181. func Tcompl(a, c, p)
  3182. return "format\ngoformat\nTestFOrmat\nfendoff\nstate"
  3183. endfunc
  3184. command -nargs=* -complete=custom,Tcompl Fuzzy :
  3185. set wildoptions&
  3186. call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
  3187. call assert_equal("\"Fuzzy format", @:)
  3188. call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
  3189. call assert_equal("\"Fuzzy xy", @:)
  3190. call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
  3191. call assert_equal("\"Fuzzy ttt", @:)
  3192. set wildoptions=fuzzy
  3193. call feedkeys(":Fuzzy \<C-A>\<C-B>\"\<CR>", 'tx')
  3194. call assert_equal("\"Fuzzy format goformat TestFOrmat fendoff state", @:)
  3195. call feedkeys(":Fuzzy fo\<C-A>\<C-B>\"\<CR>", 'tx')
  3196. call assert_equal("\"Fuzzy format TestFOrmat goformat fendoff", @:)
  3197. call feedkeys(":Fuzzy xy\<Tab>\<C-B>\"\<CR>", 'tx')
  3198. call assert_equal("\"Fuzzy xy", @:)
  3199. call feedkeys(":Fuzzy ttt\<C-A>\<C-B>\"\<CR>", 'tx')
  3200. call assert_equal("\"Fuzzy TestFOrmat", @:)
  3201. delcom Fuzzy
  3202. set wildoptions&
  3203. endfunc
  3204. " Test for fuzzy completion in the middle of a cmdline instead of at the end
  3205. func Test_fuzzy_completion_in_middle()
  3206. set wildoptions=fuzzy
  3207. call feedkeys(":set ildar wrap\<Left>\<Left>\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx')
  3208. call assert_equal("\"set wildchar wildcharm wrap", @:)
  3209. call feedkeys(":args ++odng zz\<Left>\<Left>\<Left>\<C-A>\<C-B>\"\<CR>", 'tx')
  3210. call assert_equal("\"args ++encoding= zz", @:)
  3211. set wildoptions&
  3212. endfunc
  3213. " Test for :breakadd argument completion
  3214. func Test_cmdline_complete_breakadd()
  3215. call feedkeys(":breakadd \<C-A>\<C-B>\"\<CR>", 'tx')
  3216. call assert_equal("\"breakadd expr file func here", @:)
  3217. call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
  3218. call assert_equal("\"breakadd expr", @:)
  3219. call feedkeys(":breakadd \<Tab>\<C-B>\"\<CR>", 'tx')
  3220. call assert_equal("\"breakadd expr", @:)
  3221. call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
  3222. call assert_equal("\"breakadd here", @:)
  3223. call feedkeys(":breakadd he\<Tab>\<C-B>\"\<CR>", 'tx')
  3224. call assert_equal("\"breakadd here", @:)
  3225. call feedkeys(":breakadd abc\<Tab>\<C-B>\"\<CR>", 'tx')
  3226. call assert_equal("\"breakadd abc", @:)
  3227. call assert_equal(['expr', 'file', 'func', 'here'], getcompletion('', 'breakpoint'))
  3228. let l = getcompletion('not', 'breakpoint')
  3229. call assert_equal([], l)
  3230. " Test for :breakadd file [lnum] <file>
  3231. call writefile([], 'Xscript')
  3232. call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
  3233. call assert_equal("\"breakadd file Xscript", @:)
  3234. call feedkeys(":breakadd file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
  3235. call assert_equal("\"breakadd file Xscript", @:)
  3236. call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
  3237. call assert_equal("\"breakadd file 20 Xscript", @:)
  3238. call feedkeys(":breakadd file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
  3239. call assert_equal("\"breakadd file 20 Xscript", @:)
  3240. call feedkeys(":breakadd file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
  3241. call assert_equal("\"breakadd file 20x Xsc\t", @:)
  3242. call feedkeys(":breakadd file 20\<Tab>\<C-B>\"\<CR>", 'tx')
  3243. call assert_equal("\"breakadd file 20\t", @:)
  3244. call feedkeys(":breakadd file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
  3245. call assert_equal("\"breakadd file 20x\t", @:)
  3246. call feedkeys(":breakadd file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
  3247. call assert_equal("\"breakadd file Xscript ", @:)
  3248. call feedkeys(":breakadd file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
  3249. call assert_equal("\"breakadd file X1B2C3", @:)
  3250. call delete('Xscript')
  3251. " Test for :breakadd func [lnum] <function>
  3252. func Xbreak_func()
  3253. endfunc
  3254. call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
  3255. call assert_equal("\"breakadd func Xbreak_func", @:)
  3256. call feedkeys(":breakadd func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
  3257. call assert_equal("\"breakadd func Xbreak_func", @:)
  3258. call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
  3259. call assert_equal("\"breakadd func 20 Xbreak_func", @:)
  3260. call feedkeys(":breakadd func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
  3261. call assert_equal("\"breakadd func 20 Xbreak_func", @:)
  3262. call feedkeys(":breakadd func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
  3263. call assert_equal("\"breakadd func 20x Xbr\t", @:)
  3264. call feedkeys(":breakadd func 20\<Tab>\<C-B>\"\<CR>", 'tx')
  3265. call assert_equal("\"breakadd func 20\t", @:)
  3266. call feedkeys(":breakadd func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
  3267. call assert_equal("\"breakadd func 20x\t", @:)
  3268. call feedkeys(":breakadd func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
  3269. call assert_equal("\"breakadd func Xbreak_func ", @:)
  3270. call feedkeys(":breakadd func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
  3271. call assert_equal("\"breakadd func X1B2C3", @:)
  3272. delfunc Xbreak_func
  3273. " Test for :breakadd expr <expression>
  3274. let g:Xtest_var = 10
  3275. call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
  3276. call assert_equal("\"breakadd expr Xtest_var", @:)
  3277. call feedkeys(":breakadd expr Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
  3278. call assert_equal("\"breakadd expr Xtest_var", @:)
  3279. call feedkeys(":breakadd expr Xtest_var \<Tab>\<C-B>\"\<CR>", 'tx')
  3280. call assert_equal("\"breakadd expr Xtest_var ", @:)
  3281. call feedkeys(":breakadd expr X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
  3282. call assert_equal("\"breakadd expr X1B2C3", @:)
  3283. unlet g:Xtest_var
  3284. " Test for :breakadd here
  3285. call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
  3286. call assert_equal("\"breakadd here Xtest", @:)
  3287. call feedkeys(":breakadd here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
  3288. call assert_equal("\"breakadd here Xtest", @:)
  3289. call feedkeys(":breakadd here \<Tab>\<C-B>\"\<CR>", 'tx')
  3290. call assert_equal("\"breakadd here ", @:)
  3291. endfunc
  3292. " Test for :breakdel argument completion
  3293. func Test_cmdline_complete_breakdel()
  3294. call feedkeys(":breakdel \<C-A>\<C-B>\"\<CR>", 'tx')
  3295. call assert_equal("\"breakdel file func here", @:)
  3296. call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
  3297. call assert_equal("\"breakdel file", @:)
  3298. call feedkeys(":breakdel \<Tab>\<C-B>\"\<CR>", 'tx')
  3299. call assert_equal("\"breakdel file", @:)
  3300. call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
  3301. call assert_equal("\"breakdel here", @:)
  3302. call feedkeys(":breakdel he\<Tab>\<C-B>\"\<CR>", 'tx')
  3303. call assert_equal("\"breakdel here", @:)
  3304. call feedkeys(":breakdel abc\<Tab>\<C-B>\"\<CR>", 'tx')
  3305. call assert_equal("\"breakdel abc", @:)
  3306. " Test for :breakdel file [lnum] <file>
  3307. call writefile([], 'Xscript')
  3308. call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
  3309. call assert_equal("\"breakdel file Xscript", @:)
  3310. call feedkeys(":breakdel file Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
  3311. call assert_equal("\"breakdel file Xscript", @:)
  3312. call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
  3313. call assert_equal("\"breakdel file 20 Xscript", @:)
  3314. call feedkeys(":breakdel file 20 Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
  3315. call assert_equal("\"breakdel file 20 Xscript", @:)
  3316. call feedkeys(":breakdel file 20x Xsc\<Tab>\<C-B>\"\<CR>", 'tx')
  3317. call assert_equal("\"breakdel file 20x Xsc\t", @:)
  3318. call feedkeys(":breakdel file 20\<Tab>\<C-B>\"\<CR>", 'tx')
  3319. call assert_equal("\"breakdel file 20\t", @:)
  3320. call feedkeys(":breakdel file 20x\<Tab>\<C-B>\"\<CR>", 'tx')
  3321. call assert_equal("\"breakdel file 20x\t", @:)
  3322. call feedkeys(":breakdel file Xscript \<Tab>\<C-B>\"\<CR>", 'tx')
  3323. call assert_equal("\"breakdel file Xscript ", @:)
  3324. call feedkeys(":breakdel file X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
  3325. call assert_equal("\"breakdel file X1B2C3", @:)
  3326. call delete('Xscript')
  3327. " Test for :breakdel func [lnum] <function>
  3328. func Xbreak_func()
  3329. endfunc
  3330. call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
  3331. call assert_equal("\"breakdel func Xbreak_func", @:)
  3332. call feedkeys(":breakdel func Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
  3333. call assert_equal("\"breakdel func Xbreak_func", @:)
  3334. call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
  3335. call assert_equal("\"breakdel func 20 Xbreak_func", @:)
  3336. call feedkeys(":breakdel func 20 Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
  3337. call assert_equal("\"breakdel func 20 Xbreak_func", @:)
  3338. call feedkeys(":breakdel func 20x Xbr\<Tab>\<C-B>\"\<CR>", 'tx')
  3339. call assert_equal("\"breakdel func 20x Xbr\t", @:)
  3340. call feedkeys(":breakdel func 20\<Tab>\<C-B>\"\<CR>", 'tx')
  3341. call assert_equal("\"breakdel func 20\t", @:)
  3342. call feedkeys(":breakdel func 20x\<Tab>\<C-B>\"\<CR>", 'tx')
  3343. call assert_equal("\"breakdel func 20x\t", @:)
  3344. call feedkeys(":breakdel func Xbreak_func \<Tab>\<C-B>\"\<CR>", 'tx')
  3345. call assert_equal("\"breakdel func Xbreak_func ", @:)
  3346. call feedkeys(":breakdel func X1B2C3\<Tab>\<C-B>\"\<CR>", 'tx')
  3347. call assert_equal("\"breakdel func X1B2C3", @:)
  3348. delfunc Xbreak_func
  3349. " Test for :breakdel here
  3350. call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
  3351. call assert_equal("\"breakdel here Xtest", @:)
  3352. call feedkeys(":breakdel here Xtest\<Tab>\<C-B>\"\<CR>", 'tx')
  3353. call assert_equal("\"breakdel here Xtest", @:)
  3354. call feedkeys(":breakdel here \<Tab>\<C-B>\"\<CR>", 'tx')
  3355. call assert_equal("\"breakdel here ", @:)
  3356. endfunc
  3357. " Test for :scriptnames argument completion
  3358. func Test_cmdline_complete_scriptnames()
  3359. set wildmenu
  3360. call writefile(['let a = 1'], 'Xa1b2c3.vim')
  3361. source Xa1b2c3.vim
  3362. call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
  3363. call assert_match("\"script .*Xa1b2c3.vim$", @:)
  3364. call feedkeys(":script \<Tab>\<Left>\<Left>\<C-B>\"\<CR>", 'tx')
  3365. call assert_match("\"script .*Xa1b2c3.vim$", @:)
  3366. call feedkeys(":script b2c3\<Tab>\<C-B>\"\<CR>", 'tx')
  3367. call assert_equal("\"script b2c3", @:)
  3368. call feedkeys(":script 2\<Tab>\<C-B>\"\<CR>", 'tx')
  3369. call assert_match("\"script 2\<Tab>$", @:)
  3370. call feedkeys(":script \<Tab>\<Left>\<Left> \<Tab>\<C-B>\"\<CR>", 'tx')
  3371. call assert_match("\"script .*Xa1b2c3.vim $", @:)
  3372. call feedkeys(":script \<Tab>\<Left>\<C-B>\"\<CR>", 'tx')
  3373. call assert_equal("\"script ", @:)
  3374. call assert_match('Xa1b2c3.vim$', getcompletion('.*Xa1b2.*', 'scriptnames')[0])
  3375. call assert_equal([], getcompletion('Xa1b2', 'scriptnames'))
  3376. new
  3377. call feedkeys(":script \<Tab>\<Left>\<Left>\<CR>", 'tx')
  3378. call assert_equal('Xa1b2c3.vim', fnamemodify(@%, ':t'))
  3379. bw!
  3380. call delete('Xa1b2c3.vim')
  3381. set wildmenu&
  3382. endfunc
  3383. " this was going over the end of IObuff
  3384. func Test_report_error_with_composing()
  3385. let caught = 'no'
  3386. try
  3387. exe repeat('0', 987) .. "0\xdd\x80\xdd\x80\xdd\x80\xdd\x80"
  3388. catch /E492:/
  3389. let caught = 'yes'
  3390. endtry
  3391. call assert_equal('yes', caught)
  3392. endfunc
  3393. " Test for expanding 2-letter and 3-letter :substitute command arguments.
  3394. " These commands don't accept an argument.
  3395. func Test_cmdline_complete_substitute_short()
  3396. for cmd in ['sc', 'sce', 'scg', 'sci', 'scI', 'scn', 'scp', 'scl',
  3397. \ 'sgc', 'sge', 'sg', 'sgi', 'sgI', 'sgn', 'sgp', 'sgl', 'sgr',
  3398. \ 'sic', 'sie', 'si', 'siI', 'sin', 'sip', 'sir',
  3399. \ 'sIc', 'sIe', 'sIg', 'sIi', 'sI', 'sIn', 'sIp', 'sIl', 'sIr',
  3400. \ 'src', 'srg', 'sri', 'srI', 'srn', 'srp', 'srl', 'sr']
  3401. call feedkeys(':' .. cmd .. " \<Tab>\<C-B>\"\<CR>", 'tx')
  3402. call assert_equal('"' .. cmd .. " \<Tab>", @:)
  3403. endfor
  3404. endfunc
  3405. " Test for shellcmdline command argument completion
  3406. func Test_cmdline_complete_shellcmdline_argument()
  3407. command -nargs=+ -complete=shellcmdline MyCmd
  3408. set wildoptions=fuzzy
  3409. call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
  3410. call assert_equal('"MyCmd vim test_cmdline.vim', @:)
  3411. call assert_equal(['test_cmdline.vim'],
  3412. \ getcompletion('vim test_cmdline.', 'shellcmdline'))
  3413. call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
  3414. call assert_equal('"MyCmd vim nonexistentfile', @:)
  3415. call assert_equal([],
  3416. \ getcompletion('vim nonexistentfile', 'shellcmdline'))
  3417. let compl1 = getcompletion('', 'file')[0]
  3418. let compl2 = getcompletion('', 'file')[1]
  3419. call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt')
  3420. call assert_equal('"MyCmd vim ' .. compl1, @:)
  3421. call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt')
  3422. call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:)
  3423. let compl = getcompletion('', 'file')[1]
  3424. call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
  3425. call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:)
  3426. set wildoptions&
  3427. call feedkeys(":MyCmd vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
  3428. call assert_equal('"MyCmd vim test_cmdline.vim', @:)
  3429. call assert_equal(['test_cmdline.vim'],
  3430. \ getcompletion('vim test_cmdline.', 'shellcmdline'))
  3431. call feedkeys(":MyCmd vim nonexistentfile\<Tab>\<C-B>\"\<CR>", 'xt')
  3432. call assert_equal('"MyCmd vim nonexistentfile', @:)
  3433. call assert_equal([],
  3434. \ getcompletion('vim nonexistentfile', 'shellcmdline'))
  3435. let compl1 = getcompletion('', 'file')[0]
  3436. let compl2 = getcompletion('', 'file')[1]
  3437. call feedkeys(":MyCmd vim \<Tab>\<C-B>\"\<CR>", 'xt')
  3438. call assert_equal('"MyCmd vim ' .. compl1, @:)
  3439. call feedkeys(":MyCmd vim \<Tab> \<Tab>\<C-B>\"\<CR>", 'xt')
  3440. call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl1, @:)
  3441. let compl = getcompletion('', 'file')[1]
  3442. call feedkeys(":MyCmd vim \<Tab> \<Tab>\<Tab>\<C-B>\"\<CR>", 'xt')
  3443. call assert_equal('"MyCmd vim ' .. compl1 .. ' ' .. compl2, @:)
  3444. delcommand MyCmd
  3445. endfunc
  3446. " Test for :! shell command argument completion
  3447. func Test_cmdline_complete_bang_cmd_argument()
  3448. set wildoptions=fuzzy
  3449. call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
  3450. call assert_equal('"!vim test_cmdline.vim', @:)
  3451. set wildoptions&
  3452. call feedkeys(":!vim test_cmdline.\<Tab>\<C-B>\"\<CR>", 'xt')
  3453. call assert_equal('"!vim test_cmdline.vim', @:)
  3454. endfunc
  3455. func Call_cmd_funcs()
  3456. return [getcmdpos(), getcmdscreenpos(), getcmdcompltype(), getcmdcomplpat()]
  3457. endfunc
  3458. func Test_screenpos_and_completion()
  3459. call assert_equal(0, getcmdpos())
  3460. call assert_equal(0, getcmdscreenpos())
  3461. call assert_equal('', getcmdcompltype())
  3462. call assert_equal('', getcmdcomplpat())
  3463. cnoremap <expr> <F2> string(Call_cmd_funcs())
  3464. call feedkeys(":let a\<F2>\<C-B>\"\<CR>", "xt")
  3465. call assert_equal("\"let a[6, 7, 'var', 'a']", @:)
  3466. call feedkeys(":quit \<F2>\<C-B>\"\<CR>", "xt")
  3467. call assert_equal("\"quit [6, 7, '', '']", @:)
  3468. call feedkeys(":nosuchcommand \<F2>\<C-B>\"\<CR>", "xt")
  3469. call assert_equal("\"nosuchcommand [15, 16, '', '']", @:)
  3470. " Check that getcmdcompltype() and getcmdcomplpat() don't interfere with
  3471. " cmdline completion.
  3472. let g:results = []
  3473. cnoremap <F2> <Cmd>let g:results += [[getcmdline()] + Call_cmd_funcs()]<CR>
  3474. call feedkeys(":sign un\<Tab>\<F2>\<Tab>\<F2>\<Tab>\<F2>\<C-C>", "xt")
  3475. call assert_equal([
  3476. \ ['sign undefine', 14, 15, 'sign', 'undefine'],
  3477. \ ['sign unplace', 13, 14, 'sign', 'unplace'],
  3478. \ ['sign un', 8, 9, 'sign', 'un']], g:results)
  3479. unlet g:results
  3480. cunmap <F2>
  3481. endfunc
  3482. func Test_recursive_register()
  3483. let @= = ''
  3484. silent! ?e/
  3485. let caught = 'no'
  3486. try
  3487. normal //
  3488. catch /E169:/
  3489. let caught = 'yes'
  3490. endtry
  3491. call assert_equal('yes', caught)
  3492. endfunc
  3493. func Test_long_error_message()
  3494. " the error should be truncated, not overrun IObuff
  3495. silent! norm Q00000000000000     000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000                                                                                                                                                                                                                        
  3496. endfunc
  3497. func Test_cmdline_redraw_tabline()
  3498. CheckRunVimInTerminal
  3499. let lines =<< trim END
  3500. set showtabline=2
  3501. autocmd CmdlineEnter * set tabline=foo
  3502. END
  3503. call writefile(lines, 'Xcmdline_redraw_tabline')
  3504. let buf = RunVimInTerminal('-S Xcmdline_redraw_tabline', #{rows: 6})
  3505. call term_sendkeys(buf, ':')
  3506. call WaitForAssert({-> assert_match('^foo', term_getline(buf, 1))})
  3507. call StopVimInTerminal(buf)
  3508. call delete('Xcmdline_redraw_tabline')
  3509. endfunc
  3510. func Test_wildmenu_pum_disable_while_shown()
  3511. set wildoptions=pum
  3512. set wildmenu
  3513. cnoremap <F2> <Cmd>set nowildmenu<CR>
  3514. call feedkeys(":sign \<Tab>\<F2>\<Esc>", 'tx')
  3515. call assert_equal(0, pumvisible())
  3516. cunmap <F2>
  3517. set wildoptions& wildmenu&
  3518. endfunc
  3519. func Test_setcmdline()
  3520. func SetText(text, pos)
  3521. call assert_equal(0, setcmdline(v:_null_string))
  3522. call assert_equal('', getcmdline())
  3523. call assert_equal(1, getcmdpos())
  3524. call assert_equal(0, setcmdline(''[: -1]))
  3525. call assert_equal('', getcmdline())
  3526. call assert_equal(1, getcmdpos())
  3527. autocmd CmdlineChanged * let g:cmdtype = expand('<afile>')
  3528. call assert_equal(0, setcmdline(a:text))
  3529. call assert_equal(a:text, getcmdline())
  3530. call assert_equal(len(a:text) + 1, getcmdpos())
  3531. call assert_equal(getcmdtype(), g:cmdtype)
  3532. unlet g:cmdtype
  3533. autocmd! CmdlineChanged
  3534. call assert_equal(0, setcmdline(a:text, a:pos))
  3535. call assert_equal(a:text, getcmdline())
  3536. call assert_equal(a:pos, getcmdpos())
  3537. call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:')
  3538. call assert_fails('call setcmdline({}, 0)', 'E1174:')
  3539. call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E1210:')
  3540. return ''
  3541. endfunc
  3542. call feedkeys(":\<C-R>=SetText('set rtp?', 2)\<CR>\<CR>", 'xt')
  3543. call assert_equal('set rtp?', @:)
  3544. call feedkeys(":let g:str = input('? ')\<CR>", 't')
  3545. call feedkeys("\<C-R>=SetText('foo', 4)\<CR>\<CR>", 'xt')
  3546. call assert_equal('foo', g:str)
  3547. unlet g:str
  3548. delfunc SetText
  3549. " setcmdline() returns 1 when not editing the command line.
  3550. call assert_equal(1, 'foo'->setcmdline())
  3551. " Called in custom function
  3552. func CustomComplete(A, L, P)
  3553. call assert_equal(0, setcmdline("DoCmd "))
  3554. return "January\nFebruary\nMars\n"
  3555. endfunc
  3556. com! -nargs=* -complete=custom,CustomComplete DoCmd :
  3557. call feedkeys(":DoCmd \<C-A>\<C-B>\"\<CR>", 'tx')
  3558. call assert_equal('"DoCmd January February Mars', @:)
  3559. delcom DoCmd
  3560. delfunc CustomComplete
  3561. " Called in <expr>
  3562. cnoremap <expr>a setcmdline('let foo=')
  3563. call feedkeys(":a\<CR>", 'tx')
  3564. call assert_equal('let foo=0', @:)
  3565. cunmap a
  3566. endfunc
  3567. func Test_rulerformat_position()
  3568. CheckScreendump
  3569. let buf = RunVimInTerminal('', #{rows: 2, cols: 20})
  3570. call term_sendkeys(buf, ":set ruler rulerformat=longish\<CR>")
  3571. call term_sendkeys(buf, ":set laststatus=0 winwidth=1\<CR>")
  3572. call term_sendkeys(buf, "\<C-W>v\<C-W>|\<C-W>p")
  3573. call VerifyScreenDump(buf, 'Test_rulerformat_position', {})
  3574. " clean up
  3575. call StopVimInTerminal(buf)
  3576. endfunc
  3577. " Test for using "%!" in 'rulerformat' to use a function
  3578. func Test_rulerformat_function()
  3579. CheckScreendump
  3580. let lines =<< trim END
  3581. func TestRulerFn()
  3582. return '10,20%=30%%'
  3583. endfunc
  3584. END
  3585. call writefile(lines, 'Xrulerformat_function', 'D')
  3586. let buf = RunVimInTerminal('-S Xrulerformat_function', #{rows: 2, cols: 40})
  3587. call term_sendkeys(buf, ":set ruler rulerformat=%!TestRulerFn()\<CR>")
  3588. call term_sendkeys(buf, ":redraw!\<CR>")
  3589. call term_wait(buf)
  3590. call VerifyScreenDump(buf, 'Test_rulerformat_function', {})
  3591. " clean up
  3592. call StopVimInTerminal(buf)
  3593. endfunc
  3594. func Test_getcompletion_usercmd()
  3595. command! -nargs=* -complete=command TestCompletion echo <q-args>
  3596. call assert_equal(getcompletion('', 'cmdline'),
  3597. \ getcompletion('TestCompletion ', 'cmdline'))
  3598. call assert_equal(['<buffer>'],
  3599. \ getcompletion('TestCompletion map <bu', 'cmdline'))
  3600. delcom TestCompletion
  3601. endfunc
  3602. func Test_custom_completion()
  3603. func CustomComplete1(lead, line, pos)
  3604. return "a\nb\nc"
  3605. endfunc
  3606. func CustomComplete2(lead, line, pos)
  3607. return ['a', 'b']->filter({ _, val -> val->stridx(a:lead) == 0 })
  3608. endfunc
  3609. func Check_custom_completion()
  3610. call assert_equal('custom,CustomComplete1', getcmdcompltype())
  3611. return ''
  3612. endfunc
  3613. func Check_customlist_completion()
  3614. call assert_equal('customlist,CustomComplete2', getcmdcompltype())
  3615. return ''
  3616. endfunc
  3617. command -nargs=1 -complete=custom,CustomComplete1 Test1 echo
  3618. command -nargs=1 -complete=customlist,CustomComplete2 Test2 echo
  3619. call feedkeys(":Test1 \<C-R>=Check_custom_completion()\<CR>\<Esc>", "xt")
  3620. call feedkeys(":Test2 \<C-R>=Check_customlist_completion()\<CR>\<Esc>", "xt")
  3621. call assert_fails("call getcompletion('', 'custom')", 'E475:')
  3622. call assert_fails("call getcompletion('', 'customlist')", 'E475:')
  3623. call assert_equal(['a', 'b', 'c'], getcompletion('', 'custom,CustomComplete1'))
  3624. call assert_equal(['a', 'b'], getcompletion('', 'customlist,CustomComplete2'))
  3625. call assert_equal(['b'], getcompletion('b', 'customlist,CustomComplete2'))
  3626. delcom Test1
  3627. delcom Test2
  3628. delfunc CustomComplete1
  3629. delfunc CustomComplete2
  3630. delfunc Check_custom_completion
  3631. delfunc Check_customlist_completion
  3632. endfunc
  3633. func Test_custom_completion_with_glob()
  3634. func TestGlobComplete(A, L, P)
  3635. return split(glob('Xglob*'), "\n")
  3636. endfunc
  3637. command -nargs=* -complete=customlist,TestGlobComplete TestGlobComplete :
  3638. call writefile([], 'Xglob1', 'D')
  3639. call writefile([], 'Xglob2', 'D')
  3640. call feedkeys(":TestGlobComplete \<Tab> \<Tab>\<C-N> \<Tab>\<C-P>;\<C-B>\"\<CR>", 'xt')
  3641. call assert_equal('"TestGlobComplete Xglob1 Xglob2 ;', @:)
  3642. delcommand TestGlobComplete
  3643. delfunc TestGlobComplete
  3644. endfunc
  3645. func Test_window_size_stays_same_after_changing_cmdheight()
  3646. set laststatus=2
  3647. let expected = winheight(0)
  3648. function! Function_name() abort
  3649. call feedkeys(":"..repeat('x', &columns), 'x')
  3650. let &cmdheight=2
  3651. let &cmdheight=1
  3652. redraw
  3653. endfunction
  3654. call Function_name()
  3655. call assert_equal(expected, winheight(0))
  3656. endfunc
  3657. " verify that buffer-completion finds all buffer names matching a pattern
  3658. func Test_buffer_completion()
  3659. " should return empty list
  3660. call assert_equal([], getcompletion('', 'buffer'))
  3661. call mkdir('Xbuf_complete', 'R')
  3662. e Xbuf_complete/Foobar.c
  3663. e Xbuf_complete/MyFoobar.c
  3664. e AFoobar.h
  3665. let expected = ["Xbuf_complete/Foobar.c", "Xbuf_complete/MyFoobar.c", "AFoobar.h"]
  3666. call assert_equal(3, len(getcompletion('Foo', 'buffer')))
  3667. call assert_equal(expected, getcompletion('Foo', 'buffer'))
  3668. call feedkeys(":b Foo\<C-A>\<C-B>\"\<CR>", 'xt')
  3669. call assert_equal("\"b Xbuf_complete/Foobar.c Xbuf_complete/MyFoobar.c AFoobar.h", @:)
  3670. endfunc
  3671. " :set t_??
  3672. func Test_term_option()
  3673. throw 'Skipped: Nvim does not support termcap options'
  3674. set wildoptions&
  3675. let _cpo = &cpo
  3676. set cpo-=C
  3677. " There may be more, test only until t_xo
  3678. let expected='"set t_AB t_AF t_AU t_AL t_al t_bc t_BE t_BD t_cd t_ce t_Ce t_CF t_cl t_cm'
  3679. \ .. ' t_Co t_CS t_Cs t_cs t_CV t_da t_db t_DL t_dl t_ds t_Ds t_EC t_EI t_fs t_fd t_fe'
  3680. \ .. ' t_GP t_IE t_IS t_ke t_ks t_le t_mb t_md t_me t_mr t_ms t_nd t_op t_RF t_RB t_RC'
  3681. \ .. ' t_RI t_Ri t_RK t_RS t_RT t_RV t_Sb t_SC t_se t_Sf t_SH t_SI t_Si t_so t_SR t_sr'
  3682. \ .. ' t_ST t_Te t_te t_TE t_ti t_TI t_Ts t_ts t_u7 t_ue t_us t_Us t_ut t_vb t_ve t_vi'
  3683. \ .. ' t_VS t_vs t_WP t_WS t_XM t_xn t_xs t_ZH t_ZR t_8f t_8b t_8u t_xo .*'
  3684. call feedkeys(":set t_\<C-A>\<C-B>\"\<CR>", 'tx')
  3685. call assert_match(expected, @:)
  3686. let &cpo = _cpo
  3687. endfunc
  3688. func Test_cd_bslash_completion_windows()
  3689. CheckMSWindows
  3690. let save_shellslash = &shellslash
  3691. set noshellslash
  3692. call system('mkdir XXXa\_b')
  3693. defer delete('XXXa', 'rf')
  3694. call feedkeys(":cd XXXa\\_b\<C-A>\<C-B>\"\<CR>", 'tx')
  3695. call assert_equal('"cd XXXa\_b\', @:)
  3696. let &shellslash = save_shellslash
  3697. endfunc
  3698. " Test cmdcomplete_info() with CmdlineLeavePre autocmd
  3699. func Test_cmdcomplete_info()
  3700. augroup test_CmdlineLeavePre
  3701. autocmd!
  3702. " Calling expand() should not interfere with cmdcomplete_info().
  3703. autocmd CmdlineLeavePre * call expand('test_cmdline.*')
  3704. autocmd CmdlineLeavePre * let g:cmdcomplete_info = string(cmdcomplete_info())
  3705. augroup END
  3706. new
  3707. call assert_equal({}, cmdcomplete_info())
  3708. call feedkeys(":h echom\<cr>", "tx") " No expansion
  3709. call assert_equal('{}', g:cmdcomplete_info)
  3710. call feedkeys(":h echoms\<tab>\<cr>", "tx")
  3711. call assert_equal('{''cmdline_orig'': '''', ''pum_visible'': 0, ''matches'': [], ''selected'': 0}', g:cmdcomplete_info)
  3712. call feedkeys(":h echom\<tab>\<cr>", "tx")
  3713. call assert_equal(
  3714. \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 0, ''matches'': ['':echom'', '':echomsg''], ''selected'': 0}',
  3715. \ g:cmdcomplete_info)
  3716. call feedkeys(":h echom\<tab>\<tab>\<cr>", "tx")
  3717. call assert_equal(
  3718. \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 0, ''matches'': ['':echom'', '':echomsg''], ''selected'': 1}',
  3719. \ g:cmdcomplete_info)
  3720. call feedkeys(":h echom\<tab>\<tab>\<tab>\<cr>", "tx")
  3721. call assert_equal(
  3722. \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 0, ''matches'': ['':echom'', '':echomsg''], ''selected'': -1}',
  3723. \ g:cmdcomplete_info)
  3724. set wildoptions=pum
  3725. call feedkeys(":h echoms\<tab>\<cr>", "tx")
  3726. call assert_equal('{''cmdline_orig'': '''', ''pum_visible'': 0, ''matches'': [], ''selected'': 0}', g:cmdcomplete_info)
  3727. call feedkeys(":h echom\<tab>\<cr>", "tx")
  3728. call assert_equal(
  3729. \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 1, ''matches'': ['':echom'', '':echomsg''], ''selected'': 0}',
  3730. \ g:cmdcomplete_info)
  3731. call feedkeys(":h echom\<tab>\<tab>\<cr>", "tx")
  3732. call assert_equal(
  3733. \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 1, ''matches'': ['':echom'', '':echomsg''], ''selected'': 1}',
  3734. \ g:cmdcomplete_info)
  3735. call feedkeys(":h echom\<tab>\<tab>\<tab>\<cr>", "tx")
  3736. call assert_equal(
  3737. \ '{''cmdline_orig'': ''h echom'', ''pum_visible'': 1, ''matches'': ['':echom'', '':echomsg''], ''selected'': -1}',
  3738. \ g:cmdcomplete_info)
  3739. bw!
  3740. set wildoptions&
  3741. endfunc
  3742. " vim: shiftwidth=2 sts=2 expandtab