test_normal.vim 112 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307
  1. " Test for various Normal mode commands
  2. source shared.vim
  3. source check.vim
  4. source view_util.vim
  5. source vim9.vim
  6. source screendump.vim
  7. func Setup_NewWindow()
  8. 10new
  9. call setline(1, range(1,100))
  10. endfunc
  11. func MyFormatExpr()
  12. " Adds '->$' at lines having numbers followed by trailing whitespace
  13. for ln in range(v:lnum, v:lnum+v:count-1)
  14. let line = getline(ln)
  15. if getline(ln) =~# '\d\s\+$'
  16. call setline(ln, substitute(line, '\s\+$', '', '') . '->$')
  17. endif
  18. endfor
  19. endfunc
  20. func CountSpaces(type, ...)
  21. " for testing operatorfunc
  22. " will count the number of spaces
  23. " and return the result in g:a
  24. let sel_save = &selection
  25. let &selection = "inclusive"
  26. let reg_save = @@
  27. if a:0 " Invoked from Visual mode, use gv command.
  28. silent exe "normal! gvy"
  29. elseif a:type == 'line'
  30. silent exe "normal! '[V']y"
  31. else
  32. silent exe "normal! `[v`]y"
  33. endif
  34. let g:a = strlen(substitute(@@, '[^ ]', '', 'g'))
  35. let &selection = sel_save
  36. let @@ = reg_save
  37. endfunc
  38. func OpfuncDummy(type, ...)
  39. " for testing operatorfunc
  40. let g:opt = &linebreak
  41. if a:0 " Invoked from Visual mode, use gv command.
  42. silent exe "normal! gvy"
  43. elseif a:type == 'line'
  44. silent exe "normal! '[V']y"
  45. else
  46. silent exe "normal! `[v`]y"
  47. endif
  48. " Create a new dummy window
  49. new
  50. let g:bufnr = bufnr('%')
  51. endfunc
  52. func Test_normal00_optrans()
  53. new
  54. call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line'])
  55. 1
  56. exe "norm! Sfoobar\<esc>"
  57. call assert_equal(['foobar', '2 This is the second line', '3 this is the third line', ''], getline(1,'$'))
  58. 2
  59. exe "norm! $vbsone"
  60. call assert_equal(['foobar', '2 This is the second one', '3 this is the third line', ''], getline(1,'$'))
  61. norm! VS Second line here
  62. call assert_equal(['foobar', ' Second line here', '3 this is the third line', ''], getline(1, '$'))
  63. %d
  64. call append(0, ['4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line'])
  65. call append(0, ['1 This is a simple test: abcd', '2 This is the second line', '3 this is the third line'])
  66. 1
  67. norm! 2D
  68. call assert_equal(['3 this is the third line', '4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line', ''], getline(1,'$'))
  69. " Nvim: no "#" flag in 'cpoptions'.
  70. " set cpo+=#
  71. " norm! 4D
  72. " call assert_equal(['', '4 This is a simple test: abcd', '5 This is the second line', '6 this is the third line', ''], getline(1,'$'))
  73. " clean up
  74. set cpo-=#
  75. bw!
  76. endfunc
  77. func Test_normal01_keymodel()
  78. call Setup_NewWindow()
  79. " Test 1: depending on 'keymodel' <s-down> does something different
  80. 50
  81. call feedkeys("V\<S-Up>y", 'tx')
  82. call assert_equal(['47', '48', '49', '50'], getline("'<", "'>"))
  83. set keymodel=startsel
  84. 50
  85. call feedkeys("V\<S-Up>y", 'tx')
  86. call assert_equal(['49', '50'], getline("'<", "'>"))
  87. " Start visual mode when keymodel = startsel
  88. 50
  89. call feedkeys("\<S-Up>y", 'tx')
  90. call assert_equal(['49', '5'], getreg(0, 0, 1))
  91. " Use the different Shift special keys
  92. 50
  93. call feedkeys("\<S-Right>\<S-Left>\<S-Up>\<S-Down>\<S-Home>\<S-End>y", 'tx')
  94. call assert_equal(['50'], getline("'<", "'>"))
  95. call assert_equal(['50', ''], getreg(0, 0, 1))
  96. " Do not start visual mode when keymodel=
  97. set keymodel=
  98. 50
  99. call feedkeys("\<S-Up>y$", 'tx')
  100. call assert_equal(['42'], getreg(0, 0, 1))
  101. " Stop visual mode when keymodel=stopsel
  102. set keymodel=stopsel
  103. 50
  104. call feedkeys("Vkk\<Up>yy", 'tx')
  105. call assert_equal(['47'], getreg(0, 0, 1))
  106. set keymodel=
  107. 50
  108. call feedkeys("Vkk\<Up>yy", 'tx')
  109. call assert_equal(['47', '48', '49', '50'], getreg(0, 0, 1))
  110. " Test for using special keys to start visual selection
  111. %d
  112. call setline(1, ['red fox tail', 'red fox tail', 'red fox tail'])
  113. set keymodel=startsel
  114. " Test for <S-PageUp> and <S-PageDown>
  115. call cursor(1, 1)
  116. call feedkeys("\<S-PageDown>y", 'xt')
  117. call assert_equal([0, 1, 1, 0], getpos("'<"))
  118. call assert_equal([0, 3, 1, 0], getpos("'>"))
  119. call feedkeys("Gz\<CR>8|\<S-PageUp>y", 'xt')
  120. call assert_equal([0, 3, 1, 0], getpos("'<"))
  121. call assert_equal([0, 3, 8, 0], getpos("'>"))
  122. " Test for <S-C-Home> and <S-C-End>
  123. call cursor(2, 12)
  124. call feedkeys("\<S-C-Home>y", 'xt')
  125. call assert_equal([0, 1, 1, 0], getpos("'<"))
  126. call assert_equal([0, 2, 12, 0], getpos("'>"))
  127. call cursor(1, 4)
  128. call feedkeys("\<S-C-End>y", 'xt')
  129. call assert_equal([0, 1, 4, 0], getpos("'<"))
  130. call assert_equal([0, 3, 13, 0], getpos("'>"))
  131. " Test for <S-C-Left> and <S-C-Right>
  132. call cursor(2, 5)
  133. call feedkeys("\<S-C-Right>y", 'xt')
  134. call assert_equal([0, 2, 5, 0], getpos("'<"))
  135. call assert_equal([0, 2, 9, 0], getpos("'>"))
  136. call cursor(2, 9)
  137. call feedkeys("\<S-C-Left>y", 'xt')
  138. call assert_equal([0, 2, 5, 0], getpos("'<"))
  139. call assert_equal([0, 2, 9, 0], getpos("'>"))
  140. set keymodel&
  141. " clean up
  142. bw!
  143. endfunc
  144. func Test_normal03_join()
  145. " basic join test
  146. call Setup_NewWindow()
  147. 50
  148. norm! VJ
  149. call assert_equal('50 51', getline('.'))
  150. $
  151. norm! J
  152. call assert_equal('100', getline('.'))
  153. $
  154. norm! V9-gJ
  155. call assert_equal('919293949596979899100', getline('.'))
  156. call setline(1, range(1,100))
  157. $
  158. :j 10
  159. call assert_equal('100', getline('.'))
  160. call assert_beeps('normal GVJ')
  161. " clean up
  162. bw!
  163. endfunc
  164. " basic filter test
  165. func Test_normal04_filter()
  166. " only test on non windows platform
  167. CheckNotMSWindows
  168. call Setup_NewWindow()
  169. 1
  170. call feedkeys("!!sed -e 's/^/| /'\n", 'tx')
  171. call assert_equal('| 1', getline('.'))
  172. 90
  173. :sil :!echo one
  174. call feedkeys('.', 'tx')
  175. call assert_equal('| 90', getline('.'))
  176. 95
  177. set cpo+=!
  178. " 2 <CR>, 1: for executing the command,
  179. " 2: clear hit-enter-prompt
  180. call feedkeys("!!\n", 'tx')
  181. call feedkeys(":!echo one\n\n", 'tx')
  182. call feedkeys(".", 'tx')
  183. call assert_equal('one', getline('.'))
  184. set cpo-=!
  185. bw!
  186. endfunc
  187. func Test_normal05_formatexpr()
  188. " basic formatexpr test
  189. call Setup_NewWindow()
  190. %d_
  191. call setline(1, ['here: 1 ', '2', 'here: 3 ', '4', 'not here: '])
  192. 1
  193. set formatexpr=MyFormatExpr()
  194. norm! gqG
  195. call assert_equal(['here: 1->$', '2', 'here: 3->$', '4', 'not here: '], getline(1,'$'))
  196. set formatexpr=
  197. bw!
  198. endfunc
  199. func Test_normal05_formatexpr_newbuf()
  200. " Edit another buffer in the 'formatexpr' function
  201. new
  202. func! Format()
  203. edit another
  204. endfunc
  205. set formatexpr=Format()
  206. norm gqG
  207. bw!
  208. set formatexpr=
  209. endfunc
  210. func Test_normal05_formatexpr_setopt()
  211. " Change the 'formatexpr' value in the function
  212. new
  213. func! Format()
  214. set formatexpr=
  215. endfunc
  216. set formatexpr=Format()
  217. norm gqG
  218. bw!
  219. set formatexpr=
  220. endfunc
  221. " When 'formatexpr' returns non-zero, internal formatting is used.
  222. func Test_normal_formatexpr_returns_nonzero()
  223. new
  224. call setline(1, ['one', 'two'])
  225. func! Format()
  226. return 1
  227. endfunc
  228. setlocal formatexpr=Format()
  229. normal VGgq
  230. call assert_equal(['one two'], getline(1, '$'))
  231. setlocal formatexpr=
  232. delfunc Format
  233. bwipe!
  234. endfunc
  235. " Test for using a script-local function for 'formatexpr'
  236. func Test_formatexpr_scriptlocal_func()
  237. func! s:Format()
  238. let g:FormatArgs = [v:lnum, v:count]
  239. endfunc
  240. set formatexpr=s:Format()
  241. call assert_equal(expand('<SID>') .. 'Format()', &formatexpr)
  242. call assert_equal(expand('<SID>') .. 'Format()', &g:formatexpr)
  243. new | only
  244. call setline(1, range(1, 40))
  245. let g:FormatArgs = []
  246. normal! 2GVjgq
  247. call assert_equal([2, 2], g:FormatArgs)
  248. bw!
  249. set formatexpr=<SID>Format()
  250. call assert_equal(expand('<SID>') .. 'Format()', &formatexpr)
  251. call assert_equal(expand('<SID>') .. 'Format()', &g:formatexpr)
  252. new | only
  253. call setline(1, range(1, 40))
  254. let g:FormatArgs = []
  255. normal! 4GVjgq
  256. call assert_equal([4, 2], g:FormatArgs)
  257. bw!
  258. let &formatexpr = 's:Format()'
  259. call assert_equal(expand('<SID>') .. 'Format()', &g:formatexpr)
  260. new | only
  261. call setline(1, range(1, 40))
  262. let g:FormatArgs = []
  263. normal! 6GVjgq
  264. call assert_equal([6, 2], g:FormatArgs)
  265. bw!
  266. let &formatexpr = '<SID>Format()'
  267. call assert_equal(expand('<SID>') .. 'Format()', &g:formatexpr)
  268. new | only
  269. call setline(1, range(1, 40))
  270. let g:FormatArgs = []
  271. normal! 8GVjgq
  272. call assert_equal([8, 2], g:FormatArgs)
  273. bw!
  274. setlocal formatexpr=
  275. setglobal formatexpr=s:Format()
  276. call assert_equal(expand('<SID>') .. 'Format()', &g:formatexpr)
  277. call assert_equal('', &formatexpr)
  278. new
  279. call assert_equal(expand('<SID>') .. 'Format()', &formatexpr)
  280. call setline(1, range(1, 40))
  281. let g:FormatArgs = []
  282. normal! 10GVjgq
  283. call assert_equal([10, 2], g:FormatArgs)
  284. bw!
  285. setglobal formatexpr=<SID>Format()
  286. call assert_equal(expand('<SID>') .. 'Format()', &g:formatexpr)
  287. call assert_equal('', &formatexpr)
  288. new
  289. call assert_equal(expand('<SID>') .. 'Format()', &formatexpr)
  290. call setline(1, range(1, 40))
  291. let g:FormatArgs = []
  292. normal! 12GVjgq
  293. call assert_equal([12, 2], g:FormatArgs)
  294. bw!
  295. let &g:formatexpr = 's:Format()'
  296. call assert_equal(expand('<SID>') .. 'Format()', &g:formatexpr)
  297. call assert_equal('', &formatexpr)
  298. new
  299. call assert_equal(expand('<SID>') .. 'Format()', &formatexpr)
  300. call setline(1, range(1, 40))
  301. let g:FormatArgs = []
  302. normal! 14GVjgq
  303. call assert_equal([14, 2], g:FormatArgs)
  304. bw!
  305. let &g:formatexpr = '<SID>Format()'
  306. call assert_equal(expand('<SID>') .. 'Format()', &g:formatexpr)
  307. call assert_equal('', &formatexpr)
  308. new
  309. call assert_equal(expand('<SID>') .. 'Format()', &formatexpr)
  310. call setline(1, range(1, 40))
  311. let g:FormatArgs = []
  312. normal! 16GVjgq
  313. call assert_equal([16, 2], g:FormatArgs)
  314. bw!
  315. set formatexpr=
  316. delfunc s:Format
  317. bw!
  318. endfunc
  319. " basic test for formatprg
  320. func Test_normal06_formatprg()
  321. " only test on non windows platform
  322. CheckNotMSWindows
  323. " uses sed to number non-empty lines
  324. call writefile(['#!/bin/sh', 'sed ''/./=''|sed ''/./{', 'N', 's/\n/ /', '}'''], 'Xsed_format.sh', 'D')
  325. call system('chmod +x ./Xsed_format.sh')
  326. let text = ['a', '', 'c', '', ' ', 'd', 'e']
  327. let expected = ['1 a', '', '3 c', '', '5 ', '6 d', '7 e']
  328. 10new
  329. call setline(1, text)
  330. set formatprg=./Xsed_format.sh
  331. norm! gggqG
  332. call assert_equal(expected, getline(1, '$'))
  333. %d
  334. call setline(1, text)
  335. set formatprg=donothing
  336. setlocal formatprg=./Xsed_format.sh
  337. norm! gggqG
  338. call assert_equal(expected, getline(1, '$'))
  339. %d
  340. " Check for the command-line ranges added to 'formatprg'
  341. set formatprg=cat
  342. call setline(1, ['one', 'two', 'three', 'four', 'five'])
  343. call feedkeys('gggqG', 'xt')
  344. call assert_equal('.,$!cat', @:)
  345. call feedkeys('2Ggq2j', 'xt')
  346. call assert_equal('.,.+2!cat', @:)
  347. bw!
  348. " clean up
  349. set formatprg=
  350. setlocal formatprg=
  351. endfunc
  352. func Test_normal07_internalfmt()
  353. " basic test for internal formatter to textwidth of 12
  354. let list=range(1,11)
  355. call map(list, 'v:val." "')
  356. 10new
  357. call setline(1, list)
  358. set tw=12
  359. norm! ggVGgq
  360. call assert_equal(['1 2 3', '4 5 6', '7 8 9', '10 11 '], getline(1, '$'))
  361. " clean up
  362. set tw=0
  363. bw!
  364. endfunc
  365. " basic tests for foldopen/folddelete
  366. func Test_normal08_fold()
  367. CheckFeature folding
  368. call Setup_NewWindow()
  369. 50
  370. setl foldenable fdm=marker
  371. " First fold
  372. norm! V4jzf
  373. " check that folds have been created
  374. call assert_equal(['50/* {{{ */', '51', '52', '53', '54/* }}} */'], getline(50,54))
  375. " Second fold
  376. 46
  377. norm! V10jzf
  378. " check that folds have been created
  379. call assert_equal('46/* {{{ */', getline(46))
  380. call assert_equal('60/* }}} */', getline(60))
  381. norm! k
  382. call assert_equal('45', getline('.'))
  383. norm! j
  384. call assert_equal('46/* {{{ */', getline('.'))
  385. norm! j
  386. call assert_equal('61', getline('.'))
  387. norm! k
  388. " open a fold
  389. norm! Vzo
  390. norm! k
  391. call assert_equal('45', getline('.'))
  392. norm! j
  393. call assert_equal('46/* {{{ */', getline('.'))
  394. norm! j
  395. call assert_equal('47', getline('.'))
  396. norm! k
  397. norm! zcVzO
  398. call assert_equal('46/* {{{ */', getline('.'))
  399. norm! j
  400. call assert_equal('47', getline('.'))
  401. norm! j
  402. call assert_equal('48', getline('.'))
  403. norm! j
  404. call assert_equal('49', getline('.'))
  405. norm! j
  406. call assert_equal('50/* {{{ */', getline('.'))
  407. norm! j
  408. call assert_equal('51', getline('.'))
  409. " delete folds
  410. :46
  411. " collapse fold
  412. norm! V14jzC
  413. " delete all folds recursively
  414. norm! VzD
  415. call assert_equal(['46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60'], getline(46,60))
  416. " clean up
  417. setl nofoldenable fdm=marker
  418. bw!
  419. endfunc
  420. func Test_normal09a_operatorfunc()
  421. " Test operatorfunc
  422. call Setup_NewWindow()
  423. " Add some spaces for counting
  424. 50,60s/$/ /
  425. unlet! g:a
  426. let g:a=0
  427. nmap <buffer><silent> ,, :set opfunc=CountSpaces<CR>g@
  428. vmap <buffer><silent> ,, :<C-U>call CountSpaces(visualmode(), 1)<CR>
  429. 50
  430. norm V2j,,
  431. call assert_equal(6, g:a)
  432. norm V,,
  433. call assert_equal(2, g:a)
  434. norm ,,l
  435. call assert_equal(0, g:a)
  436. 50
  437. exe "norm 0\<c-v>10j2l,,"
  438. call assert_equal(11, g:a)
  439. 50
  440. norm V10j,,
  441. call assert_equal(22, g:a)
  442. " clean up
  443. unmap <buffer> ,,
  444. set opfunc=
  445. unlet! g:a
  446. bw!
  447. endfunc
  448. func Test_normal09b_operatorfunc()
  449. " Test operatorfunc
  450. call Setup_NewWindow()
  451. " Add some spaces for counting
  452. 50,60s/$/ /
  453. unlet! g:opt
  454. set linebreak
  455. nmap <buffer><silent> ,, :set opfunc=OpfuncDummy<CR>g@
  456. 50
  457. norm ,,j
  458. exe "bd!" g:bufnr
  459. call assert_true(&linebreak)
  460. call assert_equal(g:opt, &linebreak)
  461. set nolinebreak
  462. norm ,,j
  463. exe "bd!" g:bufnr
  464. call assert_false(&linebreak)
  465. call assert_equal(g:opt, &linebreak)
  466. " clean up
  467. unmap <buffer> ,,
  468. set opfunc=
  469. call assert_fails('normal Vg@', 'E774:')
  470. bw!
  471. unlet! g:opt
  472. endfunc
  473. func OperatorfuncRedo(_)
  474. let g:opfunc_count = v:count
  475. endfunc
  476. func Underscorize(_)
  477. normal! '[V']r_
  478. endfunc
  479. func Test_normal09c_operatorfunc()
  480. " Test redoing operatorfunc
  481. new
  482. call setline(1, 'some text')
  483. set operatorfunc=OperatorfuncRedo
  484. normal v3g@
  485. call assert_equal(3, g:opfunc_count)
  486. let g:opfunc_count = 0
  487. normal .
  488. call assert_equal(3, g:opfunc_count)
  489. bw!
  490. unlet g:opfunc_count
  491. " Test redoing Visual mode
  492. set operatorfunc=Underscorize
  493. new
  494. call setline(1, ['first', 'first', 'third', 'third', 'second'])
  495. normal! 1GVjg@
  496. normal! 5G.
  497. normal! 3G.
  498. call assert_equal(['_____', '_____', '_____', '_____', '______'], getline(1, '$'))
  499. bwipe!
  500. set operatorfunc=
  501. endfunc
  502. " Test for different ways of setting the 'operatorfunc' option
  503. func Test_opfunc_callback()
  504. new
  505. func OpFunc1(callnr, type)
  506. let g:OpFunc1Args = [a:callnr, a:type]
  507. endfunc
  508. func OpFunc2(type)
  509. let g:OpFunc2Args = [a:type]
  510. endfunc
  511. let lines =<< trim END
  512. #" Test for using a function name
  513. LET &opfunc = 'g:OpFunc2'
  514. LET g:OpFunc2Args = []
  515. normal! g@l
  516. call assert_equal(['char'], g:OpFunc2Args)
  517. #" Test for using a function()
  518. set opfunc=function('g:OpFunc1',\ [10])
  519. LET g:OpFunc1Args = []
  520. normal! g@l
  521. call assert_equal([10, 'char'], g:OpFunc1Args)
  522. #" Using a funcref variable to set 'operatorfunc'
  523. VAR Fn = function('g:OpFunc1', [11])
  524. LET &opfunc = Fn
  525. LET g:OpFunc1Args = []
  526. normal! g@l
  527. call assert_equal([11, 'char'], g:OpFunc1Args)
  528. #" Using a string(funcref_variable) to set 'operatorfunc'
  529. LET Fn = function('g:OpFunc1', [12])
  530. LET &operatorfunc = string(Fn)
  531. LET g:OpFunc1Args = []
  532. normal! g@l
  533. call assert_equal([12, 'char'], g:OpFunc1Args)
  534. #" Test for using a funcref()
  535. set operatorfunc=funcref('g:OpFunc1',\ [13])
  536. LET g:OpFunc1Args = []
  537. normal! g@l
  538. call assert_equal([13, 'char'], g:OpFunc1Args)
  539. #" Using a funcref variable to set 'operatorfunc'
  540. LET Fn = funcref('g:OpFunc1', [14])
  541. LET &opfunc = Fn
  542. LET g:OpFunc1Args = []
  543. normal! g@l
  544. call assert_equal([14, 'char'], g:OpFunc1Args)
  545. #" Using a string(funcref_variable) to set 'operatorfunc'
  546. LET Fn = funcref('g:OpFunc1', [15])
  547. LET &opfunc = string(Fn)
  548. LET g:OpFunc1Args = []
  549. normal! g@l
  550. call assert_equal([15, 'char'], g:OpFunc1Args)
  551. #" Test for using a lambda function using set
  552. VAR optval = "LSTART a LMIDDLE OpFunc1(16, a) LEND"
  553. LET optval = substitute(optval, ' ', '\\ ', 'g')
  554. exe "set opfunc=" .. optval
  555. LET g:OpFunc1Args = []
  556. normal! g@l
  557. call assert_equal([16, 'char'], g:OpFunc1Args)
  558. #" Test for using a lambda function using LET
  559. LET &opfunc = LSTART a LMIDDLE OpFunc1(17, a) LEND
  560. LET g:OpFunc1Args = []
  561. normal! g@l
  562. call assert_equal([17, 'char'], g:OpFunc1Args)
  563. #" Set 'operatorfunc' to a string(lambda expression)
  564. LET &opfunc = 'LSTART a LMIDDLE OpFunc1(18, a) LEND'
  565. LET g:OpFunc1Args = []
  566. normal! g@l
  567. call assert_equal([18, 'char'], g:OpFunc1Args)
  568. #" Set 'operatorfunc' to a variable with a lambda expression
  569. VAR Lambda = LSTART a LMIDDLE OpFunc1(19, a) LEND
  570. LET &opfunc = Lambda
  571. LET g:OpFunc1Args = []
  572. normal! g@l
  573. call assert_equal([19, 'char'], g:OpFunc1Args)
  574. #" Set 'operatorfunc' to a string(variable with a lambda expression)
  575. LET Lambda = LSTART a LMIDDLE OpFunc1(20, a) LEND
  576. LET &opfunc = string(Lambda)
  577. LET g:OpFunc1Args = []
  578. normal! g@l
  579. call assert_equal([20, 'char'], g:OpFunc1Args)
  580. #" Try to use 'operatorfunc' after the function is deleted
  581. func g:TmpOpFunc1(type)
  582. let g:TmpOpFunc1Args = [21, a:type]
  583. endfunc
  584. LET &opfunc = function('g:TmpOpFunc1')
  585. delfunc g:TmpOpFunc1
  586. call test_garbagecollect_now()
  587. LET g:TmpOpFunc1Args = []
  588. call assert_fails('normal! g@l', 'E117:')
  589. call assert_equal([], g:TmpOpFunc1Args)
  590. #" Try to use a function with two arguments for 'operatorfunc'
  591. func g:TmpOpFunc2(x, y)
  592. let g:TmpOpFunc2Args = [a:x, a:y]
  593. endfunc
  594. set opfunc=TmpOpFunc2
  595. LET g:TmpOpFunc2Args = []
  596. call assert_fails('normal! g@l', 'E119:')
  597. call assert_equal([], g:TmpOpFunc2Args)
  598. delfunc TmpOpFunc2
  599. #" Try to use a lambda function with two arguments for 'operatorfunc'
  600. LET &opfunc = LSTART a, b LMIDDLE OpFunc1(22, b) LEND
  601. LET g:OpFunc1Args = []
  602. call assert_fails('normal! g@l', 'E119:')
  603. call assert_equal([], g:OpFunc1Args)
  604. #" Test for clearing the 'operatorfunc' option
  605. set opfunc=''
  606. set opfunc&
  607. call assert_fails("set opfunc=function('abc')", "E700:")
  608. call assert_fails("set opfunc=funcref('abc')", "E700:")
  609. #" set 'operatorfunc' to a non-existing function
  610. LET &opfunc = function('g:OpFunc1', [23])
  611. call assert_fails("set opfunc=function('NonExistingFunc')", 'E700:')
  612. call assert_fails("LET &opfunc = function('NonExistingFunc')", 'E700:')
  613. LET g:OpFunc1Args = []
  614. normal! g@l
  615. call assert_equal([23, 'char'], g:OpFunc1Args)
  616. END
  617. call CheckTransLegacySuccess(lines)
  618. " Test for using a script-local function name
  619. func s:OpFunc3(type)
  620. let g:OpFunc3Args = [a:type]
  621. endfunc
  622. set opfunc=s:OpFunc3
  623. let g:OpFunc3Args = []
  624. normal! g@l
  625. call assert_equal(['char'], g:OpFunc3Args)
  626. let &opfunc = 's:OpFunc3'
  627. let g:OpFunc3Args = []
  628. normal! g@l
  629. call assert_equal(['char'], g:OpFunc3Args)
  630. delfunc s:OpFunc3
  631. " Using Vim9 lambda expression in legacy context should fail
  632. set opfunc=(a)\ =>\ OpFunc1(24,\ a)
  633. let g:OpFunc1Args = []
  634. call assert_fails('normal! g@l', 'E117:')
  635. call assert_equal([], g:OpFunc1Args)
  636. " set 'operatorfunc' to a partial with dict. This used to cause a crash.
  637. func SetOpFunc()
  638. let operator = {'execute': function('OperatorExecute')}
  639. let &opfunc = operator.execute
  640. endfunc
  641. func OperatorExecute(_) dict
  642. endfunc
  643. call SetOpFunc()
  644. call test_garbagecollect_now()
  645. set operatorfunc=
  646. delfunc SetOpFunc
  647. delfunc OperatorExecute
  648. " Vim9 tests
  649. let lines =<< trim END
  650. vim9script
  651. def g:Vim9opFunc(val: number, type: string): void
  652. g:OpFunc1Args = [val, type]
  653. enddef
  654. # Test for using a def function with opfunc
  655. set opfunc=function('g:Vim9opFunc',\ [60])
  656. g:OpFunc1Args = []
  657. normal! g@l
  658. assert_equal([60, 'char'], g:OpFunc1Args)
  659. # Test for using a global function name
  660. &opfunc = g:OpFunc2
  661. g:OpFunc2Args = []
  662. normal! g@l
  663. assert_equal(['char'], g:OpFunc2Args)
  664. bw!
  665. # Test for using a script-local function name
  666. def LocalOpFunc(type: string): void
  667. g:LocalOpFuncArgs = [type]
  668. enddef
  669. &opfunc = LocalOpFunc
  670. g:LocalOpFuncArgs = []
  671. normal! g@l
  672. assert_equal(['char'], g:LocalOpFuncArgs)
  673. bw!
  674. END
  675. call CheckScriptSuccess(lines)
  676. " setting 'opfunc' to a script local function outside of a script context
  677. " should fail
  678. let cleanup =<< trim END
  679. call writefile([execute('messages')], 'Xtest.out')
  680. qall
  681. END
  682. call writefile(cleanup, 'Xverify.vim')
  683. call RunVim([], [], "-c \"set opfunc=s:abc\" -S Xverify.vim")
  684. call assert_match('E81: Using <SID> not in a', readfile('Xtest.out')[0])
  685. call delete('Xtest.out')
  686. call delete('Xverify.vim')
  687. " cleanup
  688. set opfunc&
  689. delfunc OpFunc1
  690. delfunc OpFunc2
  691. unlet g:OpFunc1Args g:OpFunc2Args
  692. %bw!
  693. endfunc
  694. func Test_normal10_expand()
  695. " Test for expand()
  696. 10new
  697. call setline(1, ['1', 'ifooar,,cbar'])
  698. 2
  699. norm! $
  700. call assert_equal('cbar', expand('<cword>'))
  701. call assert_equal('ifooar,,cbar', expand('<cWORD>'))
  702. call setline(1, ['prx = list[idx];'])
  703. 1
  704. let expected = ['', 'prx', 'prx', 'prx',
  705. \ 'list', 'list', 'list', 'list', 'list', 'list', 'list',
  706. \ 'idx', 'idx', 'idx', 'idx',
  707. \ 'list[idx]',
  708. \ '];',
  709. \ ]
  710. for i in range(1, 16)
  711. exe 'norm ' . i . '|'
  712. call assert_equal(expected[i], expand('<cexpr>'), 'i == ' . i)
  713. endfor
  714. " Test for <cexpr> in state.val and ptr->val
  715. call setline(1, 'x = state.val;')
  716. call cursor(1, 10)
  717. call assert_equal('state.val', expand('<cexpr>'))
  718. call setline(1, 'x = ptr->val;')
  719. call cursor(1, 9)
  720. call assert_equal('ptr->val', expand('<cexpr>'))
  721. if executable('echo')
  722. " Test expand(`...`) i.e. backticks command expansion.
  723. " MS-Windows has a trailing space.
  724. call assert_match('^abcde *$', expand('`echo abcde`'))
  725. endif
  726. " Test expand(`=...`) i.e. backticks expression expansion
  727. call assert_equal('5', expand('`=2+3`'))
  728. call assert_equal('3.14', expand('`=3.14`'))
  729. " clean up
  730. bw!
  731. endfunc
  732. " Test for expand() in latin1 encoding
  733. func Test_normal_expand_latin1()
  734. new
  735. let save_enc = &encoding
  736. " set encoding=latin1
  737. call setline(1, 'val = item->color;')
  738. call cursor(1, 11)
  739. call assert_equal('color', expand("<cword>"))
  740. call assert_equal('item->color', expand("<cexpr>"))
  741. let &encoding = save_enc
  742. bw!
  743. endfunc
  744. func Test_normal11_showcmd()
  745. " test for 'showcmd'
  746. 10new
  747. exe "norm! ofoobar\<esc>"
  748. call assert_equal(2, line('$'))
  749. set showcmd
  750. exe "norm! ofoobar2\<esc>"
  751. call assert_equal(3, line('$'))
  752. exe "norm! VAfoobar3\<esc>"
  753. call assert_equal(3, line('$'))
  754. exe "norm! 0d3\<del>2l"
  755. call assert_equal('obar2foobar3', getline('.'))
  756. " test for the visual block size displayed in the status line
  757. call setline(1, ['aaaaa', 'bbbbb', 'ccccc'])
  758. call feedkeys("ggl\<C-V>lljj", 'xt')
  759. redraw!
  760. call assert_match('3x3$', Screenline(&lines))
  761. call feedkeys("\<C-V>", 'xt')
  762. " test for visually selecting a multi-byte character
  763. call setline(1, ["\U2206"])
  764. call feedkeys("ggv", 'xt')
  765. redraw!
  766. call assert_match('1-3$', Screenline(&lines))
  767. call feedkeys("v", 'xt')
  768. " test for visually selecting the end of line
  769. call setline(1, ["foobar"])
  770. call feedkeys("$vl", 'xt')
  771. redraw!
  772. call assert_match('2$', Screenline(&lines))
  773. call feedkeys("y", 'xt')
  774. call assert_equal("r\n", @")
  775. bw!
  776. endfunc
  777. " Test for nv_error and normal command errors
  778. func Test_normal12_nv_error()
  779. 10new
  780. call setline(1, range(1,5))
  781. " should not do anything, just beep
  782. call assert_beeps('exe "norm! <c-k>"')
  783. call assert_equal(map(range(1,5), 'string(v:val)'), getline(1,'$'))
  784. call assert_beeps('normal! G2dd')
  785. call assert_beeps("normal! g\<C-A>")
  786. call assert_beeps("normal! g\<C-X>")
  787. call assert_beeps("normal! g\<C-B>")
  788. " call assert_beeps("normal! vQ\<Esc>")
  789. call assert_beeps("normal! 2[[")
  790. call assert_beeps("normal! 2]]")
  791. call assert_beeps("normal! 2[]")
  792. call assert_beeps("normal! 2][")
  793. call assert_beeps("normal! 4[z")
  794. call assert_beeps("normal! 4]z")
  795. call assert_beeps("normal! 4[c")
  796. call assert_beeps("normal! 4]c")
  797. call assert_beeps("normal! 200%")
  798. call assert_beeps("normal! %")
  799. call assert_beeps("normal! 2{")
  800. call assert_beeps("normal! 2}")
  801. call assert_beeps("normal! r\<Right>")
  802. call assert_beeps("normal! 8ry")
  803. call assert_beeps('normal! "@')
  804. bw!
  805. endfunc
  806. func Test_normal13_help()
  807. " Test for F1
  808. call assert_equal(1, winnr())
  809. call feedkeys("\<f1>", 'txi')
  810. call assert_match('help\.txt', bufname('%'))
  811. call assert_equal(2, winnr('$'))
  812. bw!
  813. endfunc
  814. func Test_normal14_page()
  815. " basic test for Ctrl-F and Ctrl-B
  816. call Setup_NewWindow()
  817. exe "norm! \<c-f>"
  818. call assert_equal('9', getline('.'))
  819. exe "norm! 2\<c-f>"
  820. call assert_equal('25', getline('.'))
  821. exe "norm! 2\<c-b>"
  822. call assert_equal('18', getline('.'))
  823. 1
  824. set scrolloff=5
  825. exe "norm! 2\<c-f>"
  826. call assert_equal('21', getline('.'))
  827. exe "norm! \<c-b>"
  828. call assert_equal('13', getline('.'))
  829. 1
  830. set scrolloff=99
  831. exe "norm! \<c-f>"
  832. call assert_equal('13', getline('.'))
  833. set scrolloff=0
  834. 100
  835. exe "norm! $\<c-b>"
  836. call assert_equal([0, 92, 1, 0, 1], getcurpos())
  837. 100
  838. set nostartofline
  839. exe "norm! $\<c-b>"
  840. call assert_equal([0, 92, 2, 0, v:maxcol], getcurpos())
  841. " cleanup
  842. set startofline
  843. bw!
  844. endfunc
  845. func Test_normal14_page_eol()
  846. 10new
  847. norm oxxxxxxx
  848. exe "norm 2\<c-f>"
  849. " check with valgrind that cursor is put back in column 1
  850. exe "norm 2\<c-b>"
  851. bw!
  852. endfunc
  853. " Test for errors with z command
  854. func Test_normal_z_error()
  855. call assert_beeps('normal! z2p')
  856. call assert_beeps('normal! zq')
  857. call assert_beeps('normal! cz1')
  858. endfunc
  859. func Test_normal15_z_scroll_vert()
  860. " basic test for z commands that scroll the window
  861. call Setup_NewWindow()
  862. 100
  863. norm! >>
  864. " Test for z<cr>
  865. exe "norm! z\<cr>"
  866. call assert_equal(' 100', getline('.'))
  867. call assert_equal(100, winsaveview()['topline'])
  868. call assert_equal([0, 100, 2, 0, 9], getcurpos())
  869. " Test for zt
  870. 21
  871. norm! >>0zt
  872. call assert_equal(' 21', getline('.'))
  873. call assert_equal(21, winsaveview()['topline'])
  874. call assert_equal([0, 21, 1, 0, 8], getcurpos())
  875. " Test for zb
  876. 30
  877. norm! >>$ztzb
  878. call assert_equal(' 30', getline('.'))
  879. call assert_equal(30, winsaveview()['topline']+winheight(0)-1)
  880. call assert_equal([0, 30, 3, 0, v:maxcol], getcurpos())
  881. " Test for z-
  882. 1
  883. 30
  884. norm! 0z-
  885. call assert_equal(' 30', getline('.'))
  886. call assert_equal(30, winsaveview()['topline']+winheight(0)-1)
  887. call assert_equal([0, 30, 2, 0, 9], getcurpos())
  888. " Test for z{height}<cr>
  889. call assert_equal(10, winheight(0))
  890. exe "norm! z12\<cr>"
  891. call assert_equal(12, winheight(0))
  892. exe "norm! z15\<Del>0\<cr>"
  893. call assert_equal(10, winheight(0))
  894. " Test for z.
  895. 1
  896. 21
  897. norm! 0z.
  898. call assert_equal(' 21', getline('.'))
  899. call assert_equal(17, winsaveview()['topline'])
  900. call assert_equal([0, 21, 2, 0, 9], getcurpos())
  901. " Test for zz
  902. 1
  903. 21
  904. norm! 0zz
  905. call assert_equal(' 21', getline('.'))
  906. call assert_equal(17, winsaveview()['topline'])
  907. call assert_equal([0, 21, 1, 0, 8], getcurpos())
  908. " Test for z+
  909. 11
  910. norm! zt
  911. norm! z+
  912. call assert_equal(' 21', getline('.'))
  913. call assert_equal(21, winsaveview()['topline'])
  914. call assert_equal([0, 21, 2, 0, 9], getcurpos())
  915. " Test for [count]z+
  916. 1
  917. norm! 21z+
  918. call assert_equal(' 21', getline('.'))
  919. call assert_equal(21, winsaveview()['topline'])
  920. call assert_equal([0, 21, 2, 0, 9], getcurpos())
  921. " Test for z+ with [count] greater than buffer size
  922. 1
  923. norm! 1000z+
  924. call assert_equal(' 100', getline('.'))
  925. call assert_equal(100, winsaveview()['topline'])
  926. call assert_equal([0, 100, 2, 0, 9], getcurpos())
  927. " Test for z+ from the last buffer line
  928. norm! Gz.z+
  929. call assert_equal(' 100', getline('.'))
  930. call assert_equal(100, winsaveview()['topline'])
  931. call assert_equal([0, 100, 2, 0, 9], getcurpos())
  932. " Test for z^
  933. norm! 22z+0
  934. norm! z^
  935. call assert_equal(' 21', getline('.'))
  936. call assert_equal(12, winsaveview()['topline'])
  937. call assert_equal([0, 21, 2, 0, 9], getcurpos())
  938. " Test for z^ from first buffer line
  939. norm! ggz^
  940. call assert_equal('1', getline('.'))
  941. call assert_equal(1, winsaveview()['topline'])
  942. call assert_equal([0, 1, 1, 0, 1], getcurpos())
  943. " Test for [count]z^
  944. 1
  945. norm! 30z^
  946. call assert_equal(' 21', getline('.'))
  947. call assert_equal(12, winsaveview()['topline'])
  948. call assert_equal([0, 21, 2, 0, 9], getcurpos())
  949. " cleanup
  950. bw!
  951. endfunc
  952. func Test_normal16_z_scroll_hor()
  953. " basic test for z commands that scroll the window
  954. 10new
  955. 15vsp
  956. set nowrap listchars=
  957. let lineA='abcdefghijklmnopqrstuvwxyz'
  958. let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  959. $put =lineA
  960. $put =lineB
  961. 1d
  962. " Test for zl and zh with a count
  963. norm! 0z10l
  964. call assert_equal([11, 1], [col('.'), wincol()])
  965. norm! z4h
  966. call assert_equal([11, 5], [col('.'), wincol()])
  967. normal! 2gg
  968. " Test for zl
  969. 1
  970. norm! 5zl
  971. call assert_equal(lineA, getline('.'))
  972. call assert_equal(6, col('.'))
  973. call assert_equal(5, winsaveview()['leftcol'])
  974. norm! yl
  975. call assert_equal('f', @0)
  976. " Test for zh
  977. norm! 2zh
  978. call assert_equal(lineA, getline('.'))
  979. call assert_equal(6, col('.'))
  980. norm! yl
  981. call assert_equal('f', @0)
  982. call assert_equal(3, winsaveview()['leftcol'])
  983. " Test for zL
  984. norm! zL
  985. call assert_equal(11, col('.'))
  986. norm! yl
  987. call assert_equal('k', @0)
  988. call assert_equal(10, winsaveview()['leftcol'])
  989. norm! 2zL
  990. call assert_equal(25, col('.'))
  991. norm! yl
  992. call assert_equal('y', @0)
  993. call assert_equal(24, winsaveview()['leftcol'])
  994. " Test for zH
  995. norm! 2zH
  996. call assert_equal(25, col('.'))
  997. call assert_equal(10, winsaveview()['leftcol'])
  998. norm! yl
  999. call assert_equal('y', @0)
  1000. " Test for zs
  1001. norm! $zs
  1002. call assert_equal(26, col('.'))
  1003. call assert_equal(25, winsaveview()['leftcol'])
  1004. norm! yl
  1005. call assert_equal('z', @0)
  1006. " Test for ze
  1007. norm! ze
  1008. call assert_equal(26, col('.'))
  1009. call assert_equal(11, winsaveview()['leftcol'])
  1010. norm! yl
  1011. call assert_equal('z', @0)
  1012. " Test for zs and ze with folds
  1013. %fold
  1014. norm! $zs
  1015. call assert_equal(26, col('.'))
  1016. call assert_equal(0, winsaveview()['leftcol'])
  1017. norm! yl
  1018. call assert_equal('z', @0)
  1019. norm! ze
  1020. call assert_equal(26, col('.'))
  1021. call assert_equal(0, winsaveview()['leftcol'])
  1022. norm! yl
  1023. call assert_equal('z', @0)
  1024. " cleanup
  1025. set wrap listchars=eol:$
  1026. bw!
  1027. endfunc
  1028. func Test_normal17_z_scroll_hor2()
  1029. " basic test for z commands that scroll the window
  1030. " using 'sidescrolloff' setting
  1031. 10new
  1032. 20vsp
  1033. set nowrap listchars= sidescrolloff=5
  1034. let lineA='abcdefghijklmnopqrstuvwxyz'
  1035. let lineB='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  1036. $put =lineA
  1037. $put =lineB
  1038. 1d
  1039. " Test for zl
  1040. 1
  1041. norm! 5zl
  1042. call assert_equal(lineA, getline('.'))
  1043. call assert_equal(11, col('.'))
  1044. call assert_equal(5, winsaveview()['leftcol'])
  1045. norm! yl
  1046. call assert_equal('k', @0)
  1047. " Test for zh
  1048. norm! 2zh
  1049. call assert_equal(lineA, getline('.'))
  1050. call assert_equal(11, col('.'))
  1051. norm! yl
  1052. call assert_equal('k', @0)
  1053. call assert_equal(3, winsaveview()['leftcol'])
  1054. " Test for zL
  1055. norm! 0zL
  1056. call assert_equal(16, col('.'))
  1057. norm! yl
  1058. call assert_equal('p', @0)
  1059. call assert_equal(10, winsaveview()['leftcol'])
  1060. norm! 2zL
  1061. call assert_equal(26, col('.'))
  1062. norm! yl
  1063. call assert_equal('z', @0)
  1064. call assert_equal(15, winsaveview()['leftcol'])
  1065. " Test for zH
  1066. norm! 2zH
  1067. call assert_equal(15, col('.'))
  1068. call assert_equal(0, winsaveview()['leftcol'])
  1069. norm! yl
  1070. call assert_equal('o', @0)
  1071. " Test for zs
  1072. norm! $zs
  1073. call assert_equal(26, col('.'))
  1074. call assert_equal(20, winsaveview()['leftcol'])
  1075. norm! yl
  1076. call assert_equal('z', @0)
  1077. " Test for ze
  1078. norm! ze
  1079. call assert_equal(26, col('.'))
  1080. call assert_equal(11, winsaveview()['leftcol'])
  1081. norm! yl
  1082. call assert_equal('z', @0)
  1083. " cleanup
  1084. set wrap listchars=eol:$ sidescrolloff=0
  1085. bw!
  1086. endfunc
  1087. " Test for commands that scroll the window horizontally. Test with folds.
  1088. " H, M, L, CTRL-E, CTRL-Y, CTRL-U, CTRL-D, PageUp, PageDown commands
  1089. func Test_vert_scroll_cmds()
  1090. 15new
  1091. call setline(1, range(1, 100))
  1092. exe "normal! 30ggz\<CR>"
  1093. set foldenable
  1094. 33,36fold
  1095. 40,43fold
  1096. 46,49fold
  1097. let h = winheight(0)
  1098. " Test for H, M and L commands
  1099. " Top of the screen = 30
  1100. " Folded lines = 9
  1101. " Bottom of the screen = 30 + h + 9 - 1
  1102. normal! 4L
  1103. call assert_equal(35 + h, line('.'))
  1104. normal! 4H
  1105. call assert_equal(33, line('.'))
  1106. " Test for using a large count value
  1107. %d
  1108. call setline(1, range(1, 4))
  1109. norm! 6H
  1110. call assert_equal(4, line('.'))
  1111. " Test for 'M' with folded lines
  1112. %d
  1113. call setline(1, range(1, 20))
  1114. 1,5fold
  1115. norm! LM
  1116. call assert_equal(12, line('.'))
  1117. " Test for the CTRL-E and CTRL-Y commands with folds
  1118. %d
  1119. call setline(1, range(1, 10))
  1120. 3,5fold
  1121. exe "normal 6G3\<C-E>"
  1122. call assert_equal(6, line('w0'))
  1123. exe "normal 2\<C-Y>"
  1124. call assert_equal(2, line('w0'))
  1125. " Test for CTRL-Y on a folded line
  1126. %d
  1127. call setline(1, range(1, 100))
  1128. exe (h + 2) .. "," .. (h + 4) .. "fold"
  1129. exe h + 5
  1130. normal z-
  1131. exe "normal \<C-Y>\<C-Y>"
  1132. call assert_equal(h + 1, line('w$'))
  1133. " Test for CTRL-Y from the first line and CTRL-E from the last line
  1134. %d
  1135. set scrolloff=2
  1136. call setline(1, range(1, 4))
  1137. exe "normal gg\<C-Y>"
  1138. call assert_equal(1, line('w0'))
  1139. call assert_equal(1, line('.'))
  1140. exe "normal G4\<C-E>\<C-E>"
  1141. call assert_equal(4, line('w$'))
  1142. call assert_equal(4, line('.'))
  1143. set scrolloff&
  1144. " Using <PageUp> and <PageDown> in an empty buffer should beep
  1145. %d
  1146. call assert_beeps('exe "normal \<PageUp>"')
  1147. call assert_beeps('exe "normal \<C-B>"')
  1148. call assert_beeps('exe "normal \<PageDown>"')
  1149. call assert_beeps('exe "normal \<C-F>"')
  1150. " Test for <C-U> and <C-D> with fold
  1151. %d
  1152. call setline(1, range(1, 100))
  1153. 10,35fold
  1154. set scroll=10
  1155. exe "normal \<C-D>"
  1156. call assert_equal(36, line('.'))
  1157. exe "normal \<C-D>"
  1158. call assert_equal(46, line('.'))
  1159. exe "normal \<C-U>"
  1160. call assert_equal(36, line('.'))
  1161. exe "normal \<C-U>"
  1162. call assert_equal(1, line('.'))
  1163. exe "normal \<C-U>"
  1164. call assert_equal(1, line('.'))
  1165. set scroll&
  1166. " Test for scrolling to the top of the file with <C-U> and a fold
  1167. 10
  1168. normal ztL
  1169. exe "normal \<C-U>\<C-U>"
  1170. call assert_equal(1, line('w0'))
  1171. " Test for CTRL-D on a folded line
  1172. %d
  1173. call setline(1, range(1, 100))
  1174. 50,100fold
  1175. 75
  1176. normal z-
  1177. exe "normal \<C-D>"
  1178. call assert_equal(50, line('.'))
  1179. call assert_equal(100, line('w$'))
  1180. normal z.
  1181. let lnum = winline()
  1182. exe "normal \<C-D>"
  1183. call assert_equal(lnum, winline())
  1184. call assert_equal(50, line('.'))
  1185. normal zt
  1186. exe "normal \<C-D>"
  1187. call assert_equal(50, line('w0'))
  1188. " Test for <S-CR>. Page down.
  1189. %d
  1190. call setline(1, range(1, 100))
  1191. call feedkeys("\<S-CR>", 'xt')
  1192. call assert_equal(14, line('w0'))
  1193. call assert_equal(28, line('w$'))
  1194. " Test for <S-->. Page up.
  1195. call feedkeys("\<S-->", 'xt')
  1196. call assert_equal(1, line('w0'))
  1197. call assert_equal(15, line('w$'))
  1198. set foldenable&
  1199. bwipe!
  1200. endfunc
  1201. func Test_scroll_in_ex_mode()
  1202. " This was using invalid memory because w_botline was invalid.
  1203. let lines =<< trim END
  1204. diffsplit
  1205. norm os00(
  1206. call writefile(['done'], 'Xdone')
  1207. qa!
  1208. END
  1209. call writefile(lines, 'Xscript')
  1210. call assert_equal(1, RunVim([], [], '--clean -X -Z -e -s -S Xscript'))
  1211. call assert_equal(['done'], readfile('Xdone'))
  1212. call delete('Xscript')
  1213. call delete('Xdone')
  1214. endfunc
  1215. " Test for the 'sidescroll' option
  1216. func Test_sidescroll_opt()
  1217. new
  1218. 20vnew
  1219. " scroll by 2 characters horizontally
  1220. set sidescroll=2 nowrap
  1221. call setline(1, repeat('a', 40))
  1222. normal g$l
  1223. call assert_equal(19, screenpos(0, 1, 21).col)
  1224. normal l
  1225. call assert_equal(20, screenpos(0, 1, 22).col)
  1226. normal g0h
  1227. call assert_equal(2, screenpos(0, 1, 2).col)
  1228. call assert_equal(20, screenpos(0, 1, 20).col)
  1229. " when 'sidescroll' is 0, cursor positioned at the center
  1230. set sidescroll=0
  1231. normal g$l
  1232. call assert_equal(11, screenpos(0, 1, 21).col)
  1233. normal g0h
  1234. call assert_equal(10, screenpos(0, 1, 10).col)
  1235. %bw!
  1236. set wrap& sidescroll&
  1237. endfunc
  1238. " basic tests for foldopen/folddelete
  1239. func Test_normal18_z_fold()
  1240. CheckFeature folding
  1241. call Setup_NewWindow()
  1242. 50
  1243. setl foldenable fdm=marker foldlevel=5
  1244. call assert_beeps('normal! zj')
  1245. call assert_beeps('normal! zk')
  1246. " Test for zF
  1247. " First fold
  1248. norm! 4zF
  1249. " check that folds have been created
  1250. call assert_equal(['50/* {{{ */', '51', '52', '53/* }}} */'], getline(50,53))
  1251. " Test for zd
  1252. 51
  1253. norm! 2zF
  1254. call assert_equal(2, foldlevel('.'))
  1255. norm! kzd
  1256. call assert_equal(['50', '51/* {{{ */', '52/* }}} */', '53'], getline(50,53))
  1257. norm! j
  1258. call assert_equal(1, foldlevel('.'))
  1259. " Test for zD
  1260. " also deletes partially selected folds recursively
  1261. 51
  1262. norm! zF
  1263. call assert_equal(2, foldlevel('.'))
  1264. norm! kV2jzD
  1265. call assert_equal(['50', '51', '52', '53'], getline(50,53))
  1266. " Test for zE
  1267. 85
  1268. norm! 4zF
  1269. 86
  1270. norm! 2zF
  1271. 90
  1272. norm! 4zF
  1273. call assert_equal(['85/* {{{ */', '86/* {{{ */', '87/* }}} */', '88/* }}} */', '89', '90/* {{{ */', '91', '92', '93/* }}} */'], getline(85,93))
  1274. norm! zE
  1275. call assert_equal(['85', '86', '87', '88', '89', '90', '91', '92', '93'], getline(85,93))
  1276. " Test for zn
  1277. 50
  1278. set foldlevel=0
  1279. norm! 2zF
  1280. norm! zn
  1281. norm! k
  1282. call assert_equal('49', getline('.'))
  1283. norm! j
  1284. call assert_equal('50/* {{{ */', getline('.'))
  1285. norm! j
  1286. call assert_equal('51/* }}} */', getline('.'))
  1287. norm! j
  1288. call assert_equal('52', getline('.'))
  1289. call assert_equal(0, &foldenable)
  1290. " Test for zN
  1291. 49
  1292. norm! zN
  1293. call assert_equal('49', getline('.'))
  1294. norm! j
  1295. call assert_equal('50/* {{{ */', getline('.'))
  1296. norm! j
  1297. call assert_equal('52', getline('.'))
  1298. call assert_equal(1, &foldenable)
  1299. " Test for zi
  1300. norm! zi
  1301. call assert_equal(0, &foldenable)
  1302. norm! zi
  1303. call assert_equal(1, &foldenable)
  1304. norm! zi
  1305. call assert_equal(0, &foldenable)
  1306. norm! zi
  1307. call assert_equal(1, &foldenable)
  1308. " Test for za
  1309. 50
  1310. norm! za
  1311. norm! k
  1312. call assert_equal('49', getline('.'))
  1313. norm! j
  1314. call assert_equal('50/* {{{ */', getline('.'))
  1315. norm! j
  1316. call assert_equal('51/* }}} */', getline('.'))
  1317. norm! j
  1318. call assert_equal('52', getline('.'))
  1319. 50
  1320. norm! za
  1321. norm! k
  1322. call assert_equal('49', getline('.'))
  1323. norm! j
  1324. call assert_equal('50/* {{{ */', getline('.'))
  1325. norm! j
  1326. call assert_equal('52', getline('.'))
  1327. 49
  1328. norm! 5zF
  1329. norm! k
  1330. call assert_equal('48', getline('.'))
  1331. norm! j
  1332. call assert_equal('49/* {{{ */', getline('.'))
  1333. norm! j
  1334. call assert_equal('55', getline('.'))
  1335. 49
  1336. norm! za
  1337. call assert_equal('49/* {{{ */', getline('.'))
  1338. norm! j
  1339. call assert_equal('50/* {{{ */', getline('.'))
  1340. norm! j
  1341. call assert_equal('52', getline('.'))
  1342. set nofoldenable
  1343. " close fold and set foldenable
  1344. norm! za
  1345. call assert_equal(1, &foldenable)
  1346. 50
  1347. " have to use {count}za to open all folds and make the cursor visible
  1348. norm! 2za
  1349. norm! 2k
  1350. call assert_equal('48', getline('.'))
  1351. norm! j
  1352. call assert_equal('49/* {{{ */', getline('.'))
  1353. norm! j
  1354. call assert_equal('50/* {{{ */', getline('.'))
  1355. norm! j
  1356. call assert_equal('51/* }}} */', getline('.'))
  1357. norm! j
  1358. call assert_equal('52', getline('.'))
  1359. " Test for zA
  1360. 49
  1361. set foldlevel=0
  1362. 50
  1363. norm! zA
  1364. norm! 2k
  1365. call assert_equal('48', getline('.'))
  1366. norm! j
  1367. call assert_equal('49/* {{{ */', getline('.'))
  1368. norm! j
  1369. call assert_equal('50/* {{{ */', getline('.'))
  1370. norm! j
  1371. call assert_equal('51/* }}} */', getline('.'))
  1372. norm! j
  1373. call assert_equal('52', getline('.'))
  1374. " zA on an opened fold when foldenable is not set
  1375. 50
  1376. set nofoldenable
  1377. norm! zA
  1378. call assert_equal(1, &foldenable)
  1379. norm! k
  1380. call assert_equal('48', getline('.'))
  1381. norm! j
  1382. call assert_equal('49/* {{{ */', getline('.'))
  1383. norm! j
  1384. call assert_equal('55', getline('.'))
  1385. " Test for zc
  1386. norm! zE
  1387. 50
  1388. norm! 2zF
  1389. 49
  1390. norm! 5zF
  1391. set nofoldenable
  1392. 50
  1393. " There most likely is a bug somewhere:
  1394. " https://groups.google.com/d/msg/vim_dev/v2EkfJ_KQjI/u-Cvv94uCAAJ
  1395. " TODO: Should this only close the inner most fold or both folds?
  1396. norm! zc
  1397. call assert_equal(1, &foldenable)
  1398. norm! k
  1399. call assert_equal('48', getline('.'))
  1400. norm! j
  1401. call assert_equal('49/* {{{ */', getline('.'))
  1402. norm! j
  1403. call assert_equal('55', getline('.'))
  1404. set nofoldenable
  1405. 50
  1406. norm! Vjzc
  1407. norm! k
  1408. call assert_equal('48', getline('.'))
  1409. norm! j
  1410. call assert_equal('49/* {{{ */', getline('.'))
  1411. norm! j
  1412. call assert_equal('55', getline('.'))
  1413. " Test for zC
  1414. set nofoldenable
  1415. 50
  1416. norm! zCk
  1417. call assert_equal('48', getline('.'))
  1418. norm! j
  1419. call assert_equal('49/* {{{ */', getline('.'))
  1420. norm! j
  1421. call assert_equal('55', getline('.'))
  1422. " Test for zx
  1423. " 1) close folds at line 49-54
  1424. set nofoldenable
  1425. 48
  1426. norm! zx
  1427. call assert_equal(1, &foldenable)
  1428. norm! j
  1429. call assert_equal('49/* {{{ */', getline('.'))
  1430. norm! j
  1431. call assert_equal('55', getline('.'))
  1432. " 2) do not close fold under cursor
  1433. 51
  1434. set nofoldenable
  1435. norm! zx
  1436. call assert_equal(1, &foldenable)
  1437. norm! 3k
  1438. call assert_equal('48', getline('.'))
  1439. norm! j
  1440. call assert_equal('49/* {{{ */', getline('.'))
  1441. norm! j
  1442. call assert_equal('50/* {{{ */', getline('.'))
  1443. norm! j
  1444. call assert_equal('51/* }}} */', getline('.'))
  1445. norm! j
  1446. call assert_equal('52', getline('.'))
  1447. norm! j
  1448. call assert_equal('53', getline('.'))
  1449. norm! j
  1450. call assert_equal('54/* }}} */', getline('.'))
  1451. norm! j
  1452. call assert_equal('55', getline('.'))
  1453. " 3) close one level of folds
  1454. 48
  1455. set nofoldenable
  1456. set foldlevel=1
  1457. norm! zx
  1458. call assert_equal(1, &foldenable)
  1459. call assert_equal('48', getline('.'))
  1460. norm! j
  1461. call assert_equal('49/* {{{ */', getline('.'))
  1462. norm! j
  1463. call assert_equal('50/* {{{ */', getline('.'))
  1464. norm! j
  1465. call assert_equal('52', getline('.'))
  1466. norm! j
  1467. call assert_equal('53', getline('.'))
  1468. norm! j
  1469. call assert_equal('54/* }}} */', getline('.'))
  1470. norm! j
  1471. call assert_equal('55', getline('.'))
  1472. " Test for zX
  1473. " Close all folds
  1474. set foldlevel=0 nofoldenable
  1475. 50
  1476. norm! zX
  1477. call assert_equal(1, &foldenable)
  1478. norm! k
  1479. call assert_equal('48', getline('.'))
  1480. norm! j
  1481. call assert_equal('49/* {{{ */', getline('.'))
  1482. norm! j
  1483. call assert_equal('55', getline('.'))
  1484. " Test for zm
  1485. 50
  1486. set nofoldenable foldlevel=2
  1487. norm! zm
  1488. call assert_equal(1, &foldenable)
  1489. call assert_equal(1, &foldlevel)
  1490. norm! zm
  1491. call assert_equal(0, &foldlevel)
  1492. norm! zm
  1493. call assert_equal(0, &foldlevel)
  1494. norm! k
  1495. call assert_equal('48', getline('.'))
  1496. norm! j
  1497. call assert_equal('49/* {{{ */', getline('.'))
  1498. norm! j
  1499. call assert_equal('55', getline('.'))
  1500. " Test for zm with a count
  1501. 50
  1502. set foldlevel=2
  1503. norm! 3zm
  1504. call assert_equal(0, &foldlevel)
  1505. call assert_equal(49, foldclosed(line('.')))
  1506. " Test for zM
  1507. 48
  1508. set nofoldenable foldlevel=99
  1509. norm! zM
  1510. call assert_equal(1, &foldenable)
  1511. call assert_equal(0, &foldlevel)
  1512. call assert_equal('48', getline('.'))
  1513. norm! j
  1514. call assert_equal('49/* {{{ */', getline('.'))
  1515. norm! j
  1516. call assert_equal('55', getline('.'))
  1517. " Test for zr
  1518. 48
  1519. set nofoldenable foldlevel=0
  1520. norm! zr
  1521. call assert_equal(0, &foldenable)
  1522. call assert_equal(1, &foldlevel)
  1523. set foldlevel=0 foldenable
  1524. norm! zr
  1525. call assert_equal(1, &foldenable)
  1526. call assert_equal(1, &foldlevel)
  1527. norm! zr
  1528. call assert_equal(2, &foldlevel)
  1529. call assert_equal('48', getline('.'))
  1530. norm! j
  1531. call assert_equal('49/* {{{ */', getline('.'))
  1532. norm! j
  1533. call assert_equal('50/* {{{ */', getline('.'))
  1534. norm! j
  1535. call assert_equal('51/* }}} */', getline('.'))
  1536. norm! j
  1537. call assert_equal('52', getline('.'))
  1538. " Test for zR
  1539. 48
  1540. set nofoldenable foldlevel=0
  1541. norm! zR
  1542. call assert_equal(0, &foldenable)
  1543. call assert_equal(2, &foldlevel)
  1544. set foldenable foldlevel=0
  1545. norm! zR
  1546. call assert_equal(1, &foldenable)
  1547. call assert_equal(2, &foldlevel)
  1548. call assert_equal('48', getline('.'))
  1549. norm! j
  1550. call assert_equal('49/* {{{ */', getline('.'))
  1551. norm! j
  1552. call assert_equal('50/* {{{ */', getline('.'))
  1553. norm! j
  1554. call assert_equal('51/* }}} */', getline('.'))
  1555. norm! j
  1556. call assert_equal('52', getline('.'))
  1557. call append(50, ['a /* {{{ */', 'b /* }}} */'])
  1558. 48
  1559. call assert_equal('48', getline('.'))
  1560. norm! j
  1561. call assert_equal('49/* {{{ */', getline('.'))
  1562. norm! j
  1563. call assert_equal('50/* {{{ */', getline('.'))
  1564. norm! j
  1565. call assert_equal('a /* {{{ */', getline('.'))
  1566. norm! j
  1567. call assert_equal('51/* }}} */', getline('.'))
  1568. norm! j
  1569. call assert_equal('52', getline('.'))
  1570. 48
  1571. norm! zR
  1572. call assert_equal(1, &foldenable)
  1573. call assert_equal(3, &foldlevel)
  1574. call assert_equal('48', getline('.'))
  1575. norm! j
  1576. call assert_equal('49/* {{{ */', getline('.'))
  1577. norm! j
  1578. call assert_equal('50/* {{{ */', getline('.'))
  1579. norm! j
  1580. call assert_equal('a /* {{{ */', getline('.'))
  1581. norm! j
  1582. call assert_equal('b /* }}} */', getline('.'))
  1583. norm! j
  1584. call assert_equal('51/* }}} */', getline('.'))
  1585. norm! j
  1586. call assert_equal('52', getline('.'))
  1587. " clean up
  1588. setl nofoldenable fdm=marker foldlevel=0
  1589. bw!
  1590. endfunc
  1591. func Test_normal20_exmode()
  1592. " Reading from redirected file doesn't work on MS-Windows
  1593. CheckNotMSWindows
  1594. call writefile(['1a', 'foo', 'bar', '.', 'w! Xfile2', 'q!'], 'Xscript')
  1595. call writefile(['1', '2'], 'Xfile')
  1596. call system(GetVimCommand() .. ' -e -s < Xscript Xfile')
  1597. let a=readfile('Xfile2')
  1598. call assert_equal(['1', 'foo', 'bar', '2'], a)
  1599. " clean up
  1600. for file in ['Xfile', 'Xfile2', 'Xscript']
  1601. call delete(file)
  1602. endfor
  1603. bw!
  1604. endfunc
  1605. func Test_normal21_nv_hat()
  1606. " Edit a fresh file and wipe the buffer list so that there is no alternate
  1607. " file present. Next, check for the expected command failures.
  1608. edit Xfoo | %bw
  1609. call assert_fails(':buffer #', 'E86')
  1610. call assert_fails(':execute "normal! \<C-^>"', 'E23')
  1611. call assert_fails("normal i\<C-R>#", 'E23:')
  1612. " Test for the expected behavior when switching between two named buffers.
  1613. edit Xfoo | edit Xbar
  1614. call feedkeys("\<C-^>", 'tx')
  1615. call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
  1616. call feedkeys("\<C-^>", 'tx')
  1617. call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
  1618. " Test for the expected behavior when only one buffer is named.
  1619. enew | let l:nr = bufnr('%')
  1620. call feedkeys("\<C-^>", 'tx')
  1621. call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
  1622. call feedkeys("\<C-^>", 'tx')
  1623. call assert_equal('', bufname('%'))
  1624. call assert_equal(l:nr, bufnr('%'))
  1625. " Test that no action is taken by "<C-^>" when an operator is pending.
  1626. edit Xfoo
  1627. call feedkeys("ci\<C-^>", 'tx')
  1628. call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
  1629. %bw!
  1630. endfunc
  1631. func Test_normal22_zet()
  1632. " Test for ZZ
  1633. " let shell = &shell
  1634. " let &shell = 'sh'
  1635. call writefile(['1', '2'], 'Xn22file', 'D')
  1636. let args = ' -N -i NONE --noplugins -X --headless'
  1637. call system(GetVimCommand() .. args .. ' -c "%d" -c ":norm! ZZ" Xn22file')
  1638. let a = readfile('Xn22file')
  1639. call assert_equal([], a)
  1640. " Test for ZQ
  1641. call writefile(['1', '2'], 'Xn22file')
  1642. call system(GetVimCommand() . args . ' -c "%d" -c ":norm! ZQ" Xn22file')
  1643. let a = readfile('Xn22file')
  1644. call assert_equal(['1', '2'], a)
  1645. " Unsupported Z command
  1646. call assert_beeps('normal! ZW')
  1647. " clean up
  1648. " let &shell = shell
  1649. endfunc
  1650. func Test_normal23_K()
  1651. " Test for K command
  1652. new
  1653. call append(0, ['helphelp.txt', 'man', 'aa%bb', 'cc|dd'])
  1654. let k = &keywordprg
  1655. set keywordprg=:help
  1656. 1
  1657. norm! VK
  1658. call assert_equal('helphelp.txt', fnamemodify(bufname('%'), ':t'))
  1659. call assert_equal('help', &ft)
  1660. call assert_match('\*helphelp.txt\*', getline('.'))
  1661. helpclose
  1662. norm! 0K
  1663. call assert_equal('helphelp.txt', fnamemodify(bufname('%'), ':t'))
  1664. call assert_equal('help', &ft)
  1665. call assert_match('Help on help files', getline('.'))
  1666. helpclose
  1667. set keywordprg=:new
  1668. set iskeyword+=%
  1669. set iskeyword+=\|
  1670. 2
  1671. norm! K
  1672. call assert_equal('man', fnamemodify(bufname('%'), ':t'))
  1673. bwipe!
  1674. 3
  1675. norm! K
  1676. call assert_equal('aa%bb', fnamemodify(bufname('%'), ':t'))
  1677. bwipe!
  1678. if !has('win32')
  1679. 4
  1680. norm! K
  1681. call assert_equal('cc|dd', fnamemodify(bufname('%'), ':t'))
  1682. bwipe!
  1683. endif
  1684. set iskeyword-=%
  1685. set iskeyword-=\|
  1686. " Currently doesn't work in Nvim, see #19436
  1687. " Test for specifying a count to K
  1688. " 1
  1689. " com! -nargs=* Kprog let g:Kprog_Args = <q-args>
  1690. " set keywordprg=:Kprog
  1691. " norm! 3K
  1692. " call assert_equal('3 version8', g:Kprog_Args)
  1693. " delcom Kprog
  1694. " Only expect "man" to work on Unix
  1695. if !has("unix") || has('nvim') " Nvim K uses :terminal. #15398
  1696. let &keywordprg = k
  1697. bw!
  1698. return
  1699. endif
  1700. let not_gnu_man = has('mac') || has('bsd')
  1701. if not_gnu_man
  1702. " In macOS and BSD, the option for specifying a pager is different
  1703. set keywordprg=man\ -P\ cat
  1704. else
  1705. set keywordprg=man\ --pager=cat
  1706. endif
  1707. " Test for using man
  1708. 2
  1709. let a = execute('unsilent norm! K')
  1710. if not_gnu_man
  1711. call assert_match("man -P cat 'man'", a)
  1712. else
  1713. call assert_match("man --pager=cat 'man'", a)
  1714. endif
  1715. " Error cases
  1716. call setline(1, '#$#')
  1717. call assert_fails('normal! ggK', 'E349:')
  1718. call setline(1, '---')
  1719. call assert_fails('normal! ggv2lK', 'E349:')
  1720. call setline(1, ['abc', 'xyz'])
  1721. call assert_fails("normal! gg2lv2h\<C-]>", 'E433:')
  1722. call assert_beeps("normal! ggVjK")
  1723. " clean up
  1724. let &keywordprg = k
  1725. bw!
  1726. endfunc
  1727. func Test_normal24_rot13()
  1728. " Testing for g?? g?g?
  1729. new
  1730. call append(0, 'abcdefghijklmnopqrstuvwxyzäüö')
  1731. 1
  1732. norm! g??
  1733. call assert_equal('nopqrstuvwxyzabcdefghijklmäüö', getline('.'))
  1734. norm! g?g?
  1735. call assert_equal('abcdefghijklmnopqrstuvwxyzäüö', getline('.'))
  1736. " clean up
  1737. bw!
  1738. endfunc
  1739. func Test_normal25_tag()
  1740. CheckFeature quickfix
  1741. " Testing for CTRL-] g CTRL-] g]
  1742. " CTRL-W g] CTRL-W CTRL-] CTRL-W g CTRL-]
  1743. h
  1744. " Test for CTRL-]
  1745. call search('\<x\>$')
  1746. exe "norm! \<c-]>"
  1747. call assert_equal("change.txt", fnamemodify(bufname('%'), ':t'))
  1748. norm! yiW
  1749. call assert_equal("*x*", @0)
  1750. exe ":norm \<c-o>"
  1751. " Test for g_CTRL-]
  1752. call search('\<v_u\>$')
  1753. exe "norm! g\<c-]>"
  1754. call assert_equal("change.txt", fnamemodify(bufname('%'), ':t'))
  1755. norm! yiW
  1756. call assert_equal("*v_u*", @0)
  1757. exe ":norm \<c-o>"
  1758. " Test for g]
  1759. call search('\<i_<Esc>$')
  1760. let a = execute(":norm! g]")
  1761. call assert_match('i_<Esc>.*insert.txt', a)
  1762. if !empty(exepath('cscope')) && has('cscope')
  1763. " setting cscopetag changes how g] works
  1764. set cst
  1765. exe "norm! g]"
  1766. call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
  1767. norm! yiW
  1768. call assert_equal("*i_<Esc>*", @0)
  1769. exe ":norm \<c-o>"
  1770. " Test for CTRL-W g]
  1771. exe "norm! \<C-W>g]"
  1772. call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
  1773. norm! yiW
  1774. call assert_equal("*i_<Esc>*", @0)
  1775. call assert_equal(3, winnr('$'))
  1776. helpclose
  1777. set nocst
  1778. endif
  1779. " Test for CTRL-W g]
  1780. let a = execute("norm! \<C-W>g]")
  1781. call assert_match('i_<Esc>.*insert.txt', a)
  1782. " Test for CTRL-W CTRL-]
  1783. exe "norm! \<C-W>\<C-]>"
  1784. call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
  1785. norm! yiW
  1786. call assert_equal("*i_<Esc>*", @0)
  1787. call assert_equal(3, winnr('$'))
  1788. helpclose
  1789. " Test for CTRL-W g CTRL-]
  1790. exe "norm! \<C-W>g\<C-]>"
  1791. call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
  1792. norm! yiW
  1793. call assert_equal("*i_<Esc>*", @0)
  1794. call assert_equal(3, winnr('$'))
  1795. helpclose
  1796. " clean up
  1797. helpclose
  1798. endfunc
  1799. func Test_normal26_put()
  1800. " Test for ]p ]P [p and [P
  1801. new
  1802. call append(0, ['while read LINE', 'do', ' ((count++))', ' if [ $? -ne 0 ]; then', " echo 'Error writing file'", ' fi', 'done'])
  1803. 1
  1804. /Error/y a
  1805. 2
  1806. norm! "a]pj"a[p
  1807. call assert_equal(['do', "echo 'Error writing file'", " echo 'Error writing file'", ' ((count++))'], getline(2,5))
  1808. 1
  1809. /^\s\{4}/
  1810. exe "norm! \"a]P3Eldt'"
  1811. exe "norm! j\"a[P2Eldt'"
  1812. call assert_equal([' if [ $? -ne 0 ]; then', " echo 'Error writing'", " echo 'Error'", " echo 'Error writing file'", ' fi'], getline(6,10))
  1813. " clean up
  1814. bw!
  1815. endfunc
  1816. func Test_normal27_bracket()
  1817. " Test for [' [` ]' ]`
  1818. call Setup_NewWindow()
  1819. 1,21s/.\+/ & b/
  1820. 1
  1821. norm! $ma
  1822. 5
  1823. norm! $mb
  1824. 10
  1825. norm! $mc
  1826. 15
  1827. norm! $md
  1828. 20
  1829. norm! $me
  1830. " Test for ['
  1831. 9
  1832. norm! 2['
  1833. call assert_equal(' 1 b', getline('.'))
  1834. call assert_equal(1, line('.'))
  1835. call assert_equal(3, col('.'))
  1836. " Test for ]'
  1837. norm! ]'
  1838. call assert_equal(' 5 b', getline('.'))
  1839. call assert_equal(5, line('.'))
  1840. call assert_equal(3, col('.'))
  1841. " No mark before line 1, cursor moves to first non-blank on current line
  1842. 1
  1843. norm! 5|['
  1844. call assert_equal(' 1 b', getline('.'))
  1845. call assert_equal(1, line('.'))
  1846. call assert_equal(3, col('.'))
  1847. " No mark after line 21, cursor moves to first non-blank on current line
  1848. 21
  1849. norm! 5|]'
  1850. call assert_equal(' 21 b', getline('.'))
  1851. call assert_equal(21, line('.'))
  1852. call assert_equal(3, col('.'))
  1853. " Test for [`
  1854. norm! 2[`
  1855. call assert_equal(' 15 b', getline('.'))
  1856. call assert_equal(15, line('.'))
  1857. call assert_equal(8, col('.'))
  1858. " Test for ]`
  1859. norm! ]`
  1860. call assert_equal(' 20 b', getline('.'))
  1861. call assert_equal(20, line('.'))
  1862. call assert_equal(8, col('.'))
  1863. " No mark before line 1, cursor does not move
  1864. 1
  1865. norm! 5|[`
  1866. call assert_equal(' 1 b', getline('.'))
  1867. call assert_equal(1, line('.'))
  1868. call assert_equal(5, col('.'))
  1869. " No mark after line 21, cursor does not move
  1870. 21
  1871. norm! 5|]`
  1872. call assert_equal(' 21 b', getline('.'))
  1873. call assert_equal(21, line('.'))
  1874. call assert_equal(5, col('.'))
  1875. " Count too large for [`
  1876. " cursor moves to first lowercase mark
  1877. norm! 99[`
  1878. call assert_equal(' 1 b', getline('.'))
  1879. call assert_equal(1, line('.'))
  1880. call assert_equal(7, col('.'))
  1881. " Count too large for ]`
  1882. " cursor moves to last lowercase mark
  1883. norm! 99]`
  1884. call assert_equal(' 20 b', getline('.'))
  1885. call assert_equal(20, line('.'))
  1886. call assert_equal(8, col('.'))
  1887. " clean up
  1888. bw!
  1889. endfunc
  1890. " Test for ( and ) sentence movements
  1891. func Test_normal28_parenthesis()
  1892. new
  1893. call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here'])
  1894. $
  1895. norm! d(
  1896. call assert_equal(['This is a test. With some sentences!', '', 'Even with a question? And one more. ', ''], getline(1, '$'))
  1897. norm! 2d(
  1898. call assert_equal(['This is a test. With some sentences!', '', ' ', ''], getline(1, '$'))
  1899. 1
  1900. norm! 0d)
  1901. call assert_equal(['With some sentences!', '', ' ', ''], getline(1, '$'))
  1902. call append('$', ['This is a long sentence', '', 'spanning', 'over several lines. '])
  1903. $
  1904. norm! $d(
  1905. call assert_equal(['With some sentences!', '', ' ', '', 'This is a long sentence', ''], getline(1, '$'))
  1906. " Move to the next sentence from a paragraph macro
  1907. %d
  1908. call setline(1, ['.LP', 'blue sky!. blue sky.', 'blue sky. blue sky.'])
  1909. call cursor(1, 1)
  1910. normal )
  1911. call assert_equal([2, 1], [line('.'), col('.')])
  1912. normal )
  1913. call assert_equal([2, 12], [line('.'), col('.')])
  1914. normal ((
  1915. call assert_equal([1, 1], [line('.'), col('.')])
  1916. " It is an error if a next sentence is not found
  1917. %d
  1918. call setline(1, '.SH')
  1919. call assert_beeps('normal )')
  1920. " If only dot is present, don't treat that as a sentence
  1921. call setline(1, '. This is a sentence.')
  1922. normal $((
  1923. call assert_equal(3, col('.'))
  1924. " Jumping to a fold should open the fold
  1925. call setline(1, ['', '', 'one', 'two', 'three'])
  1926. set foldenable
  1927. 2,$fold
  1928. call feedkeys(')', 'xt')
  1929. call assert_equal(3, line('.'))
  1930. call assert_equal(1, foldlevel('.'))
  1931. call assert_equal(-1, foldclosed('.'))
  1932. set foldenable&
  1933. " clean up
  1934. bw!
  1935. endfunc
  1936. " Test for { and } paragraph movements
  1937. func Test_normal29_brace()
  1938. let text =<< trim [DATA]
  1939. A paragraph begins after each empty line, and also at each of a set of
  1940. paragraph macros, specified by the pairs of characters in the 'paragraphs'
  1941. option. The default is "IPLPPPQPP TPHPLIPpLpItpplpipbp", which corresponds to
  1942. the macros ".IP", ".LP", etc. (These are nroff macros, so the dot must be in
  1943. the first column). A section boundary is also a paragraph boundary.
  1944. Note that a blank line (only containing white space) is NOT a paragraph
  1945. boundary.
  1946. Also note that this does not include a '{' or '}' in the first column. When
  1947. the '{' flag is in 'cpoptions' then '{' in the first column is used as a
  1948. paragraph boundary |posix|.
  1949. {
  1950. This is no paragraph
  1951. unless the '{' is set
  1952. in 'cpoptions'
  1953. }
  1954. .IP
  1955. The nroff macros IP separates a paragraph
  1956. That means, it must be a '.'
  1957. followed by IP
  1958. .LPIt does not matter, if afterwards some
  1959. more characters follow.
  1960. .SHAlso section boundaries from the nroff
  1961. macros terminate a paragraph. That means
  1962. a character like this:
  1963. .NH
  1964. End of text here
  1965. [DATA]
  1966. new
  1967. call append(0, text)
  1968. 1
  1969. norm! 0d2}
  1970. let expected =<< trim [DATA]
  1971. .IP
  1972. The nroff macros IP separates a paragraph
  1973. That means, it must be a '.'
  1974. followed by IP
  1975. .LPIt does not matter, if afterwards some
  1976. more characters follow.
  1977. .SHAlso section boundaries from the nroff
  1978. macros terminate a paragraph. That means
  1979. a character like this:
  1980. .NH
  1981. End of text here
  1982. [DATA]
  1983. call assert_equal(expected, getline(1, '$'))
  1984. norm! 0d}
  1985. let expected =<< trim [DATA]
  1986. .LPIt does not matter, if afterwards some
  1987. more characters follow.
  1988. .SHAlso section boundaries from the nroff
  1989. macros terminate a paragraph. That means
  1990. a character like this:
  1991. .NH
  1992. End of text here
  1993. [DATA]
  1994. call assert_equal(expected, getline(1, '$'))
  1995. $
  1996. norm! d{
  1997. let expected =<< trim [DATA]
  1998. .LPIt does not matter, if afterwards some
  1999. more characters follow.
  2000. .SHAlso section boundaries from the nroff
  2001. macros terminate a paragraph. That means
  2002. a character like this:
  2003. [DATA]
  2004. call assert_equal(expected, getline(1, '$'))
  2005. norm! d{
  2006. let expected =<< trim [DATA]
  2007. .LPIt does not matter, if afterwards some
  2008. more characters follow.
  2009. [DATA]
  2010. call assert_equal(expected, getline(1, '$'))
  2011. " Test with { in cpoptions
  2012. %d
  2013. call append(0, text)
  2014. " Nvim: no "{" flag in 'cpoptions'.
  2015. " set cpo+={
  2016. " 1
  2017. " norm! 0d2}
  2018. let expected =<< trim [DATA]
  2019. {
  2020. This is no paragraph
  2021. unless the '{' is set
  2022. in 'cpoptions'
  2023. }
  2024. .IP
  2025. The nroff macros IP separates a paragraph
  2026. That means, it must be a '.'
  2027. followed by IP
  2028. .LPIt does not matter, if afterwards some
  2029. more characters follow.
  2030. .SHAlso section boundaries from the nroff
  2031. macros terminate a paragraph. That means
  2032. a character like this:
  2033. .NH
  2034. End of text here
  2035. [DATA]
  2036. " call assert_equal(expected, getline(1, '$'))
  2037. " $
  2038. " norm! d}
  2039. let expected =<< trim [DATA]
  2040. {
  2041. This is no paragraph
  2042. unless the '{' is set
  2043. in 'cpoptions'
  2044. }
  2045. .IP
  2046. The nroff macros IP separates a paragraph
  2047. That means, it must be a '.'
  2048. followed by IP
  2049. .LPIt does not matter, if afterwards some
  2050. more characters follow.
  2051. .SHAlso section boundaries from the nroff
  2052. macros terminate a paragraph. That means
  2053. a character like this:
  2054. .NH
  2055. End of text here
  2056. [DATA]
  2057. " call assert_equal(expected, getline(1, '$'))
  2058. " norm! gg}
  2059. " norm! d5}
  2060. let expected =<< trim [DATA]
  2061. {
  2062. This is no paragraph
  2063. unless the '{' is set
  2064. in 'cpoptions'
  2065. }
  2066. [DATA]
  2067. " call assert_equal(expected, getline(1, '$'))
  2068. " Jumping to a fold should open the fold
  2069. " %d
  2070. " call setline(1, ['', 'one', 'two', ''])
  2071. " set foldenable
  2072. " 2,$fold
  2073. " call feedkeys('}', 'xt')
  2074. " call assert_equal(4, line('.'))
  2075. " call assert_equal(1, foldlevel('.'))
  2076. " call assert_equal(-1, foldclosed('.'))
  2077. " set foldenable&
  2078. " clean up
  2079. set cpo-={
  2080. bw!
  2081. endfunc
  2082. " Test for section movements
  2083. func Test_normal_section()
  2084. new
  2085. let lines =<< trim [END]
  2086. int foo()
  2087. {
  2088. if (1)
  2089. {
  2090. a = 1;
  2091. }
  2092. }
  2093. [END]
  2094. call setline(1, lines)
  2095. " jumping to a folded line using [[ should open the fold
  2096. 2,3fold
  2097. call cursor(5, 1)
  2098. call feedkeys("[[", 'xt')
  2099. call assert_equal(2, line('.'))
  2100. call assert_equal(-1, foldclosedend(line('.')))
  2101. bwipe!
  2102. endfunc
  2103. " Test for changing case using u, U, gu, gU and ~ (tilde) commands
  2104. func Test_normal30_changecase()
  2105. new
  2106. call append(0, 'This is a simple test: äüöß')
  2107. norm! 1ggVu
  2108. call assert_equal('this is a simple test: äüöß', getline('.'))
  2109. norm! VU
  2110. call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖẞ', getline('.'))
  2111. norm! guu
  2112. call assert_equal('this is a simple test: äüöß', getline('.'))
  2113. norm! gUgU
  2114. call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖẞ', getline('.'))
  2115. norm! gugu
  2116. call assert_equal('this is a simple test: äüöß', getline('.'))
  2117. norm! gUU
  2118. call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖẞ', getline('.'))
  2119. norm! 010~
  2120. call assert_equal('this is a SIMPLE TEST: ÄÜÖẞ', getline('.'))
  2121. norm! V~
  2122. call assert_equal('THIS IS A simple test: äüöß', getline('.'))
  2123. call assert_beeps('norm! c~')
  2124. %d
  2125. call assert_beeps('norm! ~')
  2126. " Test with multiple lines
  2127. call setline(1, ['AA', 'BBBB', 'CCCCCC', 'DDDDDDDD'])
  2128. norm! ggguG
  2129. call assert_equal(['aa', 'bbbb', 'cccccc', 'dddddddd'], getline(1, '$'))
  2130. norm! GgUgg
  2131. call assert_equal(['AA', 'BBBB', 'CCCCCC', 'DDDDDDDD'], getline(1, '$'))
  2132. %d
  2133. " Test for changing case across lines using 'whichwrap'
  2134. call setline(1, ['aaaaaa', 'aaaaaa'])
  2135. normal! gg10~
  2136. call assert_equal(['AAAAAA', 'aaaaaa'], getline(1, 2))
  2137. set whichwrap+=~
  2138. normal! gg10~
  2139. call assert_equal(['aaaaaa', 'AAAAaa'], getline(1, 2))
  2140. set whichwrap&
  2141. " try changing the case with a double byte encoding (DBCS)
  2142. %bw!
  2143. let enc = &enc
  2144. " set encoding=cp932
  2145. call setline(1, "\u8470")
  2146. normal ~
  2147. normal gU$gu$gUgUg~g~gugu
  2148. call assert_equal("\u8470", getline(1))
  2149. let &encoding = enc
  2150. " clean up
  2151. bw!
  2152. endfunc
  2153. " Turkish ASCII turns to multi-byte. On some systems Turkish locale
  2154. " is available but toupper()/tolower() don't do the right thing.
  2155. func Test_normal_changecase_turkish()
  2156. new
  2157. try
  2158. lang tr_TR.UTF-8
  2159. set casemap=
  2160. let iupper = toupper('i')
  2161. if iupper == "\u0130"
  2162. call setline(1, 'iI')
  2163. 1normal gUU
  2164. call assert_equal("\u0130I", getline(1))
  2165. call assert_equal("\u0130I", toupper("iI"))
  2166. call setline(1, 'iI')
  2167. 1normal guu
  2168. call assert_equal("i\u0131", getline(1))
  2169. call assert_equal("i\u0131", tolower("iI"))
  2170. elseif iupper == "I"
  2171. call setline(1, 'iI')
  2172. 1normal gUU
  2173. call assert_equal("II", getline(1))
  2174. call assert_equal("II", toupper("iI"))
  2175. call setline(1, 'iI')
  2176. 1normal guu
  2177. call assert_equal("ii", getline(1))
  2178. call assert_equal("ii", tolower("iI"))
  2179. else
  2180. call assert_true(false, "expected toupper('i') to be either 'I' or '\u0131'")
  2181. endif
  2182. set casemap&
  2183. call setline(1, 'iI')
  2184. 1normal gUU
  2185. call assert_equal("II", getline(1))
  2186. call assert_equal("II", toupper("iI"))
  2187. call setline(1, 'iI')
  2188. 1normal guu
  2189. call assert_equal("ii", getline(1))
  2190. call assert_equal("ii", tolower("iI"))
  2191. lang en_US.UTF-8
  2192. catch /E197:/
  2193. " can't use Turkish locale
  2194. throw 'Skipped: Turkish locale not available'
  2195. endtry
  2196. bwipe!
  2197. endfunc
  2198. " Test for r (replace) command
  2199. func Test_normal31_r_cmd()
  2200. new
  2201. call append(0, 'This is a simple test: abcd')
  2202. exe "norm! 1gg$r\<cr>"
  2203. call assert_equal(['This is a simple test: abc', '', ''], getline(1,'$'))
  2204. exe "norm! 1gg2wlr\<cr>"
  2205. call assert_equal(['This is a', 'simple test: abc', '', ''], getline(1,'$'))
  2206. exe "norm! 2gg0W5r\<cr>"
  2207. call assert_equal(['This is a', 'simple ', ' abc', '', ''], getline('1', '$'))
  2208. set autoindent
  2209. call setline(2, ['simple test: abc', ''])
  2210. exe "norm! 2gg0W5r\<cr>"
  2211. call assert_equal(['This is a', 'simple ', 'abc', '', '', ''], getline('1', '$'))
  2212. exe "norm! 1ggVr\<cr>"
  2213. call assert_equal('^M^M^M^M^M^M^M^M^M', strtrans(getline(1)))
  2214. call setline(1, 'This is a')
  2215. exe "norm! 1gg05rf"
  2216. call assert_equal('fffffis a', getline(1))
  2217. " When replacing characters, copy characters from above and below lines
  2218. " using CTRL-Y and CTRL-E.
  2219. " Different code paths are used for utf-8 and latin1 encodings
  2220. set showmatch
  2221. " for enc in ['latin1', 'utf-8']
  2222. for enc in ['utf-8']
  2223. enew!
  2224. let &encoding = enc
  2225. call setline(1, [' {a}', 'xxxxxxxxxx', ' [b]'])
  2226. exe "norm! 2gg5r\<C-Y>l5r\<C-E>"
  2227. call assert_equal(' {a}x [b]x', getline(2))
  2228. endfor
  2229. set showmatch&
  2230. " r command should fail in operator pending mode
  2231. call assert_beeps('normal! cr')
  2232. " replace a tab character in visual mode
  2233. %d
  2234. call setline(1, ["a\tb", "c\td", "e\tf"])
  2235. normal gglvjjrx
  2236. call assert_equal(['axx', 'xxx', 'xxf'], getline(1, '$'))
  2237. " replace with a multibyte character (with multiple composing characters)
  2238. %d
  2239. new
  2240. call setline(1, 'aaa')
  2241. exe "normal $ra\u0328\u0301"
  2242. call assert_equal("aaa\u0328\u0301", getline(1))
  2243. " clean up
  2244. set noautoindent
  2245. bw!
  2246. endfunc
  2247. " Test for g*, g#
  2248. func Test_normal32_g_cmd1()
  2249. new
  2250. call append(0, ['abc.x_foo', 'x_foobar.abc'])
  2251. 1
  2252. norm! $g*
  2253. call assert_equal('x_foo', @/)
  2254. call assert_equal('x_foobar.abc', getline('.'))
  2255. norm! $g#
  2256. call assert_equal('abc', @/)
  2257. call assert_equal('abc.x_foo', getline('.'))
  2258. " clean up
  2259. bw!
  2260. endfunc
  2261. " Test for g`, g;, g,, g&, gv, gk, gj, gJ, g0, g^, g_, gm, g$, gM, g CTRL-G,
  2262. " gi and gI commands
  2263. func Test_normal33_g_cmd2()
  2264. call Setup_NewWindow()
  2265. " Test for g`
  2266. clearjumps
  2267. norm! ma10j
  2268. let a=execute(':jumps')
  2269. " empty jumplist
  2270. call assert_equal('>', a[-1:])
  2271. norm! g`a
  2272. call assert_equal('>', a[-1:])
  2273. call assert_equal(1, line('.'))
  2274. call assert_equal('1', getline('.'))
  2275. call cursor(10, 1)
  2276. norm! g'a
  2277. call assert_equal('>', a[-1:])
  2278. call assert_equal(1, line('.'))
  2279. let v:errmsg = ''
  2280. call assert_nobeep("normal! g`\<Esc>")
  2281. call assert_equal('', v:errmsg)
  2282. call assert_nobeep("normal! g'\<Esc>")
  2283. call assert_equal('', v:errmsg)
  2284. " Test for g; and g,
  2285. norm! g;
  2286. " there is only one change in the changelist
  2287. " currently, when we setup the window
  2288. call assert_equal(2, line('.'))
  2289. call assert_fails(':norm! g;', 'E662')
  2290. call assert_fails(':norm! g,', 'E663')
  2291. let &ul = &ul
  2292. call append('$', ['a', 'b', 'c', 'd'])
  2293. let &ul = &ul
  2294. call append('$', ['Z', 'Y', 'X', 'W'])
  2295. let a = execute(':changes')
  2296. call assert_match('2\s\+0\s\+2', a)
  2297. call assert_match('101\s\+0\s\+a', a)
  2298. call assert_match('105\s\+0\s\+Z', a)
  2299. norm! 3g;
  2300. call assert_equal(2, line('.'))
  2301. norm! 2g,
  2302. call assert_equal(105, line('.'))
  2303. " Test for g& - global substitute
  2304. %d
  2305. call setline(1, range(1,10))
  2306. call append('$', ['a', 'b', 'c', 'd'])
  2307. $s/\w/&&/g
  2308. exe "norm! /[1-8]\<cr>"
  2309. norm! g&
  2310. call assert_equal(['11', '22', '33', '44', '55', '66', '77', '88', '9', '110', 'a', 'b', 'c', 'dd'], getline(1, '$'))
  2311. " Jumping to a fold using gg should open the fold
  2312. set foldenable
  2313. set foldopen+=jump
  2314. 5,8fold
  2315. call feedkeys('6gg', 'xt')
  2316. call assert_equal(1, foldlevel('.'))
  2317. call assert_equal(-1, foldclosed('.'))
  2318. set foldopen-=jump
  2319. set foldenable&
  2320. " Test for gv
  2321. %d
  2322. call append('$', repeat(['abcdefgh'], 8))
  2323. exe "norm! 2gg02l\<c-v>2j2ly"
  2324. call assert_equal(['cde', 'cde', 'cde'], getreg(0, 1, 1))
  2325. " in visual mode, gv swaps current and last selected region
  2326. exe "norm! G0\<c-v>4k4lgvd"
  2327. call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh'], getline(1,'$'))
  2328. exe "norm! G0\<c-v>4k4ly"
  2329. exe "norm! gvood"
  2330. call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'fgh', 'fgh', 'fgh', 'fgh', 'fgh'], getline(1,'$'))
  2331. " gv cannot be used in operator pending mode
  2332. call assert_beeps('normal! cgv')
  2333. " gv should beep without a previously selected visual area
  2334. new
  2335. call assert_beeps('normal! gv')
  2336. close
  2337. " Test for gk/gj
  2338. %d
  2339. 15vsp
  2340. set wrap listchars= sbr=
  2341. let lineA = 'abcdefghijklmnopqrstuvwxyz'
  2342. let lineB = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  2343. let lineC = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
  2344. $put =lineA
  2345. $put =lineB
  2346. norm! 3gg0dgk
  2347. call assert_equal(['', 'abcdefghijklmno', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'], getline(1, '$'))
  2348. set nu
  2349. norm! 3gg0gjdgj
  2350. call assert_equal(['', 'abcdefghijklmno', '0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
  2351. " Test for gJ
  2352. norm! 2gggJ
  2353. call assert_equal(['', 'abcdefghijklmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
  2354. call assert_equal(16, col('.'))
  2355. " shouldn't do anything
  2356. norm! 10gJ
  2357. call assert_equal(1, col('.'))
  2358. " Test for g0 g^ gm g$
  2359. exe "norm! 2gg0gji "
  2360. call assert_equal(['', 'abcdefghijk lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
  2361. norm! g0yl
  2362. call assert_equal(12, col('.'))
  2363. call assert_equal(' ', getreg(0))
  2364. norm! g$yl
  2365. call assert_equal(22, col('.'))
  2366. call assert_equal('3', getreg(0))
  2367. norm! gmyl
  2368. call assert_equal(17, col('.'))
  2369. call assert_equal('n', getreg(0))
  2370. norm! g^yl
  2371. call assert_equal(15, col('.'))
  2372. call assert_equal('l', getreg(0))
  2373. call assert_beeps('normal 5g$')
  2374. " Test for g$ with double-width character half displayed
  2375. vsplit
  2376. 9wincmd |
  2377. setlocal nowrap nonumber
  2378. call setline(2, 'asdfasdfヨ')
  2379. 2
  2380. normal 0g$
  2381. call assert_equal(8, col('.'))
  2382. 10wincmd |
  2383. normal 0g$
  2384. call assert_equal(9, col('.'))
  2385. setlocal signcolumn=yes
  2386. 11wincmd |
  2387. normal 0g$
  2388. call assert_equal(8, col('.'))
  2389. 12wincmd |
  2390. normal 0g$
  2391. call assert_equal(9, col('.'))
  2392. close
  2393. " Test for g_
  2394. call assert_beeps('normal! 100g_')
  2395. call setline(2, [' foo ', ' foobar '])
  2396. normal! 2ggg_
  2397. call assert_equal(5, col('.'))
  2398. normal! 2g_
  2399. call assert_equal(8, col('.'))
  2400. norm! 2ggdG
  2401. $put =lineC
  2402. " Test for gM
  2403. norm! gMyl
  2404. call assert_equal(73, col('.'))
  2405. call assert_equal('0', getreg(0))
  2406. " Test for 20gM
  2407. norm! 20gMyl
  2408. call assert_equal(29, col('.'))
  2409. call assert_equal('S', getreg(0))
  2410. " Test for 60gM
  2411. norm! 60gMyl
  2412. call assert_equal(87, col('.'))
  2413. call assert_equal('E', getreg(0))
  2414. " Test for gM with Tab characters
  2415. call setline('.', "\ta\tb\tc\td\te\tf")
  2416. norm! gMyl
  2417. call assert_equal(6, col('.'))
  2418. call assert_equal("c", getreg(0))
  2419. " Test for g Ctrl-G
  2420. call setline('.', lineC)
  2421. norm! 60gMyl
  2422. set ff=unix
  2423. let a=execute(":norm! g\<c-g>")
  2424. call assert_match('Col 87 of 144; Line 2 of 2; Word 1 of 1; Byte 88 of 146', a)
  2425. " Test for gI
  2426. norm! gIfoo
  2427. call assert_equal(['', 'foo0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'], getline(1,'$'))
  2428. " Test for gi
  2429. wincmd c
  2430. %d
  2431. set tw=0
  2432. call setline(1, ['foobar', 'new line'])
  2433. norm! A next word
  2434. $put ='third line'
  2435. norm! gi another word
  2436. call assert_equal(['foobar next word another word', 'new line', 'third line'], getline(1,'$'))
  2437. call setline(1, 'foobar')
  2438. normal! Ggifirst line
  2439. call assert_equal('foobarfirst line', getline(1))
  2440. " Test gi in 'virtualedit' mode with cursor after the end of the line
  2441. set virtualedit=all
  2442. call setline(1, 'foo')
  2443. exe "normal! Abar\<Right>\<Right>\<Right>\<Right>"
  2444. call setline(1, 'foo')
  2445. normal! Ggifirst line
  2446. call assert_equal('foo first line', getline(1))
  2447. set virtualedit&
  2448. " Test for aborting a g command using CTRL-\ CTRL-G
  2449. exe "normal! g\<C-\>\<C-G>"
  2450. call assert_equal('foo first line', getline('.'))
  2451. " clean up
  2452. bw!
  2453. endfunc
  2454. func Test_normal_ex_substitute()
  2455. " This was hanging on the substitute prompt.
  2456. new
  2457. call setline(1, 'a')
  2458. exe "normal! gggQs/a/b/c\<CR>"
  2459. call assert_equal('a', getline(1))
  2460. bwipe!
  2461. endfunc
  2462. " Test for g CTRL-G
  2463. func Test_g_ctrl_g()
  2464. new
  2465. let a = execute(":norm! g\<c-g>")
  2466. call assert_equal("\n--No lines in buffer--", a)
  2467. " Test for CTRL-G (same as :file)
  2468. let a = execute(":norm! \<c-g>")
  2469. call assert_equal("\n\n\"[No Name]\" --No lines in buffer--", a)
  2470. call setline(1, ['first line', 'second line'])
  2471. " Test g CTRL-g with dos, mac and unix file type.
  2472. norm! gojll
  2473. set ff=dos
  2474. let a = execute(":norm! g\<c-g>")
  2475. call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 15 of 25", a)
  2476. set ff=mac
  2477. let a = execute(":norm! g\<c-g>")
  2478. call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a)
  2479. set ff=unix
  2480. let a = execute(":norm! g\<c-g>")
  2481. call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a)
  2482. " Test g CTRL-g in visual mode (v)
  2483. let a = execute(":norm! gojllvlg\<c-g>")
  2484. call assert_equal("\nSelected 1 of 2 Lines; 1 of 4 Words; 2 of 23 Bytes", a)
  2485. " Test g CTRL-g in visual mode (CTRL-V) with end col > start col
  2486. let a = execute(":norm! \<Esc>gojll\<C-V>kllg\<c-g>")
  2487. call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a)
  2488. " Test g_CTRL-g in visual mode (CTRL-V) with end col < start col
  2489. let a = execute(":norm! \<Esc>goll\<C-V>jhhg\<c-g>")
  2490. call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a)
  2491. " Test g CTRL-g in visual mode (CTRL-V) with end_vcol being MAXCOL
  2492. let a = execute(":norm! \<Esc>gojll\<C-V>k$g\<c-g>")
  2493. call assert_equal("\nSelected 2 of 2 Lines; 4 of 4 Words; 17 of 23 Bytes", a)
  2494. " There should be one byte less with noeol
  2495. set bin noeol
  2496. let a = execute(":norm! \<Esc>gog\<c-g>")
  2497. call assert_equal("\nCol 1 of 10; Line 1 of 2; Word 1 of 4; Char 1 of 23; Byte 1 of 22", a)
  2498. set bin & eol&
  2499. call setline(1, ['Français', '日本語'])
  2500. let a = execute(":norm! \<Esc>gojlg\<c-g>")
  2501. call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20", a)
  2502. let a = execute(":norm! \<Esc>gojvlg\<c-g>")
  2503. call assert_equal("\nSelected 1 of 2 Lines; 1 of 2 Words; 2 of 13 Chars; 6 of 20 Bytes", a)
  2504. let a = execute(":norm! \<Esc>goll\<c-v>jlg\<c-g>")
  2505. call assert_equal("\nSelected 4 Cols; 2 of 2 Lines; 2 of 2 Words; 6 of 13 Chars; 11 of 20 Bytes", a)
  2506. set fenc=utf8 bomb
  2507. let a = execute(":norm! \<Esc>gojlg\<c-g>")
  2508. call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+3 for BOM)", a)
  2509. set fenc=utf16 bomb
  2510. let a = execute(":norm! g\<c-g>")
  2511. call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+2 for BOM)", a)
  2512. set fenc=utf32 bomb
  2513. let a = execute(":norm! g\<c-g>")
  2514. call assert_equal("\nCol 4-3 of 9-6; Line 2 of 2; Word 2 of 2; Char 11 of 13; Byte 16 of 20(+4 for BOM)", a)
  2515. set fenc& bomb&
  2516. set ff&
  2517. bwipe!
  2518. endfunc
  2519. " Test for g8
  2520. func Test_normal34_g_cmd3()
  2521. new
  2522. let a=execute(':norm! 1G0g8')
  2523. call assert_equal("\nNUL", a)
  2524. call setline(1, 'abcdefghijklmnopqrstuvwxyzäüö')
  2525. let a=execute(':norm! 1G$g8')
  2526. call assert_equal("\nc3 b6 ", a)
  2527. call setline(1, "a\u0302")
  2528. let a=execute(':norm! 1G0g8')
  2529. call assert_equal("\n61 + cc 82 ", a)
  2530. " clean up
  2531. bw!
  2532. endfunc
  2533. " Test 8g8 which finds invalid utf8 at or after the cursor.
  2534. func Test_normal_8g8()
  2535. new
  2536. " With invalid byte.
  2537. call setline(1, "___\xff___")
  2538. norm! 1G08g8g
  2539. call assert_equal([0, 1, 4, 0, 1], getcurpos())
  2540. " With invalid byte before the cursor.
  2541. call setline(1, "___\xff___")
  2542. norm! 1G$h8g8g
  2543. call assert_equal([0, 1, 6, 0, 9], getcurpos())
  2544. " With truncated sequence.
  2545. call setline(1, "___\xE2\x82___")
  2546. norm! 1G08g8g
  2547. call assert_equal([0, 1, 4, 0, 1], getcurpos())
  2548. " With overlong sequence.
  2549. call setline(1, "___\xF0\x82\x82\xAC___")
  2550. norm! 1G08g8g
  2551. call assert_equal([0, 1, 4, 0, 1], getcurpos())
  2552. " With valid utf8.
  2553. call setline(1, "café")
  2554. norm! 1G08g8
  2555. call assert_equal([0, 1, 1, 0, 1], getcurpos())
  2556. bw!
  2557. endfunc
  2558. " Test for g<
  2559. func Test_normal35_g_cmd4()
  2560. " Cannot capture its output,
  2561. " probably a bug, therefore, test disabled:
  2562. throw "Skipped: output of g< can't be tested currently"
  2563. echo "a\nb\nc\nd"
  2564. let b=execute(':norm! g<')
  2565. call assert_true(!empty(b), 'failed `execute(g<)`')
  2566. endfunc
  2567. " Test for gp gP go
  2568. func Test_normal36_g_cmd5()
  2569. new
  2570. call append(0, 'abcdefghijklmnopqrstuvwxyz')
  2571. set ff=unix
  2572. " Test for gp gP
  2573. call append(1, range(1,10))
  2574. 1
  2575. norm! 1yy
  2576. 3
  2577. norm! gp
  2578. call assert_equal([0, 5, 1, 0, 1], getcurpos())
  2579. $
  2580. norm! gP
  2581. call assert_equal([0, 14, 1, 0, 1], getcurpos())
  2582. " Test for go
  2583. norm! 26go
  2584. call assert_equal([0, 1, 26, 0, 26], getcurpos())
  2585. norm! 27go
  2586. call assert_equal([0, 1, 26, 0, 26], getcurpos())
  2587. norm! 28go
  2588. call assert_equal([0, 2, 1, 0, 1], getcurpos())
  2589. set ff=dos
  2590. norm! 29go
  2591. call assert_equal([0, 2, 1, 0, 1], getcurpos())
  2592. set ff=unix
  2593. norm! gg0
  2594. norm! 101go
  2595. call assert_equal([0, 13, 26, 0, 26], getcurpos())
  2596. norm! 103go
  2597. call assert_equal([0, 14, 1, 0, 1], getcurpos())
  2598. " count > buffer content
  2599. norm! 120go
  2600. call assert_equal([0, 14, 1, 0, v:maxcol], getcurpos())
  2601. " clean up
  2602. bw!
  2603. endfunc
  2604. " Test for gt and gT
  2605. func Test_normal37_g_cmd6()
  2606. tabnew 1.txt
  2607. tabnew 2.txt
  2608. tabnew 3.txt
  2609. norm! 1gt
  2610. call assert_equal(1, tabpagenr())
  2611. norm! 3gt
  2612. call assert_equal(3, tabpagenr())
  2613. norm! 1gT
  2614. " count gT goes not to the absolute tabpagenumber
  2615. " but, but goes to the count previous tabpagenumber
  2616. call assert_equal(2, tabpagenr())
  2617. " wrap around
  2618. norm! 3gT
  2619. call assert_equal(3, tabpagenr())
  2620. " gt does not wrap around
  2621. norm! 5gt
  2622. call assert_equal(3, tabpagenr())
  2623. for i in range(3)
  2624. tabclose
  2625. endfor
  2626. " clean up
  2627. call assert_fails(':tabclose', 'E784:')
  2628. endfunc
  2629. " Test for <Home> and <C-Home> key
  2630. func Test_normal38_nvhome()
  2631. new
  2632. call setline(1, range(10))
  2633. $
  2634. setl et sw=2
  2635. norm! V10>$
  2636. " count is ignored
  2637. exe "norm! 10\<home>"
  2638. call assert_equal(1, col('.'))
  2639. exe "norm! \<home>"
  2640. call assert_equal([0, 10, 1, 0, 1], getcurpos())
  2641. exe "norm! 5\<c-home>"
  2642. call assert_equal([0, 5, 1, 0, 1], getcurpos())
  2643. exe "norm! \<c-home>"
  2644. call assert_equal([0, 1, 1, 0, 1], getcurpos())
  2645. exe "norm! G\<c-kHome>"
  2646. call assert_equal([0, 1, 1, 0, 1], getcurpos())
  2647. " clean up
  2648. bw!
  2649. endfunc
  2650. " Test for <End> and <C-End> keys
  2651. func Test_normal_nvend()
  2652. new
  2653. call setline(1, map(range(1, 10), '"line" .. v:val'))
  2654. exe "normal! \<End>"
  2655. call assert_equal(5, col('.'))
  2656. exe "normal! 4\<End>"
  2657. call assert_equal([4, 5], [line('.'), col('.')])
  2658. exe "normal! \<C-End>"
  2659. call assert_equal([10, 6], [line('.'), col('.')])
  2660. bwipe!
  2661. endfunc
  2662. " Test for cw cW ce
  2663. func Test_normal39_cw()
  2664. " Test for cw and cW on whitespace
  2665. new
  2666. set tw=0
  2667. call append(0, 'here are some words')
  2668. norm! 1gg0elcwZZZ
  2669. call assert_equal('hereZZZare some words', getline('.'))
  2670. norm! 1gg0elcWYYY
  2671. call assert_equal('hereZZZareYYYsome words', getline('.'))
  2672. norm! 2gg0cwfoo
  2673. call assert_equal('foo', getline('.'))
  2674. call setline(1, 'one; two')
  2675. call cursor(1, 1)
  2676. call feedkeys('cwvim', 'xt')
  2677. call assert_equal('vim; two', getline(1))
  2678. call feedkeys('0cWone', 'xt')
  2679. call assert_equal('one two', getline(1))
  2680. "When cursor is at the end of a word 'ce' will change until the end of the
  2681. "next word, but 'cw' will change only one character
  2682. call setline(1, 'one two')
  2683. call feedkeys('0ecwce', 'xt')
  2684. call assert_equal('once two', getline(1))
  2685. call setline(1, 'one two')
  2686. call feedkeys('0ecely', 'xt')
  2687. call assert_equal('only', getline(1))
  2688. " clean up
  2689. bw!
  2690. endfunc
  2691. " Test for CTRL-\ commands
  2692. func Test_normal40_ctrl_bsl()
  2693. new
  2694. call append(0, 'here are some words')
  2695. exe "norm! 1gg0a\<C-\>\<C-N>"
  2696. call assert_equal('n', mode())
  2697. call assert_equal(1, col('.'))
  2698. call assert_equal('', visualmode())
  2699. exe "norm! 1gg0viw\<C-\>\<C-N>"
  2700. call assert_equal('n', mode())
  2701. call assert_equal(4, col('.'))
  2702. exe "norm! 1gg0a\<C-\>\<C-G>"
  2703. call assert_equal('n', mode())
  2704. call assert_equal(1, col('.'))
  2705. "imap <buffer> , <c-\><c-n>
  2706. " set im
  2707. exe ":norm! \<c-\>\<c-n>dw"
  2708. " set noim
  2709. call assert_equal('are some words', getline(1))
  2710. call assert_false(&insertmode)
  2711. call assert_beeps("normal! \<C-\>\<C-A>")
  2712. " Using CTRL-\ CTRL-N in cmd window should close the window
  2713. call feedkeys("q:\<C-\>\<C-N>", 'xt')
  2714. call assert_equal('', getcmdwintype())
  2715. " clean up
  2716. bw!
  2717. endfunc
  2718. " Test for <c-r>=, <c-r><c-r>= and <c-r><c-o>= in insert mode
  2719. func Test_normal41_insert_reg()
  2720. new
  2721. set sts=2 sw=2 ts=8 tw=0
  2722. call append(0, ["aaa\tbbb\tccc", '', '', ''])
  2723. let a=getline(1)
  2724. norm! 2gg0
  2725. exe "norm! a\<c-r>=a\<cr>"
  2726. norm! 3gg0
  2727. exe "norm! a\<c-r>\<c-r>=a\<cr>"
  2728. norm! 4gg0
  2729. exe "norm! a\<c-r>\<c-o>=a\<cr>"
  2730. call assert_equal(['aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', ''], getline(1, '$'))
  2731. " clean up
  2732. set sts=0 sw=8 ts=8
  2733. bw!
  2734. endfunc
  2735. " Test for Ctrl-D and Ctrl-U
  2736. func Test_normal42_halfpage()
  2737. call Setup_NewWindow()
  2738. call assert_equal(5, &scroll)
  2739. exe "norm! \<c-d>"
  2740. call assert_equal('6', getline('.'))
  2741. exe "norm! 2\<c-d>"
  2742. call assert_equal('8', getline('.'))
  2743. call assert_equal(2, &scroll)
  2744. set scroll=5
  2745. exe "norm! \<c-u>"
  2746. call assert_equal('3', getline('.'))
  2747. 1
  2748. set scrolloff=5
  2749. exe "norm! \<c-d>"
  2750. call assert_equal('10', getline('.'))
  2751. exe "norm! \<c-u>"
  2752. call assert_equal('5', getline('.'))
  2753. 1
  2754. set scrolloff=99
  2755. exe "norm! \<c-d>"
  2756. call assert_equal('10', getline('.'))
  2757. set scrolloff=0
  2758. 100
  2759. exe "norm! $\<c-u>"
  2760. call assert_equal('95', getline('.'))
  2761. call assert_equal([0, 95, 1, 0, 1], getcurpos())
  2762. 100
  2763. set nostartofline
  2764. exe "norm! $\<c-u>"
  2765. call assert_equal('95', getline('.'))
  2766. call assert_equal([0, 95, 2, 0, v:maxcol], getcurpos())
  2767. " cleanup
  2768. set startofline
  2769. bw!
  2770. endfunc
  2771. func Test_normal45_drop()
  2772. if !has('dnd')
  2773. " The ~ register does not exist
  2774. call assert_beeps('norm! "~')
  2775. return
  2776. endif
  2777. " basic test for drag-n-drop
  2778. " unfortunately, without a gui, we can't really test much here,
  2779. " so simply test that ~p fails (which uses the drop register)
  2780. new
  2781. call assert_fails(':norm! "~p', 'E353')
  2782. call assert_equal([], getreg('~', 1, 1))
  2783. " the ~ register is read only
  2784. call assert_fails(':let @~="1"', 'E354')
  2785. bw!
  2786. endfunc
  2787. func Test_normal46_ignore()
  2788. new
  2789. " How to test this?
  2790. " let's just for now test, that the buffer
  2791. " does not change
  2792. call feedkeys("\<c-s>", 't')
  2793. call assert_equal([''], getline(1,'$'))
  2794. " no valid commands
  2795. exe "norm! \<char-0x100>"
  2796. call assert_equal([''], getline(1,'$'))
  2797. exe "norm! ä"
  2798. call assert_equal([''], getline(1,'$'))
  2799. " clean up
  2800. bw!
  2801. endfunc
  2802. func Test_normal47_visual_buf_wipe()
  2803. " This was causing a crash or ml_get error.
  2804. enew!
  2805. call setline(1,'xxx')
  2806. normal $
  2807. new
  2808. call setline(1, range(1,2))
  2809. 2
  2810. exe "norm \<C-V>$"
  2811. bw!
  2812. norm yp
  2813. set nomodified
  2814. endfunc
  2815. func Test_normal48_wincmd()
  2816. new
  2817. exe "norm! \<c-w>c"
  2818. call assert_equal(1, winnr('$'))
  2819. call assert_fails(":norm! \<c-w>c", "E444")
  2820. endfunc
  2821. func Test_normal49_counts()
  2822. new
  2823. call setline(1, 'one two three four five six seven eight nine ten')
  2824. 1
  2825. norm! 3d2w
  2826. call assert_equal('seven eight nine ten', getline(1))
  2827. bw!
  2828. endfunc
  2829. func Test_normal50_commandline()
  2830. CheckFeature timers
  2831. CheckFeature cmdline_hist
  2832. func! DoTimerWork(id)
  2833. call assert_equal(1, getbufinfo('')[0].command)
  2834. " should fail, with E11, but does fail with E23?
  2835. "call feedkeys("\<c-^>", 'tm')
  2836. " should fail with E11 - "Invalid in command-line window"
  2837. call assert_fails(":wincmd p", 'E11')
  2838. " Return from commandline window.
  2839. call feedkeys("\<CR>", 't')
  2840. endfunc
  2841. let oldlang=v:lang
  2842. lang C
  2843. set updatetime=20
  2844. call timer_start(100, 'DoTimerWork')
  2845. try
  2846. " throws E23, for whatever reason...
  2847. call feedkeys('q:', 'x!')
  2848. catch /E23/
  2849. " no-op
  2850. endtry
  2851. " clean up
  2852. delfunc DoTimerWork
  2853. set updatetime=4000
  2854. exe "lang" oldlang
  2855. bw!
  2856. endfunc
  2857. func Test_normal51_FileChangedRO()
  2858. CheckFeature autocmd
  2859. call writefile(['foo'], 'Xreadonly.log')
  2860. new Xreadonly.log
  2861. setl ro
  2862. au FileChangedRO <buffer> :call feedkeys("\<c-^>", 'tix')
  2863. call assert_fails(":norm! Af", 'E788')
  2864. call assert_equal(['foo'], getline(1,'$'))
  2865. call assert_equal('Xreadonly.log', bufname(''))
  2866. " cleanup
  2867. bw!
  2868. call delete("Xreadonly.log")
  2869. endfunc
  2870. func Test_normal52_rl()
  2871. CheckFeature rightleft
  2872. new
  2873. call setline(1, 'abcde fghij klmnopq')
  2874. norm! 1gg$
  2875. set rl
  2876. call assert_equal(19, col('.'))
  2877. call feedkeys('l', 'tx')
  2878. call assert_equal(18, col('.'))
  2879. call feedkeys('h', 'tx')
  2880. call assert_equal(19, col('.'))
  2881. call feedkeys("\<right>", 'tx')
  2882. call assert_equal(18, col('.'))
  2883. call feedkeys("\<left>", 'tx')
  2884. call assert_equal(19, col('.'))
  2885. call feedkeys("\<s-right>", 'tx')
  2886. call assert_equal(13, col('.'))
  2887. call feedkeys("\<c-right>", 'tx')
  2888. call assert_equal(7, col('.'))
  2889. call feedkeys("\<c-left>", 'tx')
  2890. call assert_equal(13, col('.'))
  2891. call feedkeys("\<s-left>", 'tx')
  2892. call assert_equal(19, col('.'))
  2893. call feedkeys("<<", 'tx')
  2894. call assert_equal(' abcde fghij klmnopq',getline(1))
  2895. call feedkeys(">>", 'tx')
  2896. call assert_equal('abcde fghij klmnopq',getline(1))
  2897. " cleanup
  2898. set norl
  2899. bw!
  2900. endfunc
  2901. func Test_normal54_Ctrl_bsl()
  2902. new
  2903. call setline(1, 'abcdefghijklmn')
  2904. exe "norm! df\<c-\>\<c-n>"
  2905. call assert_equal(['abcdefghijklmn'], getline(1,'$'))
  2906. exe "norm! df\<c-\>\<c-g>"
  2907. call assert_equal(['abcdefghijklmn'], getline(1,'$'))
  2908. exe "norm! df\<c-\>m"
  2909. call assert_equal(['abcdefghijklmn'], getline(1,'$'))
  2910. call setline(2, 'abcdefghijklmnāf')
  2911. norm! 2gg0
  2912. exe "norm! df\<Char-0x101>"
  2913. call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$'))
  2914. norm! 1gg0
  2915. exe "norm! df\<esc>"
  2916. call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$'))
  2917. " clean up
  2918. bw!
  2919. endfunc
  2920. func Test_normal_large_count()
  2921. " This may fail with 32bit long, how do we detect that?
  2922. new
  2923. normal o
  2924. normal 6666666666dL
  2925. bwipe!
  2926. endfunc
  2927. func Test_delete_until_paragraph()
  2928. new
  2929. normal grádv}
  2930. call assert_equal('á', getline(1))
  2931. normal grád}
  2932. call assert_equal('', getline(1))
  2933. bwipe!
  2934. endfunc
  2935. " Test for the gr (virtual replace) command
  2936. func Test_gr_command()
  2937. enew!
  2938. " Test for the bug fixed by 7.4.387
  2939. let save_cpo = &cpo
  2940. call append(0, ['First line', 'Second line', 'Third line'])
  2941. exe "normal i\<C-G>u"
  2942. call cursor(2, 1)
  2943. set cpo-=X
  2944. normal 4gro
  2945. call assert_equal('oooond line', getline(2))
  2946. undo
  2947. set cpo+=X
  2948. normal 4gro
  2949. call assert_equal('ooooecond line', getline(2))
  2950. let &cpo = save_cpo
  2951. normal! ggvegrx
  2952. call assert_equal('xxxxx line', getline(1))
  2953. exe "normal! gggr\<C-V>122"
  2954. call assert_equal('zxxxx line', getline(1))
  2955. set virtualedit=all
  2956. normal! 15|grl
  2957. call assert_equal('zxxxx line l', getline(1))
  2958. set virtualedit&
  2959. set nomodifiable
  2960. call assert_fails('normal! grx', 'E21:')
  2961. call assert_fails('normal! gRx', 'E21:')
  2962. call assert_nobeep("normal! gr\<Esc>")
  2963. set modifiable&
  2964. call assert_nobeep("normal! gr\<Esc>")
  2965. call assert_nobeep("normal! cgr\<Esc>")
  2966. call assert_beeps("normal! cgrx")
  2967. call assert_equal('zxxxx line l', getline(1))
  2968. exe "normal! 2|gr\<C-V>\<Esc>"
  2969. call assert_equal("z\<Esc>xx line l", getline(1))
  2970. call setline(1, 'abcdef')
  2971. exe "normal! 0gr\<C-O>lx"
  2972. call assert_equal("\<C-O>def", getline(1))
  2973. call setline(1, 'abcdef')
  2974. exe "normal! 0gr\<C-G>lx"
  2975. call assert_equal("\<C-G>def", getline(1))
  2976. bwipe!
  2977. endfunc
  2978. func Test_nv_hat_count()
  2979. %bwipeout!
  2980. let l:nr = bufnr('%') + 1
  2981. call assert_fails(':execute "normal! ' . l:nr . '\<C-^>"', 'E92:')
  2982. edit Xfoo
  2983. let l:foo_nr = bufnr('Xfoo')
  2984. edit Xbar
  2985. let l:bar_nr = bufnr('Xbar')
  2986. " Make sure we are not just using the alternate file.
  2987. edit Xbaz
  2988. call feedkeys(l:foo_nr . "\<C-^>", 'tx')
  2989. call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
  2990. call feedkeys(l:bar_nr . "\<C-^>", 'tx')
  2991. call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
  2992. %bwipeout!
  2993. endfunc
  2994. func Test_message_when_using_ctrl_c()
  2995. " Make sure no buffers are changed.
  2996. %bwipe!
  2997. exe "normal \<C-C>"
  2998. call assert_match("Type :qa and press <Enter> to exit Nvim", Screenline(&lines))
  2999. new
  3000. cal setline(1, 'hi!')
  3001. exe "normal \<C-C>"
  3002. call assert_match("Type :qa! and press <Enter> to abandon all changes and exit Nvim", Screenline(&lines))
  3003. bwipe!
  3004. endfunc
  3005. func Test_mode_updated_after_ctrl_c()
  3006. CheckScreendump
  3007. let buf = RunVimInTerminal('', {'rows': 5})
  3008. call term_sendkeys(buf, "i")
  3009. call term_sendkeys(buf, "\<C-O>")
  3010. " wait a moment so that the "-- (insert) --" message is displayed
  3011. call TermWait(buf, 50)
  3012. call term_sendkeys(buf, "\<C-C>")
  3013. call VerifyScreenDump(buf, 'Test_mode_updated_1', {})
  3014. call StopVimInTerminal(buf)
  3015. endfunc
  3016. " Test for '[m', ']m', '[M' and ']M'
  3017. " Jumping to beginning and end of methods in Java-like languages
  3018. func Test_java_motion()
  3019. new
  3020. call assert_beeps('normal! [m')
  3021. call assert_beeps('normal! ]m')
  3022. call assert_beeps('normal! [M')
  3023. call assert_beeps('normal! ]M')
  3024. let lines =<< trim [CODE]
  3025. Piece of Java
  3026. {
  3027. tt m1 {
  3028. t1;
  3029. } e1
  3030. tt m2 {
  3031. t2;
  3032. } e2
  3033. tt m3 {
  3034. if (x)
  3035. {
  3036. t3;
  3037. }
  3038. } e3
  3039. }
  3040. [CODE]
  3041. call setline(1, lines)
  3042. normal gg
  3043. normal 2]maA
  3044. call assert_equal("\ttt m1 {A", getline('.'))
  3045. call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')])
  3046. normal j]maB
  3047. call assert_equal("\ttt m2 {B", getline('.'))
  3048. call assert_equal([7, 9, 16], [line('.'), col('.'), virtcol('.')])
  3049. normal ]maC
  3050. call assert_equal("\ttt m3 {C", getline('.'))
  3051. call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')])
  3052. normal [maD
  3053. call assert_equal("\ttt m3 {DC", getline('.'))
  3054. call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')])
  3055. normal k2[maE
  3056. call assert_equal("\ttt m1 {EA", getline('.'))
  3057. call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')])
  3058. normal 3[maF
  3059. call assert_equal("{F", getline('.'))
  3060. call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')])
  3061. normal ]MaG
  3062. call assert_equal("\t}G e1", getline('.'))
  3063. call assert_equal([5, 3, 10], [line('.'), col('.'), virtcol('.')])
  3064. normal j2]MaH
  3065. call assert_equal("\t}H e3", getline('.'))
  3066. call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')])
  3067. normal ]M]M
  3068. normal aI
  3069. call assert_equal("}I", getline('.'))
  3070. call assert_equal([17, 2, 2], [line('.'), col('.'), virtcol('.')])
  3071. normal 2[MaJ
  3072. call assert_equal("\t}JH e3", getline('.'))
  3073. call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')])
  3074. normal k[MaK
  3075. call assert_equal("\t}K e2", getline('.'))
  3076. call assert_equal([9, 3, 10], [line('.'), col('.'), virtcol('.')])
  3077. normal 3[MaL
  3078. call assert_equal("{LF", getline('.'))
  3079. call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')])
  3080. call cursor(2, 1)
  3081. call assert_beeps('norm! 5]m')
  3082. " jumping to a method in a fold should open the fold
  3083. 6,10fold
  3084. call feedkeys("gg3]m", 'xt')
  3085. call assert_equal([7, 8, 15], [line('.'), col('.'), virtcol('.')])
  3086. call assert_equal(-1, foldclosedend(7))
  3087. bwipe!
  3088. endfunc
  3089. " Tests for g cmds
  3090. func Test_normal_gdollar_cmd()
  3091. call Setup_NewWindow()
  3092. " Make long lines that will wrap
  3093. %s/$/\=repeat(' foobar', 10)/
  3094. 20vsp
  3095. set wrap
  3096. " Test for g$ with count
  3097. norm! gg
  3098. norm! 0vg$y
  3099. call assert_equal(20, col("'>"))
  3100. call assert_equal('1 foobar foobar foob', getreg(0))
  3101. norm! gg
  3102. norm! 0v4g$y
  3103. call assert_equal(72, col("'>"))
  3104. call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.."\n", getreg(0))
  3105. norm! gg
  3106. norm! 0v6g$y
  3107. call assert_equal(40, col("'>"))
  3108. call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
  3109. \ '2 foobar foobar foobar foobar foobar foo', getreg(0))
  3110. set nowrap
  3111. " clean up
  3112. norm! gg
  3113. norm! 0vg$y
  3114. call assert_equal(20, col("'>"))
  3115. call assert_equal('1 foobar foobar foob', getreg(0))
  3116. norm! gg
  3117. norm! 0v4g$y
  3118. call assert_equal(20, col("'>"))
  3119. call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
  3120. \ '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
  3121. \ '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
  3122. \ '4 foobar foobar foob', getreg(0))
  3123. norm! gg
  3124. norm! 0v6g$y
  3125. call assert_equal(20, col("'>"))
  3126. call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
  3127. \ '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
  3128. \ '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
  3129. \ '4 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
  3130. \ '5 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
  3131. \ '6 foobar foobar foob', getreg(0))
  3132. " Move to last line, also down movement is not possible, should still move
  3133. " the cursor to the last visible char
  3134. norm! G
  3135. norm! 0v6g$y
  3136. call assert_equal(20, col("'>"))
  3137. call assert_equal('100 foobar foobar fo', getreg(0))
  3138. bw!
  3139. endfunc
  3140. func Test_normal_gk_gj()
  3141. " needs 80 column new window
  3142. new
  3143. vert 80new
  3144. call assert_beeps('normal gk')
  3145. put =[repeat('x',90)..' {{{1', 'x {{{1']
  3146. norm! gk
  3147. " In a 80 column wide terminal the window will be only 78 char
  3148. " (because Vim will leave space for the other window),
  3149. " but if the terminal is larger, it will be 80 chars, so verify the
  3150. " cursor column correctly.
  3151. call assert_equal(winwidth(0)+1, col('.'))
  3152. call assert_equal(winwidth(0)+1, virtcol('.'))
  3153. norm! j
  3154. call assert_equal(6, col('.'))
  3155. call assert_equal(6, virtcol('.'))
  3156. norm! gk
  3157. call assert_equal(95, col('.'))
  3158. call assert_equal(95, virtcol('.'))
  3159. %bw!
  3160. " needs 80 column new window
  3161. new
  3162. vert 80new
  3163. call assert_beeps('normal gj')
  3164. set number
  3165. set numberwidth=10
  3166. set cpoptions+=n
  3167. put =[repeat('0',90), repeat('1',90)]
  3168. norm! 075l
  3169. call assert_equal(76, col('.'))
  3170. norm! gk
  3171. call assert_equal(1, col('.'))
  3172. norm! gk
  3173. call assert_equal(76, col('.'))
  3174. norm! gk
  3175. call assert_equal(1, col('.'))
  3176. norm! gj
  3177. call assert_equal(76, col('.'))
  3178. norm! gj
  3179. call assert_equal(1, col('.'))
  3180. norm! gj
  3181. call assert_equal(76, col('.'))
  3182. " When 'nowrap' is set, gk and gj behave like k and j
  3183. set nowrap
  3184. normal! gk
  3185. call assert_equal([2, 76], [line('.'), col('.')])
  3186. normal! gj
  3187. call assert_equal([3, 76], [line('.'), col('.')])
  3188. %bw!
  3189. set cpoptions& number& numberwidth& wrap&
  3190. endfunc
  3191. " Test for using : to run a multi-line Ex command in operator pending mode
  3192. func Test_normal_yank_with_excmd()
  3193. new
  3194. call setline(1, ['foo', 'bar', 'baz'])
  3195. let @a = ''
  3196. call feedkeys("\"ay:if v:true\<CR>normal l\<CR>endif\<CR>", 'xt')
  3197. call assert_equal('f', @a)
  3198. bwipe!
  3199. endfunc
  3200. " Test for supplying a count to a normal-mode command across a cursorhold call
  3201. func Test_normal_cursorhold_with_count()
  3202. throw 'Skipped: Nvim removed <CursorHold> key'
  3203. func s:cHold()
  3204. let g:cHold_Called += 1
  3205. endfunc
  3206. new
  3207. augroup normalcHoldTest
  3208. au!
  3209. au CursorHold <buffer> call s:cHold()
  3210. augroup END
  3211. let g:cHold_Called = 0
  3212. call feedkeys("3\<CursorHold>2ix", 'xt')
  3213. call assert_equal(1, g:cHold_Called)
  3214. call assert_equal(repeat('x', 32), getline(1))
  3215. augroup normalcHoldTest
  3216. au!
  3217. augroup END
  3218. au! normalcHoldTest
  3219. bwipe!
  3220. delfunc s:cHold
  3221. endfunc
  3222. " Test for using a count and a command with CTRL-W
  3223. func Test_wincmd_with_count()
  3224. call feedkeys("\<C-W>12n", 'xt')
  3225. call assert_equal(12, winheight(0))
  3226. endfunc
  3227. " Test for 'b', 'B' 'ge' and 'gE' commands
  3228. func Test_horiz_motion()
  3229. new
  3230. normal! gg
  3231. call assert_beeps('normal! b')
  3232. call assert_beeps('normal! B')
  3233. call assert_beeps('normal! gE')
  3234. call assert_beeps('normal! ge')
  3235. " <S-Backspace> moves one word left and <C-Backspace> moves one WORD left
  3236. call setline(1, 'one ,two ,three')
  3237. exe "normal! $\<S-BS>"
  3238. call assert_equal(11, col('.'))
  3239. exe "normal! $\<C-BS>"
  3240. call assert_equal(10, col('.'))
  3241. bwipe!
  3242. endfunc
  3243. " Test for using a ":" command in operator pending mode
  3244. func Test_normal_colon_op()
  3245. new
  3246. call setline(1, ['one', 'two'])
  3247. call assert_beeps("normal! Gc:d\<CR>")
  3248. call assert_equal(['one'], getline(1, '$'))
  3249. call setline(1, ['one…two…three!'])
  3250. normal! $
  3251. " Using ":" as a movement is characterwise exclusive
  3252. call feedkeys("d:normal! F…\<CR>", 'xt')
  3253. call assert_equal(['one…two!'], getline(1, '$'))
  3254. " Check that redoing a command with 0x80 bytes works
  3255. call feedkeys('.', 'xt')
  3256. call assert_equal(['one!'], getline(1, '$'))
  3257. call setline(1, ['one', 'two', 'three', 'four', 'five'])
  3258. " Add this to the command history
  3259. call feedkeys(":normal! G0\<CR>", 'xt')
  3260. " Use :normal! with control characters in operator pending mode
  3261. call feedkeys("d:normal! \<C-V>\<C-P>\<C-V>\<C-P>\<CR>", 'xt')
  3262. call assert_equal(['one', 'two', 'five'], getline(1, '$'))
  3263. " Check that redoing a command with control characters works
  3264. call feedkeys('.', 'xt')
  3265. call assert_equal(['five'], getline(1, '$'))
  3266. bwipe!
  3267. endfunc
  3268. " Test for d and D commands
  3269. func Test_normal_delete_cmd()
  3270. new
  3271. " D in an empty line
  3272. call setline(1, '')
  3273. normal D
  3274. call assert_equal('', getline(1))
  3275. " D in an empty line in virtualedit mode
  3276. set virtualedit=all
  3277. normal D
  3278. call assert_equal('', getline(1))
  3279. set virtualedit&
  3280. " delete to a readonly register
  3281. call setline(1, ['abcd'])
  3282. call assert_beeps('normal ":d2l')
  3283. " D and d with 'nomodifiable'
  3284. call setline(1, ['abcd'])
  3285. setlocal nomodifiable
  3286. call assert_fails('normal D', 'E21:')
  3287. call assert_fails('normal d$', 'E21:')
  3288. bwipe!
  3289. endfunc
  3290. " Test for deleting or changing characters across lines with 'whichwrap'
  3291. " containing 's'. Should count <EOL> as one character.
  3292. func Test_normal_op_across_lines()
  3293. new
  3294. set whichwrap&
  3295. call setline(1, ['one two', 'three four'])
  3296. exe "norm! $3d\<Space>"
  3297. call assert_equal(['one twhree four'], getline(1, '$'))
  3298. call setline(1, ['one two', 'three four'])
  3299. exe "norm! $3c\<Space>x"
  3300. call assert_equal(['one twxhree four'], getline(1, '$'))
  3301. set whichwrap+=l
  3302. call setline(1, ['one two', 'three four'])
  3303. exe "norm! $3x"
  3304. call assert_equal(['one twhree four'], getline(1, '$'))
  3305. bwipe!
  3306. set whichwrap&
  3307. endfunc
  3308. " Test for 'w' and 'b' commands
  3309. func Test_normal_word_move()
  3310. new
  3311. call setline(1, ['foo bar a', '', 'foo bar b'])
  3312. " copy a single character word at the end of a line
  3313. normal 1G$yw
  3314. call assert_equal('a', @")
  3315. " copy a single character word at the end of a file
  3316. normal G$yw
  3317. call assert_equal('b', @")
  3318. " check for a word movement handling an empty line properly
  3319. normal 1G$vwy
  3320. call assert_equal("a\n\n", @")
  3321. " copy using 'b' command
  3322. %d
  3323. " non-empty blank line at the start of file
  3324. call setline(1, [' ', 'foo bar'])
  3325. normal 2Gyb
  3326. call assert_equal(" \n", @")
  3327. " try to copy backwards from the start of the file
  3328. call setline(1, ['one two', 'foo bar'])
  3329. call assert_beeps('normal ggyb')
  3330. " 'b' command should stop at an empty line
  3331. call setline(1, ['one two', '', 'foo bar'])
  3332. normal 3Gyb
  3333. call assert_equal("\n", @")
  3334. normal 3Gy2b
  3335. call assert_equal("two\n", @")
  3336. " 'b' command should not stop at a non-empty blank line
  3337. call setline(1, ['one two', ' ', 'foo bar'])
  3338. normal 3Gyb
  3339. call assert_equal("two\n ", @")
  3340. bwipe!
  3341. endfunc
  3342. " Test for 'scrolloff' with a long line that doesn't fit in the screen
  3343. func Test_normal_scrolloff()
  3344. 10new
  3345. 60vnew
  3346. call setline(1, ' 1 ' .. repeat('a', 57)
  3347. \ .. ' 2 ' .. repeat('b', 57)
  3348. \ .. ' 3 ' .. repeat('c', 57)
  3349. \ .. ' 4 ' .. repeat('d', 57)
  3350. \ .. ' 5 ' .. repeat('e', 57)
  3351. \ .. ' 6 ' .. repeat('f', 57)
  3352. \ .. ' 7 ' .. repeat('g', 57)
  3353. \ .. ' 8 ' .. repeat('h', 57)
  3354. \ .. ' 9 ' .. repeat('i', 57)
  3355. \ .. '10 ' .. repeat('j', 57)
  3356. \ .. '11 ' .. repeat('k', 57)
  3357. \ .. '12 ' .. repeat('l', 57)
  3358. \ .. '13 ' .. repeat('m', 57)
  3359. \ .. '14 ' .. repeat('n', 57)
  3360. \ .. '15 ' .. repeat('o', 57)
  3361. \ .. '16 ' .. repeat('p', 57)
  3362. \ .. '17 ' .. repeat('q', 57)
  3363. \ .. '18 ' .. repeat('r', 57)
  3364. \ .. '19 ' .. repeat('s', 57)
  3365. \ .. '20 ' .. repeat('t', 57)
  3366. \ .. '21 ' .. repeat('u', 57)
  3367. \ .. '22 ' .. repeat('v', 57)
  3368. \ .. '23 ' .. repeat('w', 57)
  3369. \ .. '24 ' .. repeat('x', 57)
  3370. \ .. '25 ' .. repeat('y', 57)
  3371. \ .. '26 ' .. repeat('z', 57)
  3372. \ )
  3373. set scrolloff=10
  3374. normal gg10gj
  3375. call assert_equal(6, winline())
  3376. normal 10gj
  3377. call assert_equal(6, winline())
  3378. normal 10gk
  3379. call assert_equal(6, winline())
  3380. normal 0
  3381. call assert_equal(1, winline())
  3382. normal $
  3383. call assert_equal(10, winline())
  3384. set scrolloff&
  3385. bwipe!
  3386. endfunc
  3387. " Test for vertical scrolling with CTRL-F and CTRL-B with a long line
  3388. func Test_normal_vert_scroll_longline()
  3389. 10new
  3390. 80vnew
  3391. call setline(1, range(1, 10))
  3392. call append(5, repeat('a', 1000))
  3393. exe "normal gg\<C-F>"
  3394. call assert_equal(6, line('.'))
  3395. exe "normal \<C-F>\<C-F>"
  3396. call assert_equal(11, line('.'))
  3397. call assert_equal(1, winline())
  3398. exe "normal \<C-B>"
  3399. call assert_equal(11, line('.'))
  3400. call assert_equal(5, winline())
  3401. exe "normal \<C-B>\<C-B>"
  3402. call assert_equal(5, line('.'))
  3403. call assert_equal(5, winline())
  3404. bwipe!
  3405. endfunc
  3406. " Test for jumping in a file using %
  3407. func Test_normal_percent_jump()
  3408. new
  3409. call setline(1, range(1, 100))
  3410. " jumping to a folded line should open the fold
  3411. 25,75fold
  3412. call feedkeys('50%', 'xt')
  3413. call assert_equal(50, line('.'))
  3414. call assert_equal(-1, foldclosedend(50))
  3415. bwipe!
  3416. endfunc
  3417. " Test for << and >> commands to shift text by 'shiftwidth'
  3418. func Test_normal_shift_rightleft()
  3419. new
  3420. call setline(1, ['one', '', "\t", ' two', "\tthree", ' four'])
  3421. set shiftwidth=2 tabstop=8
  3422. normal gg6>>
  3423. call assert_equal([' one', '', "\t ", ' two', "\t three", "\tfour"],
  3424. \ getline(1, '$'))
  3425. normal ggVG2>>
  3426. call assert_equal([' one', '', "\t ", "\ttwo",
  3427. \ "\t three", "\t four"], getline(1, '$'))
  3428. normal gg6<<
  3429. call assert_equal([' one', '', "\t ", ' two', "\t three",
  3430. \ "\t four"], getline(1, '$'))
  3431. normal ggVG2<<
  3432. call assert_equal(['one', '', "\t", ' two', "\tthree", ' four'],
  3433. \ getline(1, '$'))
  3434. set shiftwidth& tabstop&
  3435. bw!
  3436. endfunc
  3437. " Some commands like yy, cc, dd, >>, << and !! accept a count after
  3438. " typing the first letter of the command.
  3439. func Test_normal_count_after_operator()
  3440. new
  3441. setlocal shiftwidth=4 tabstop=8 autoindent
  3442. call setline(1, ['one', 'two', 'three', 'four', 'five'])
  3443. let @a = ''
  3444. normal! j"ay4y
  3445. call assert_equal("two\nthree\nfour\nfive\n", @a)
  3446. normal! 3G>2>
  3447. call assert_equal(['one', 'two', ' three', ' four', 'five'],
  3448. \ getline(1, '$'))
  3449. exe "normal! 3G0c2cred\nblue"
  3450. call assert_equal(['one', 'two', ' red', ' blue', 'five'],
  3451. \ getline(1, '$'))
  3452. exe "normal! gg<8<"
  3453. call assert_equal(['one', 'two', 'red', 'blue', 'five'],
  3454. \ getline(1, '$'))
  3455. exe "normal! ggd3d"
  3456. call assert_equal(['blue', 'five'], getline(1, '$'))
  3457. call setline(1, range(1, 4))
  3458. call feedkeys("gg!3!\<C-B>\"\<CR>", 'xt')
  3459. call assert_equal('".,.+2!', @:)
  3460. call feedkeys("gg!1!\<C-B>\"\<CR>", 'xt')
  3461. call assert_equal('".!', @:)
  3462. call feedkeys("gg!9!\<C-B>\"\<CR>", 'xt')
  3463. call assert_equal('".,$!', @:)
  3464. bw!
  3465. endfunc
  3466. func Test_normal_gj_on_6_cell_wide_unprintable_char()
  3467. new | 25vsp
  3468. let text='1 foooooooo ar e ins​zwe1 foooooooo ins​zwei' .
  3469. \ ' i drei vier fünf sechs sieben acht un zehn elf zwöfl' .
  3470. \ ' dreizehn v ierzehn fünfzehn'
  3471. put =text
  3472. call cursor(2,1)
  3473. norm! gj
  3474. call assert_equal([0,2,25,0], getpos('.'))
  3475. bw!
  3476. endfunc
  3477. func Test_normal_count_out_of_range()
  3478. new
  3479. call setline(1, 'text')
  3480. normal 44444444444|
  3481. call assert_equal(999999999, v:count)
  3482. normal 444444444444|
  3483. call assert_equal(999999999, v:count)
  3484. normal 4444444444444|
  3485. call assert_equal(999999999, v:count)
  3486. normal 4444444444444444444|
  3487. call assert_equal(999999999, v:count)
  3488. normal 9y99999999|
  3489. call assert_equal(899999991, v:count)
  3490. normal 10y99999999|
  3491. call assert_equal(999999999, v:count)
  3492. normal 44444444444y44444444444|
  3493. call assert_equal(999999999, v:count)
  3494. bwipe!
  3495. endfunc
  3496. " Test that mouse shape is restored to Normal mode after failed "c" operation.
  3497. func Test_mouse_shape_after_failed_change()
  3498. CheckFeature mouseshape
  3499. CheckCanRunGui
  3500. let lines =<< trim END
  3501. vim9script
  3502. set mouseshape+=o:busy
  3503. setlocal nomodifiable
  3504. var mouse_shapes = []
  3505. feedkeys('c')
  3506. timer_start(50, (_) => {
  3507. mouse_shapes += [getmouseshape()]
  3508. timer_start(50, (_) => {
  3509. feedkeys('c')
  3510. timer_start(50, (_) => {
  3511. mouse_shapes += [getmouseshape()]
  3512. timer_start(50, (_) => {
  3513. writefile(mouse_shapes, 'Xmouseshapes')
  3514. quit
  3515. })
  3516. })
  3517. })
  3518. })
  3519. END
  3520. call writefile(lines, 'Xmouseshape.vim', 'D')
  3521. call RunVim([], [], "-g -S Xmouseshape.vim")
  3522. call WaitForAssert({-> assert_equal(['busy', 'arrow'], readfile('Xmouseshapes'))}, 300)
  3523. call delete('Xmouseshapes')
  3524. endfunc
  3525. " Test that mouse shape is restored to Normal mode after cancelling "gr".
  3526. func Test_mouse_shape_after_cancelling_gr()
  3527. CheckFeature mouseshape
  3528. CheckCanRunGui
  3529. let lines =<< trim END
  3530. vim9script
  3531. var mouse_shapes = []
  3532. feedkeys('gr')
  3533. timer_start(50, (_) => {
  3534. mouse_shapes += [getmouseshape()]
  3535. timer_start(50, (_) => {
  3536. feedkeys("\<Esc>")
  3537. timer_start(50, (_) => {
  3538. mouse_shapes += [getmouseshape()]
  3539. timer_start(50, (_) => {
  3540. writefile(mouse_shapes, 'Xmouseshapes')
  3541. quit
  3542. })
  3543. })
  3544. })
  3545. })
  3546. END
  3547. call writefile(lines, 'Xmouseshape.vim', 'D')
  3548. call RunVim([], [], "-g -S Xmouseshape.vim")
  3549. call WaitForAssert({-> assert_equal(['beam', 'arrow'], readfile('Xmouseshapes'))}, 300)
  3550. call delete('Xmouseshapes')
  3551. endfunc
  3552. " Test that "j" does not skip lines when scrolling below botline and
  3553. " 'foldmethod' is not "manual".
  3554. func Test_normal_j_below_botline()
  3555. CheckScreendump
  3556. let lines =<< trim END
  3557. set number foldmethod=diff scrolloff=0
  3558. call setline(1, map(range(1, 9), 'repeat(v:val, 200)'))
  3559. norm Lj
  3560. END
  3561. call writefile(lines, 'XNormalJBelowBotline', 'D')
  3562. let buf = RunVimInTerminal('-S XNormalJBelowBotline', #{rows: 19, cols: 40})
  3563. call VerifyScreenDump(buf, 'Test_normal_j_below_botline', {})
  3564. call StopVimInTerminal(buf)
  3565. endfunc
  3566. " Test for r (replace) command with CTRL_V and CTRL_Q
  3567. func Test_normal_r_ctrl_v_cmd()
  3568. new
  3569. call append(0, 'This is a simple test: abcd')
  3570. exe "norm! 1gg$r\<C-V>\<C-V>"
  3571. call assert_equal(['This is a simple test: abc', ''], getline(1,'$'))
  3572. exe "norm! 1gg$hr\<C-Q>\<C-Q>"
  3573. call assert_equal(['This is a simple test: ab', ''], getline(1,'$'))
  3574. exe "norm! 1gg$2hr\<C-V>x7e"
  3575. call assert_equal(['This is a simple test: a~', ''], getline(1,'$'))
  3576. exe "norm! 1gg$3hr\<C-Q>x7e"
  3577. call assert_equal(['This is a simple test: ~~', ''], getline(1,'$'))
  3578. if &encoding == 'utf-8'
  3579. exe "norm! 1gg$4hr\<C-V>u20ac"
  3580. call assert_equal(['This is a simple test:€~~', ''], getline(1,'$'))
  3581. exe "norm! 1gg$5hr\<C-Q>u20ac"
  3582. call assert_equal(['This is a simple test€€~~', ''], getline(1,'$'))
  3583. exe "norm! 1gg0R\<C-V>xff WAS \<esc>"
  3584. call assert_equal(['ÿ WAS a simple test€€~~', ''], getline(1,'$'))
  3585. exe "norm! 1gg0elR\<C-Q>xffNOT\<esc>"
  3586. call assert_equal(['ÿ WASÿNOT simple test€€~~', ''], getline(1,'$'))
  3587. endif
  3588. call setline(1, 'This is a simple test: abcd')
  3589. exe "norm! 1gg$gr\<C-V>\<C-V>"
  3590. call assert_equal(['This is a simple test: abc', ''], getline(1,'$'))
  3591. exe "norm! 1gg$hgr\<C-Q>\<C-Q>"
  3592. call assert_equal(['This is a simple test: ab ', ''], getline(1,'$'))
  3593. exe "norm! 1gg$2hgr\<C-V>x7e"
  3594. call assert_equal(['This is a simple test: a~ ', ''], getline(1,'$'))
  3595. exe "norm! 1gg$3hgr\<C-Q>x7e"
  3596. call assert_equal(['This is a simple test: ~~ ', ''], getline(1,'$'))
  3597. " clean up
  3598. bw!
  3599. endfunc
  3600. " Test clicking on a TAB or an unprintable character in Normal mode
  3601. func Test_normal_click_on_ctrl_char()
  3602. let save_mouse = &mouse
  3603. set mouse=a
  3604. new
  3605. call setline(1, "a\<Tab>b\<C-K>c")
  3606. redraw
  3607. call Ntest_setmouse(1, 1)
  3608. call feedkeys("\<LeftMouse>", 'xt')
  3609. call assert_equal([0, 1, 1, 0, 1], getcurpos())
  3610. call Ntest_setmouse(1, 2)
  3611. call feedkeys("\<LeftMouse>", 'xt')
  3612. call assert_equal([0, 1, 2, 0, 2], getcurpos())
  3613. call Ntest_setmouse(1, 3)
  3614. call feedkeys("\<LeftMouse>", 'xt')
  3615. call assert_equal([0, 1, 2, 0, 3], getcurpos())
  3616. call Ntest_setmouse(1, 7)
  3617. call feedkeys("\<LeftMouse>", 'xt')
  3618. call assert_equal([0, 1, 2, 0, 7], getcurpos())
  3619. call Ntest_setmouse(1, 8)
  3620. call feedkeys("\<LeftMouse>", 'xt')
  3621. call assert_equal([0, 1, 2, 0, 8], getcurpos())
  3622. call Ntest_setmouse(1, 9)
  3623. call feedkeys("\<LeftMouse>", 'xt')
  3624. call assert_equal([0, 1, 3, 0, 9], getcurpos())
  3625. call Ntest_setmouse(1, 10)
  3626. call feedkeys("\<LeftMouse>", 'xt')
  3627. call assert_equal([0, 1, 4, 0, 10], getcurpos())
  3628. call Ntest_setmouse(1, 11)
  3629. call feedkeys("\<LeftMouse>", 'xt')
  3630. call assert_equal([0, 1, 4, 0, 11], getcurpos())
  3631. call Ntest_setmouse(1, 12)
  3632. call feedkeys("\<LeftMouse>", 'xt')
  3633. call assert_equal([0, 1, 5, 0, 12], getcurpos())
  3634. call Ntest_setmouse(1, 13)
  3635. call feedkeys("\<LeftMouse>", 'xt')
  3636. call assert_equal([0, 1, 5, 0, 13], getcurpos())
  3637. bwipe!
  3638. let &mouse = save_mouse
  3639. endfunc
  3640. " Test clicking on a double-width character in Normal mode
  3641. func Test_normal_click_on_double_width_char()
  3642. let save_mouse = &mouse
  3643. set mouse=a
  3644. new
  3645. call setline(1, "口口")
  3646. redraw
  3647. call Ntest_setmouse(1, 1)
  3648. call feedkeys("\<LeftMouse>", 'xt')
  3649. call assert_equal([0, 1, 1, 0, 1], getcurpos())
  3650. call Ntest_setmouse(1, 2)
  3651. call feedkeys("\<LeftMouse>", 'xt')
  3652. call assert_equal([0, 1, 1, 0, 2], getcurpos())
  3653. call Ntest_setmouse(1, 3)
  3654. call feedkeys("\<LeftMouse>", 'xt')
  3655. call assert_equal([0, 1, 4, 0, 3], getcurpos())
  3656. call Ntest_setmouse(1, 4)
  3657. call feedkeys("\<LeftMouse>", 'xt')
  3658. call assert_equal([0, 1, 4, 0, 4], getcurpos())
  3659. bwipe!
  3660. let &mouse = save_mouse
  3661. endfunc
  3662. func Test_normal_click_on_empty_line()
  3663. let save_mouse = &mouse
  3664. set mouse=a
  3665. botright new
  3666. call setline(1, ['', '', ''])
  3667. let row = win_screenpos(0)[0] + 2
  3668. 20vsplit
  3669. redraw
  3670. call Ntest_setmouse(row, 1)
  3671. call feedkeys("\<LeftMouse>", 'xt')
  3672. call assert_equal([0, 3, 1, 0, 1], getcurpos())
  3673. call Ntest_setmouse(row, 2)
  3674. call feedkeys("\<LeftMouse>", 'xt')
  3675. call assert_equal([0, 3, 1, 0, 2], getcurpos())
  3676. call Ntest_setmouse(row, 10)
  3677. call feedkeys("\<LeftMouse>", 'xt')
  3678. call assert_equal([0, 3, 1, 0, 10], getcurpos())
  3679. call Ntest_setmouse(row, 21 + 1)
  3680. call feedkeys("\<LeftMouse>", 'xt')
  3681. call assert_equal([0, 3, 1, 0, 1], getcurpos())
  3682. call Ntest_setmouse(row, 21 + 2)
  3683. call feedkeys("\<LeftMouse>", 'xt')
  3684. call assert_equal([0, 3, 1, 0, 2], getcurpos())
  3685. call Ntest_setmouse(row, 21 + 10)
  3686. call feedkeys("\<LeftMouse>", 'xt')
  3687. call assert_equal([0, 3, 1, 0, 10], getcurpos())
  3688. bwipe!
  3689. let &mouse = save_mouse
  3690. endfunc
  3691. func Test_normal33_g_cmd_nonblank()
  3692. " Test that g<End> goes to the last non-blank char and g$ to the last
  3693. " visible column
  3694. 20vnew
  3695. setlocal nowrap nonumber signcolumn=no
  3696. call setline(1, ['fooo fooo fooo fooo fooo fooo fooo fooo '])
  3697. exe "normal 0g\<End>"
  3698. call assert_equal(11, col('.'))
  3699. normal 0g$
  3700. call assert_equal(20, col('.'))
  3701. exe "normal 0g\<kEnd>"
  3702. call assert_equal(11, col('.'))
  3703. setlocal wrap
  3704. exe "normal 0g\<End>"
  3705. call assert_equal(11, col('.'))
  3706. normal 0g$
  3707. call assert_equal(20, col('.'))
  3708. exe "normal 0g\<kEnd>"
  3709. call assert_equal(11, col('.'))
  3710. bw!
  3711. endfunc
  3712. func Test_normal34_zet_large()
  3713. " shouldn't cause overflow
  3714. norm! z9765405999999999999
  3715. endfunc
  3716. " Test for { and } paragraph movements in a single line
  3717. func Test_brace_single_line()
  3718. new
  3719. call setline(1, ['foobar one two three'])
  3720. 1
  3721. norm! 0}
  3722. call assert_equal([0, 1, 20, 0], getpos('.'))
  3723. norm! {
  3724. call assert_equal([0, 1, 1, 0], getpos('.'))
  3725. bw!
  3726. endfunc
  3727. " Test for Ctrl-B/Ctrl-U in buffer with a single line
  3728. func Test_single_line_scroll()
  3729. CheckFeature textprop
  3730. new
  3731. call setline(1, ['foobar one two three'])
  3732. let vt = 'virt_above'
  3733. call prop_type_add(vt, {'highlight': 'IncSearch'})
  3734. call prop_add(1, 0, {'type': vt, 'text': '---', 'text_align': 'above'})
  3735. call cursor(1, 1)
  3736. " Ctrl-B/Ctrl-U scroll up with hidden "above" virtual text.
  3737. set smoothscroll
  3738. exe "normal \<C-E>"
  3739. call assert_notequal(0, winsaveview().skipcol)
  3740. exe "normal \<C-B>"
  3741. call assert_equal(0, winsaveview().skipcol)
  3742. exe "normal \<C-E>"
  3743. call assert_notequal(0, winsaveview().skipcol)
  3744. exe "normal \<C-U>"
  3745. call assert_equal(0, winsaveview().skipcol)
  3746. set smoothscroll&
  3747. bw!
  3748. call prop_type_delete(vt)
  3749. endfunc
  3750. " Test for zb in buffer with a single line and filler lines
  3751. func Test_single_line_filler_zb()
  3752. call setline(1, ['', 'foobar one two three'])
  3753. diffthis
  3754. new
  3755. call setline(1, ['foobar one two three'])
  3756. diffthis
  3757. " zb scrolls to reveal filler lines at the start of the buffer.
  3758. exe "normal \<C-E>zb"
  3759. call assert_equal(1, winsaveview().topfill)
  3760. bw!
  3761. endfunc
  3762. " Test for Ctrl-U not getting stuck at end of buffer with 'scrolloff'.
  3763. func Test_halfpage_scrolloff_eob()
  3764. set scrolloff=5
  3765. call setline(1, range(1, 100))
  3766. exe "norm! Gzz\<C-U>zz"
  3767. call assert_notequal(100, line('.'))
  3768. set scrolloff&
  3769. bwipe!
  3770. endfunc
  3771. " Test for Ctrl-U/D moving the cursor at the buffer boundaries.
  3772. func Test_halfpage_cursor_startend()
  3773. call setline(1, range(1, 100))
  3774. exe "norm! jztj\<C-U>"
  3775. call assert_equal(1, line('.'))
  3776. exe "norm! G\<C-Y>k\<C-D>"
  3777. call assert_equal(100, line('.'))
  3778. bwipe!
  3779. endfunc
  3780. " Test for Ctrl-F/B moving the cursor to the window boundaries.
  3781. func Test_page_cursor_topbot()
  3782. 10new
  3783. call setline(1, range(1, 100))
  3784. exe "norm! gg2\<C-F>"
  3785. call assert_equal(17, line('.'))
  3786. exe "norm! \<C-B>"
  3787. call assert_equal(18, line('.'))
  3788. exe "norm! \<C-B>\<C-F>"
  3789. call assert_equal(9, line('.'))
  3790. " Not when already at the start of the buffer.
  3791. exe "norm! ggj\<C-B>"
  3792. call assert_equal(2, line('.'))
  3793. bwipe!
  3794. endfunc
  3795. " Test for Ctrl-D with long line
  3796. func Test_halfpage_longline()
  3797. 10new
  3798. 40vsplit
  3799. call setline(1, ['long'->repeat(1000), 'short'])
  3800. exe "norm! \<C-D>"
  3801. call assert_equal(2, line('.'))
  3802. bwipe!
  3803. endfunc
  3804. " Test for Ctrl-E with long line and very narrow window,
  3805. " used to cause an infinite loop
  3806. func Test_scroll_longline_no_loop()
  3807. 4vnew
  3808. setl smoothscroll number showbreak=> scrolloff=2
  3809. call setline(1, repeat(['Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'], 3))
  3810. exe "normal! \<C-E>"
  3811. bwipe!
  3812. endfunc
  3813. " Test for go command
  3814. func Test_normal_go()
  3815. new
  3816. call setline(1, ['one two three four'])
  3817. call cursor(1, 5)
  3818. norm! dvgo
  3819. call assert_equal('wo three four', getline(1))
  3820. norm! ...
  3821. call assert_equal('three four', getline(1))
  3822. bwipe!
  3823. endfunc
  3824. " vim: shiftwidth=2 sts=2 expandtab nofoldenable