test_normal.vim 113 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324
  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', 'D')
  1210. call assert_equal(1, RunVim([], [], '--clean -X -Z -e -s -S Xscript'))
  1211. call assert_equal(['done'], readfile('Xdone'))
  1212. call delete('Xdone')
  1213. endfunc
  1214. func Test_scroll_and_paste_in_ex_mode()
  1215. throw 'Skipped: does not work when Nvim is run from :!'
  1216. " This used to crash because of moving cursor to line 0.
  1217. let lines =<< trim END
  1218. v/foo/vi|YY9PYQ
  1219. v/bar/vi|YY9PYQ
  1220. v/bar/exe line('.') == 1 ? "vi|Y\<C-B>9PYQ" : "vi|YQ"
  1221. call writefile(['done'], 'Xdone')
  1222. qa!
  1223. END
  1224. call writefile(lines, 'Xscript', 'D')
  1225. call assert_equal(1, RunVim([], [], '-u NONE -i NONE -n -X -Z -e -s -S Xscript'))
  1226. call assert_equal(['done'], readfile('Xdone'))
  1227. call delete('Xdone')
  1228. endfunc
  1229. " Test for the 'sidescroll' option
  1230. func Test_sidescroll_opt()
  1231. new
  1232. 20vnew
  1233. " scroll by 2 characters horizontally
  1234. set sidescroll=2 nowrap
  1235. call setline(1, repeat('a', 40))
  1236. normal g$l
  1237. call assert_equal(19, screenpos(0, 1, 21).col)
  1238. normal l
  1239. call assert_equal(20, screenpos(0, 1, 22).col)
  1240. normal g0h
  1241. call assert_equal(2, screenpos(0, 1, 2).col)
  1242. call assert_equal(20, screenpos(0, 1, 20).col)
  1243. " when 'sidescroll' is 0, cursor positioned at the center
  1244. set sidescroll=0
  1245. normal g$l
  1246. call assert_equal(11, screenpos(0, 1, 21).col)
  1247. normal g0h
  1248. call assert_equal(10, screenpos(0, 1, 10).col)
  1249. %bw!
  1250. set wrap& sidescroll&
  1251. endfunc
  1252. " basic tests for foldopen/folddelete
  1253. func Test_normal18_z_fold()
  1254. CheckFeature folding
  1255. call Setup_NewWindow()
  1256. 50
  1257. setl foldenable fdm=marker foldlevel=5
  1258. call assert_beeps('normal! zj')
  1259. call assert_beeps('normal! zk')
  1260. " Test for zF
  1261. " First fold
  1262. norm! 4zF
  1263. " check that folds have been created
  1264. call assert_equal(['50/* {{{ */', '51', '52', '53/* }}} */'], getline(50,53))
  1265. " Test for zd
  1266. 51
  1267. norm! 2zF
  1268. call assert_equal(2, foldlevel('.'))
  1269. norm! kzd
  1270. call assert_equal(['50', '51/* {{{ */', '52/* }}} */', '53'], getline(50,53))
  1271. norm! j
  1272. call assert_equal(1, foldlevel('.'))
  1273. " Test for zD
  1274. " also deletes partially selected folds recursively
  1275. 51
  1276. norm! zF
  1277. call assert_equal(2, foldlevel('.'))
  1278. norm! kV2jzD
  1279. call assert_equal(['50', '51', '52', '53'], getline(50,53))
  1280. " Test for zE
  1281. 85
  1282. norm! 4zF
  1283. 86
  1284. norm! 2zF
  1285. 90
  1286. norm! 4zF
  1287. call assert_equal(['85/* {{{ */', '86/* {{{ */', '87/* }}} */', '88/* }}} */', '89', '90/* {{{ */', '91', '92', '93/* }}} */'], getline(85,93))
  1288. norm! zE
  1289. call assert_equal(['85', '86', '87', '88', '89', '90', '91', '92', '93'], getline(85,93))
  1290. " Test for zn
  1291. 50
  1292. set foldlevel=0
  1293. norm! 2zF
  1294. norm! zn
  1295. norm! k
  1296. call assert_equal('49', getline('.'))
  1297. norm! j
  1298. call assert_equal('50/* {{{ */', getline('.'))
  1299. norm! j
  1300. call assert_equal('51/* }}} */', getline('.'))
  1301. norm! j
  1302. call assert_equal('52', getline('.'))
  1303. call assert_equal(0, &foldenable)
  1304. " Test for zN
  1305. 49
  1306. norm! zN
  1307. call assert_equal('49', getline('.'))
  1308. norm! j
  1309. call assert_equal('50/* {{{ */', getline('.'))
  1310. norm! j
  1311. call assert_equal('52', getline('.'))
  1312. call assert_equal(1, &foldenable)
  1313. " Test for zi
  1314. norm! zi
  1315. call assert_equal(0, &foldenable)
  1316. norm! zi
  1317. call assert_equal(1, &foldenable)
  1318. norm! zi
  1319. call assert_equal(0, &foldenable)
  1320. norm! zi
  1321. call assert_equal(1, &foldenable)
  1322. " Test for za
  1323. 50
  1324. norm! za
  1325. norm! k
  1326. call assert_equal('49', getline('.'))
  1327. norm! j
  1328. call assert_equal('50/* {{{ */', getline('.'))
  1329. norm! j
  1330. call assert_equal('51/* }}} */', getline('.'))
  1331. norm! j
  1332. call assert_equal('52', getline('.'))
  1333. 50
  1334. norm! za
  1335. norm! k
  1336. call assert_equal('49', getline('.'))
  1337. norm! j
  1338. call assert_equal('50/* {{{ */', getline('.'))
  1339. norm! j
  1340. call assert_equal('52', getline('.'))
  1341. 49
  1342. norm! 5zF
  1343. norm! k
  1344. call assert_equal('48', getline('.'))
  1345. norm! j
  1346. call assert_equal('49/* {{{ */', getline('.'))
  1347. norm! j
  1348. call assert_equal('55', getline('.'))
  1349. 49
  1350. norm! za
  1351. call assert_equal('49/* {{{ */', getline('.'))
  1352. norm! j
  1353. call assert_equal('50/* {{{ */', getline('.'))
  1354. norm! j
  1355. call assert_equal('52', getline('.'))
  1356. set nofoldenable
  1357. " close fold and set foldenable
  1358. norm! za
  1359. call assert_equal(1, &foldenable)
  1360. 50
  1361. " have to use {count}za to open all folds and make the cursor visible
  1362. norm! 2za
  1363. norm! 2k
  1364. call assert_equal('48', getline('.'))
  1365. norm! j
  1366. call assert_equal('49/* {{{ */', getline('.'))
  1367. norm! j
  1368. call assert_equal('50/* {{{ */', getline('.'))
  1369. norm! j
  1370. call assert_equal('51/* }}} */', getline('.'))
  1371. norm! j
  1372. call assert_equal('52', getline('.'))
  1373. " Test for zA
  1374. 49
  1375. set foldlevel=0
  1376. 50
  1377. norm! zA
  1378. norm! 2k
  1379. call assert_equal('48', getline('.'))
  1380. norm! j
  1381. call assert_equal('49/* {{{ */', getline('.'))
  1382. norm! j
  1383. call assert_equal('50/* {{{ */', getline('.'))
  1384. norm! j
  1385. call assert_equal('51/* }}} */', getline('.'))
  1386. norm! j
  1387. call assert_equal('52', getline('.'))
  1388. " zA on an opened fold when foldenable is not set
  1389. 50
  1390. set nofoldenable
  1391. norm! zA
  1392. call assert_equal(1, &foldenable)
  1393. norm! k
  1394. call assert_equal('48', getline('.'))
  1395. norm! j
  1396. call assert_equal('49/* {{{ */', getline('.'))
  1397. norm! j
  1398. call assert_equal('55', getline('.'))
  1399. " Test for zc
  1400. norm! zE
  1401. 50
  1402. norm! 2zF
  1403. 49
  1404. norm! 5zF
  1405. set nofoldenable
  1406. 50
  1407. " There most likely is a bug somewhere:
  1408. " https://groups.google.com/d/msg/vim_dev/v2EkfJ_KQjI/u-Cvv94uCAAJ
  1409. " TODO: Should this only close the inner most fold or both folds?
  1410. norm! zc
  1411. call assert_equal(1, &foldenable)
  1412. norm! k
  1413. call assert_equal('48', getline('.'))
  1414. norm! j
  1415. call assert_equal('49/* {{{ */', getline('.'))
  1416. norm! j
  1417. call assert_equal('55', getline('.'))
  1418. set nofoldenable
  1419. 50
  1420. norm! Vjzc
  1421. norm! k
  1422. call assert_equal('48', getline('.'))
  1423. norm! j
  1424. call assert_equal('49/* {{{ */', getline('.'))
  1425. norm! j
  1426. call assert_equal('55', getline('.'))
  1427. " Test for zC
  1428. set nofoldenable
  1429. 50
  1430. norm! zCk
  1431. call assert_equal('48', getline('.'))
  1432. norm! j
  1433. call assert_equal('49/* {{{ */', getline('.'))
  1434. norm! j
  1435. call assert_equal('55', getline('.'))
  1436. " Test for zx
  1437. " 1) close folds at line 49-54
  1438. set nofoldenable
  1439. 48
  1440. norm! zx
  1441. call assert_equal(1, &foldenable)
  1442. norm! j
  1443. call assert_equal('49/* {{{ */', getline('.'))
  1444. norm! j
  1445. call assert_equal('55', getline('.'))
  1446. " 2) do not close fold under cursor
  1447. 51
  1448. set nofoldenable
  1449. norm! zx
  1450. call assert_equal(1, &foldenable)
  1451. norm! 3k
  1452. call assert_equal('48', getline('.'))
  1453. norm! j
  1454. call assert_equal('49/* {{{ */', getline('.'))
  1455. norm! j
  1456. call assert_equal('50/* {{{ */', getline('.'))
  1457. norm! j
  1458. call assert_equal('51/* }}} */', getline('.'))
  1459. norm! j
  1460. call assert_equal('52', getline('.'))
  1461. norm! j
  1462. call assert_equal('53', getline('.'))
  1463. norm! j
  1464. call assert_equal('54/* }}} */', getline('.'))
  1465. norm! j
  1466. call assert_equal('55', getline('.'))
  1467. " 3) close one level of folds
  1468. 48
  1469. set nofoldenable
  1470. set foldlevel=1
  1471. norm! zx
  1472. call assert_equal(1, &foldenable)
  1473. call assert_equal('48', getline('.'))
  1474. norm! j
  1475. call assert_equal('49/* {{{ */', getline('.'))
  1476. norm! j
  1477. call assert_equal('50/* {{{ */', getline('.'))
  1478. norm! j
  1479. call assert_equal('52', getline('.'))
  1480. norm! j
  1481. call assert_equal('53', getline('.'))
  1482. norm! j
  1483. call assert_equal('54/* }}} */', getline('.'))
  1484. norm! j
  1485. call assert_equal('55', getline('.'))
  1486. " Test for zX
  1487. " Close all folds
  1488. set foldlevel=0 nofoldenable
  1489. 50
  1490. norm! zX
  1491. call assert_equal(1, &foldenable)
  1492. norm! k
  1493. call assert_equal('48', getline('.'))
  1494. norm! j
  1495. call assert_equal('49/* {{{ */', getline('.'))
  1496. norm! j
  1497. call assert_equal('55', getline('.'))
  1498. " Test for zm
  1499. 50
  1500. set nofoldenable foldlevel=2
  1501. norm! zm
  1502. call assert_equal(1, &foldenable)
  1503. call assert_equal(1, &foldlevel)
  1504. norm! zm
  1505. call assert_equal(0, &foldlevel)
  1506. norm! zm
  1507. call assert_equal(0, &foldlevel)
  1508. norm! k
  1509. call assert_equal('48', getline('.'))
  1510. norm! j
  1511. call assert_equal('49/* {{{ */', getline('.'))
  1512. norm! j
  1513. call assert_equal('55', getline('.'))
  1514. " Test for zm with a count
  1515. 50
  1516. set foldlevel=2
  1517. norm! 3zm
  1518. call assert_equal(0, &foldlevel)
  1519. call assert_equal(49, foldclosed(line('.')))
  1520. " Test for zM
  1521. 48
  1522. set nofoldenable foldlevel=99
  1523. norm! zM
  1524. call assert_equal(1, &foldenable)
  1525. call assert_equal(0, &foldlevel)
  1526. call assert_equal('48', getline('.'))
  1527. norm! j
  1528. call assert_equal('49/* {{{ */', getline('.'))
  1529. norm! j
  1530. call assert_equal('55', getline('.'))
  1531. " Test for zr
  1532. 48
  1533. set nofoldenable foldlevel=0
  1534. norm! zr
  1535. call assert_equal(0, &foldenable)
  1536. call assert_equal(1, &foldlevel)
  1537. set foldlevel=0 foldenable
  1538. norm! zr
  1539. call assert_equal(1, &foldenable)
  1540. call assert_equal(1, &foldlevel)
  1541. norm! zr
  1542. call assert_equal(2, &foldlevel)
  1543. call assert_equal('48', getline('.'))
  1544. norm! j
  1545. call assert_equal('49/* {{{ */', getline('.'))
  1546. norm! j
  1547. call assert_equal('50/* {{{ */', getline('.'))
  1548. norm! j
  1549. call assert_equal('51/* }}} */', getline('.'))
  1550. norm! j
  1551. call assert_equal('52', getline('.'))
  1552. " Test for zR
  1553. 48
  1554. set nofoldenable foldlevel=0
  1555. norm! zR
  1556. call assert_equal(0, &foldenable)
  1557. call assert_equal(2, &foldlevel)
  1558. set foldenable foldlevel=0
  1559. norm! zR
  1560. call assert_equal(1, &foldenable)
  1561. call assert_equal(2, &foldlevel)
  1562. call assert_equal('48', getline('.'))
  1563. norm! j
  1564. call assert_equal('49/* {{{ */', getline('.'))
  1565. norm! j
  1566. call assert_equal('50/* {{{ */', getline('.'))
  1567. norm! j
  1568. call assert_equal('51/* }}} */', getline('.'))
  1569. norm! j
  1570. call assert_equal('52', getline('.'))
  1571. call append(50, ['a /* {{{ */', 'b /* }}} */'])
  1572. 48
  1573. call assert_equal('48', getline('.'))
  1574. norm! j
  1575. call assert_equal('49/* {{{ */', getline('.'))
  1576. norm! j
  1577. call assert_equal('50/* {{{ */', getline('.'))
  1578. norm! j
  1579. call assert_equal('a /* {{{ */', getline('.'))
  1580. norm! j
  1581. call assert_equal('51/* }}} */', getline('.'))
  1582. norm! j
  1583. call assert_equal('52', getline('.'))
  1584. 48
  1585. norm! zR
  1586. call assert_equal(1, &foldenable)
  1587. call assert_equal(3, &foldlevel)
  1588. call assert_equal('48', getline('.'))
  1589. norm! j
  1590. call assert_equal('49/* {{{ */', getline('.'))
  1591. norm! j
  1592. call assert_equal('50/* {{{ */', getline('.'))
  1593. norm! j
  1594. call assert_equal('a /* {{{ */', getline('.'))
  1595. norm! j
  1596. call assert_equal('b /* }}} */', getline('.'))
  1597. norm! j
  1598. call assert_equal('51/* }}} */', getline('.'))
  1599. norm! j
  1600. call assert_equal('52', getline('.'))
  1601. " clean up
  1602. setl nofoldenable fdm=marker foldlevel=0
  1603. bw!
  1604. endfunc
  1605. func Test_normal20_exmode()
  1606. " Reading from redirected file doesn't work on MS-Windows
  1607. CheckNotMSWindows
  1608. call writefile(['1a', 'foo', 'bar', '.', 'w! Xfile2', 'q!'], 'Xscript')
  1609. call writefile(['1', '2'], 'Xfile')
  1610. call system(GetVimCommand() .. ' -e -s < Xscript Xfile')
  1611. let a=readfile('Xfile2')
  1612. call assert_equal(['1', 'foo', 'bar', '2'], a)
  1613. " clean up
  1614. for file in ['Xfile', 'Xfile2', 'Xscript']
  1615. call delete(file)
  1616. endfor
  1617. bw!
  1618. endfunc
  1619. func Test_normal21_nv_hat()
  1620. " Edit a fresh file and wipe the buffer list so that there is no alternate
  1621. " file present. Next, check for the expected command failures.
  1622. edit Xfoo | %bw
  1623. call assert_fails(':buffer #', 'E86')
  1624. call assert_fails(':execute "normal! \<C-^>"', 'E23')
  1625. call assert_fails("normal i\<C-R>#", 'E23:')
  1626. " Test for the expected behavior when switching between two named buffers.
  1627. edit Xfoo | edit Xbar
  1628. call feedkeys("\<C-^>", 'tx')
  1629. call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
  1630. call feedkeys("\<C-^>", 'tx')
  1631. call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
  1632. " Test for the expected behavior when only one buffer is named.
  1633. enew | let l:nr = bufnr('%')
  1634. call feedkeys("\<C-^>", 'tx')
  1635. call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
  1636. call feedkeys("\<C-^>", 'tx')
  1637. call assert_equal('', bufname('%'))
  1638. call assert_equal(l:nr, bufnr('%'))
  1639. " Test that no action is taken by "<C-^>" when an operator is pending.
  1640. edit Xfoo
  1641. call feedkeys("ci\<C-^>", 'tx')
  1642. call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
  1643. %bw!
  1644. endfunc
  1645. func Test_normal22_zet()
  1646. " Test for ZZ
  1647. " let shell = &shell
  1648. " let &shell = 'sh'
  1649. call writefile(['1', '2'], 'Xn22file', 'D')
  1650. let args = ' -N -i NONE --noplugins -X --headless'
  1651. call system(GetVimCommand() .. args .. ' -c "%d" -c ":norm! ZZ" Xn22file')
  1652. let a = readfile('Xn22file')
  1653. call assert_equal([], a)
  1654. " Test for ZQ
  1655. call writefile(['1', '2'], 'Xn22file')
  1656. call system(GetVimCommand() . args . ' -c "%d" -c ":norm! ZQ" Xn22file')
  1657. let a = readfile('Xn22file')
  1658. call assert_equal(['1', '2'], a)
  1659. " Unsupported Z command
  1660. call assert_beeps('normal! ZW')
  1661. " clean up
  1662. " let &shell = shell
  1663. endfunc
  1664. func Test_normal23_K()
  1665. " Test for K command
  1666. new
  1667. call append(0, ['helphelp.txt', 'man', 'aa%bb', 'cc|dd'])
  1668. let k = &keywordprg
  1669. set keywordprg=:help
  1670. 1
  1671. norm! VK
  1672. call assert_equal('helphelp.txt', fnamemodify(bufname('%'), ':t'))
  1673. call assert_equal('help', &ft)
  1674. call assert_match('\*helphelp.txt\*', getline('.'))
  1675. helpclose
  1676. norm! 0K
  1677. call assert_equal('helphelp.txt', fnamemodify(bufname('%'), ':t'))
  1678. call assert_equal('help', &ft)
  1679. call assert_match('Help on help files', getline('.'))
  1680. helpclose
  1681. set keywordprg=:new
  1682. set iskeyword+=%
  1683. set iskeyword+=\|
  1684. 2
  1685. norm! K
  1686. call assert_equal('man', fnamemodify(bufname('%'), ':t'))
  1687. bwipe!
  1688. 3
  1689. norm! K
  1690. call assert_equal('aa%bb', fnamemodify(bufname('%'), ':t'))
  1691. bwipe!
  1692. if !has('win32')
  1693. 4
  1694. norm! K
  1695. call assert_equal('cc|dd', fnamemodify(bufname('%'), ':t'))
  1696. bwipe!
  1697. endif
  1698. set iskeyword-=%
  1699. set iskeyword-=\|
  1700. " Currently doesn't work in Nvim, see #19436
  1701. " Test for specifying a count to K
  1702. " 1
  1703. " com! -nargs=* Kprog let g:Kprog_Args = <q-args>
  1704. " set keywordprg=:Kprog
  1705. " norm! 3K
  1706. " call assert_equal('3 version8', g:Kprog_Args)
  1707. " delcom Kprog
  1708. " Only expect "man" to work on Unix
  1709. if !has("unix") || has('nvim') " Nvim K uses :terminal. #15398
  1710. let &keywordprg = k
  1711. bw!
  1712. return
  1713. endif
  1714. let not_gnu_man = has('mac') || has('bsd')
  1715. if not_gnu_man
  1716. " In macOS and BSD, the option for specifying a pager is different
  1717. set keywordprg=man\ -P\ cat
  1718. else
  1719. set keywordprg=man\ --pager=cat
  1720. endif
  1721. " Test for using man
  1722. 2
  1723. let a = execute('unsilent norm! K')
  1724. if not_gnu_man
  1725. call assert_match("man -P cat 'man'", a)
  1726. else
  1727. call assert_match("man --pager=cat 'man'", a)
  1728. endif
  1729. " Error cases
  1730. call setline(1, '#$#')
  1731. call assert_fails('normal! ggK', 'E349:')
  1732. call setline(1, '---')
  1733. call assert_fails('normal! ggv2lK', 'E349:')
  1734. call setline(1, ['abc', 'xyz'])
  1735. call assert_fails("normal! gg2lv2h\<C-]>", 'E433:')
  1736. call assert_beeps("normal! ggVjK")
  1737. " clean up
  1738. let &keywordprg = k
  1739. bw!
  1740. endfunc
  1741. func Test_normal24_rot13()
  1742. " Testing for g?? g?g?
  1743. new
  1744. call append(0, 'abcdefghijklmnopqrstuvwxyzäüö')
  1745. 1
  1746. norm! g??
  1747. call assert_equal('nopqrstuvwxyzabcdefghijklmäüö', getline('.'))
  1748. norm! g?g?
  1749. call assert_equal('abcdefghijklmnopqrstuvwxyzäüö', getline('.'))
  1750. " clean up
  1751. bw!
  1752. endfunc
  1753. func Test_normal25_tag()
  1754. CheckFeature quickfix
  1755. " Testing for CTRL-] g CTRL-] g]
  1756. " CTRL-W g] CTRL-W CTRL-] CTRL-W g CTRL-]
  1757. h
  1758. " Test for CTRL-]
  1759. call search('\<x\>$')
  1760. exe "norm! \<c-]>"
  1761. call assert_equal("change.txt", fnamemodify(bufname('%'), ':t'))
  1762. norm! yiW
  1763. call assert_equal("*x*", @0)
  1764. exe ":norm \<c-o>"
  1765. " Test for g_CTRL-]
  1766. call search('\<v_u\>$')
  1767. exe "norm! g\<c-]>"
  1768. call assert_equal("change.txt", fnamemodify(bufname('%'), ':t'))
  1769. norm! yiW
  1770. call assert_equal("*v_u*", @0)
  1771. exe ":norm \<c-o>"
  1772. " Test for g]
  1773. call search('\<i_<Esc>$')
  1774. let a = execute(":norm! g]")
  1775. call assert_match('i_<Esc>.*insert.txt', a)
  1776. if !empty(exepath('cscope')) && has('cscope')
  1777. " setting cscopetag changes how g] works
  1778. set cst
  1779. exe "norm! g]"
  1780. call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
  1781. norm! yiW
  1782. call assert_equal("*i_<Esc>*", @0)
  1783. exe ":norm \<c-o>"
  1784. " Test for CTRL-W g]
  1785. exe "norm! \<C-W>g]"
  1786. call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
  1787. norm! yiW
  1788. call assert_equal("*i_<Esc>*", @0)
  1789. call assert_equal(3, winnr('$'))
  1790. helpclose
  1791. set nocst
  1792. endif
  1793. " Test for CTRL-W g]
  1794. let a = execute("norm! \<C-W>g]")
  1795. call assert_match('i_<Esc>.*insert.txt', a)
  1796. " Test for CTRL-W CTRL-]
  1797. exe "norm! \<C-W>\<C-]>"
  1798. call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
  1799. norm! yiW
  1800. call assert_equal("*i_<Esc>*", @0)
  1801. call assert_equal(3, winnr('$'))
  1802. helpclose
  1803. " Test for CTRL-W g CTRL-]
  1804. exe "norm! \<C-W>g\<C-]>"
  1805. call assert_equal("insert.txt", fnamemodify(bufname('%'), ':t'))
  1806. norm! yiW
  1807. call assert_equal("*i_<Esc>*", @0)
  1808. call assert_equal(3, winnr('$'))
  1809. helpclose
  1810. " clean up
  1811. helpclose
  1812. endfunc
  1813. func Test_normal26_put()
  1814. " Test for ]p ]P [p and [P
  1815. new
  1816. call append(0, ['while read LINE', 'do', ' ((count++))', ' if [ $? -ne 0 ]; then', " echo 'Error writing file'", ' fi', 'done'])
  1817. 1
  1818. /Error/y a
  1819. 2
  1820. norm! "a]pj"a[p
  1821. call assert_equal(['do', "echo 'Error writing file'", " echo 'Error writing file'", ' ((count++))'], getline(2,5))
  1822. 1
  1823. /^\s\{4}/
  1824. exe "norm! \"a]P3Eldt'"
  1825. exe "norm! j\"a[P2Eldt'"
  1826. call assert_equal([' if [ $? -ne 0 ]; then', " echo 'Error writing'", " echo 'Error'", " echo 'Error writing file'", ' fi'], getline(6,10))
  1827. " clean up
  1828. bw!
  1829. endfunc
  1830. func Test_normal27_bracket()
  1831. " Test for [' [` ]' ]`
  1832. call Setup_NewWindow()
  1833. 1,21s/.\+/ & b/
  1834. 1
  1835. norm! $ma
  1836. 5
  1837. norm! $mb
  1838. 10
  1839. norm! $mc
  1840. 15
  1841. norm! $md
  1842. 20
  1843. norm! $me
  1844. " Test for ['
  1845. 9
  1846. norm! 2['
  1847. call assert_equal(' 1 b', getline('.'))
  1848. call assert_equal(1, line('.'))
  1849. call assert_equal(3, col('.'))
  1850. " Test for ]'
  1851. norm! ]'
  1852. call assert_equal(' 5 b', getline('.'))
  1853. call assert_equal(5, line('.'))
  1854. call assert_equal(3, col('.'))
  1855. " No mark before line 1, cursor moves to first non-blank on current line
  1856. 1
  1857. norm! 5|['
  1858. call assert_equal(' 1 b', getline('.'))
  1859. call assert_equal(1, line('.'))
  1860. call assert_equal(3, col('.'))
  1861. " No mark after line 21, cursor moves to first non-blank on current line
  1862. 21
  1863. norm! 5|]'
  1864. call assert_equal(' 21 b', getline('.'))
  1865. call assert_equal(21, line('.'))
  1866. call assert_equal(3, col('.'))
  1867. " Test for [`
  1868. norm! 2[`
  1869. call assert_equal(' 15 b', getline('.'))
  1870. call assert_equal(15, line('.'))
  1871. call assert_equal(8, col('.'))
  1872. " Test for ]`
  1873. norm! ]`
  1874. call assert_equal(' 20 b', getline('.'))
  1875. call assert_equal(20, line('.'))
  1876. call assert_equal(8, col('.'))
  1877. " No mark before line 1, cursor does not move
  1878. 1
  1879. norm! 5|[`
  1880. call assert_equal(' 1 b', getline('.'))
  1881. call assert_equal(1, line('.'))
  1882. call assert_equal(5, col('.'))
  1883. " No mark after line 21, cursor does not move
  1884. 21
  1885. norm! 5|]`
  1886. call assert_equal(' 21 b', getline('.'))
  1887. call assert_equal(21, line('.'))
  1888. call assert_equal(5, col('.'))
  1889. " Count too large for [`
  1890. " cursor moves to first lowercase mark
  1891. norm! 99[`
  1892. call assert_equal(' 1 b', getline('.'))
  1893. call assert_equal(1, line('.'))
  1894. call assert_equal(7, col('.'))
  1895. " Count too large for ]`
  1896. " cursor moves to last lowercase mark
  1897. norm! 99]`
  1898. call assert_equal(' 20 b', getline('.'))
  1899. call assert_equal(20, line('.'))
  1900. call assert_equal(8, col('.'))
  1901. " clean up
  1902. bw!
  1903. endfunc
  1904. " Test for ( and ) sentence movements
  1905. func Test_normal28_parenthesis()
  1906. new
  1907. call append(0, ['This is a test. With some sentences!', '', 'Even with a question? And one more. And no sentence here'])
  1908. $
  1909. norm! d(
  1910. call assert_equal(['This is a test. With some sentences!', '', 'Even with a question? And one more. ', ''], getline(1, '$'))
  1911. norm! 2d(
  1912. call assert_equal(['This is a test. With some sentences!', '', ' ', ''], getline(1, '$'))
  1913. 1
  1914. norm! 0d)
  1915. call assert_equal(['With some sentences!', '', ' ', ''], getline(1, '$'))
  1916. call append('$', ['This is a long sentence', '', 'spanning', 'over several lines. '])
  1917. $
  1918. norm! $d(
  1919. call assert_equal(['With some sentences!', '', ' ', '', 'This is a long sentence', ''], getline(1, '$'))
  1920. " Move to the next sentence from a paragraph macro
  1921. %d
  1922. call setline(1, ['.LP', 'blue sky!. blue sky.', 'blue sky. blue sky.'])
  1923. call cursor(1, 1)
  1924. normal )
  1925. call assert_equal([2, 1], [line('.'), col('.')])
  1926. normal )
  1927. call assert_equal([2, 12], [line('.'), col('.')])
  1928. normal ((
  1929. call assert_equal([1, 1], [line('.'), col('.')])
  1930. " It is an error if a next sentence is not found
  1931. %d
  1932. call setline(1, '.SH')
  1933. call assert_beeps('normal )')
  1934. " If only dot is present, don't treat that as a sentence
  1935. call setline(1, '. This is a sentence.')
  1936. normal $((
  1937. call assert_equal(3, col('.'))
  1938. " Jumping to a fold should open the fold
  1939. call setline(1, ['', '', 'one', 'two', 'three'])
  1940. set foldenable
  1941. 2,$fold
  1942. call feedkeys(')', 'xt')
  1943. call assert_equal(3, line('.'))
  1944. call assert_equal(1, foldlevel('.'))
  1945. call assert_equal(-1, foldclosed('.'))
  1946. set foldenable&
  1947. " clean up
  1948. bw!
  1949. endfunc
  1950. " Test for { and } paragraph movements
  1951. func Test_normal29_brace()
  1952. let text =<< trim [DATA]
  1953. A paragraph begins after each empty line, and also at each of a set of
  1954. paragraph macros, specified by the pairs of characters in the 'paragraphs'
  1955. option. The default is "IPLPPPQPP TPHPLIPpLpItpplpipbp", which corresponds to
  1956. the macros ".IP", ".LP", etc. (These are nroff macros, so the dot must be in
  1957. the first column). A section boundary is also a paragraph boundary.
  1958. Note that a blank line (only containing white space) is NOT a paragraph
  1959. boundary.
  1960. Also note that this does not include a '{' or '}' in the first column. When
  1961. the '{' flag is in 'cpoptions' then '{' in the first column is used as a
  1962. paragraph boundary |posix|.
  1963. {
  1964. This is no paragraph
  1965. unless the '{' is set
  1966. in 'cpoptions'
  1967. }
  1968. .IP
  1969. The nroff macros IP separates a paragraph
  1970. That means, it must be a '.'
  1971. followed by IP
  1972. .LPIt does not matter, if afterwards some
  1973. more characters follow.
  1974. .SHAlso section boundaries from the nroff
  1975. macros terminate a paragraph. That means
  1976. a character like this:
  1977. .NH
  1978. End of text here
  1979. [DATA]
  1980. new
  1981. call append(0, text)
  1982. 1
  1983. norm! 0d2}
  1984. let expected =<< trim [DATA]
  1985. .IP
  1986. The nroff macros IP separates a paragraph
  1987. That means, it must be a '.'
  1988. followed by IP
  1989. .LPIt does not matter, if afterwards some
  1990. more characters follow.
  1991. .SHAlso section boundaries from the nroff
  1992. macros terminate a paragraph. That means
  1993. a character like this:
  1994. .NH
  1995. End of text here
  1996. [DATA]
  1997. call assert_equal(expected, getline(1, '$'))
  1998. norm! 0d}
  1999. let expected =<< trim [DATA]
  2000. .LPIt does not matter, if afterwards some
  2001. more characters follow.
  2002. .SHAlso section boundaries from the nroff
  2003. macros terminate a paragraph. That means
  2004. a character like this:
  2005. .NH
  2006. End of text here
  2007. [DATA]
  2008. call assert_equal(expected, getline(1, '$'))
  2009. $
  2010. norm! d{
  2011. let expected =<< trim [DATA]
  2012. .LPIt does not matter, if afterwards some
  2013. more characters follow.
  2014. .SHAlso section boundaries from the nroff
  2015. macros terminate a paragraph. That means
  2016. a character like this:
  2017. [DATA]
  2018. call assert_equal(expected, getline(1, '$'))
  2019. norm! d{
  2020. let expected =<< trim [DATA]
  2021. .LPIt does not matter, if afterwards some
  2022. more characters follow.
  2023. [DATA]
  2024. call assert_equal(expected, getline(1, '$'))
  2025. " Test with { in cpoptions
  2026. %d
  2027. call append(0, text)
  2028. " Nvim: no "{" flag in 'cpoptions'.
  2029. " set cpo+={
  2030. " 1
  2031. " norm! 0d2}
  2032. let expected =<< trim [DATA]
  2033. {
  2034. This is no paragraph
  2035. unless the '{' is set
  2036. in 'cpoptions'
  2037. }
  2038. .IP
  2039. The nroff macros IP separates a paragraph
  2040. That means, it must be a '.'
  2041. followed by IP
  2042. .LPIt does not matter, if afterwards some
  2043. more characters follow.
  2044. .SHAlso section boundaries from the nroff
  2045. macros terminate a paragraph. That means
  2046. a character like this:
  2047. .NH
  2048. End of text here
  2049. [DATA]
  2050. " call assert_equal(expected, getline(1, '$'))
  2051. " $
  2052. " norm! d}
  2053. let expected =<< trim [DATA]
  2054. {
  2055. This is no paragraph
  2056. unless the '{' is set
  2057. in 'cpoptions'
  2058. }
  2059. .IP
  2060. The nroff macros IP separates a paragraph
  2061. That means, it must be a '.'
  2062. followed by IP
  2063. .LPIt does not matter, if afterwards some
  2064. more characters follow.
  2065. .SHAlso section boundaries from the nroff
  2066. macros terminate a paragraph. That means
  2067. a character like this:
  2068. .NH
  2069. End of text here
  2070. [DATA]
  2071. " call assert_equal(expected, getline(1, '$'))
  2072. " norm! gg}
  2073. " norm! d5}
  2074. let expected =<< trim [DATA]
  2075. {
  2076. This is no paragraph
  2077. unless the '{' is set
  2078. in 'cpoptions'
  2079. }
  2080. [DATA]
  2081. " call assert_equal(expected, getline(1, '$'))
  2082. " Jumping to a fold should open the fold
  2083. " %d
  2084. " call setline(1, ['', 'one', 'two', ''])
  2085. " set foldenable
  2086. " 2,$fold
  2087. " call feedkeys('}', 'xt')
  2088. " call assert_equal(4, line('.'))
  2089. " call assert_equal(1, foldlevel('.'))
  2090. " call assert_equal(-1, foldclosed('.'))
  2091. " set foldenable&
  2092. " clean up
  2093. set cpo-={
  2094. bw!
  2095. endfunc
  2096. " Test for section movements
  2097. func Test_normal_section()
  2098. new
  2099. let lines =<< trim [END]
  2100. int foo()
  2101. {
  2102. if (1)
  2103. {
  2104. a = 1;
  2105. }
  2106. }
  2107. [END]
  2108. call setline(1, lines)
  2109. " jumping to a folded line using [[ should open the fold
  2110. 2,3fold
  2111. call cursor(5, 1)
  2112. call feedkeys("[[", 'xt')
  2113. call assert_equal(2, line('.'))
  2114. call assert_equal(-1, foldclosedend(line('.')))
  2115. bwipe!
  2116. endfunc
  2117. " Test for changing case using u, U, gu, gU and ~ (tilde) commands
  2118. func Test_normal30_changecase()
  2119. new
  2120. call append(0, 'This is a simple test: äüöß')
  2121. norm! 1ggVu
  2122. call assert_equal('this is a simple test: äüöß', getline('.'))
  2123. norm! VU
  2124. call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖẞ', getline('.'))
  2125. norm! guu
  2126. call assert_equal('this is a simple test: äüöß', getline('.'))
  2127. norm! gUgU
  2128. call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖẞ', getline('.'))
  2129. norm! gugu
  2130. call assert_equal('this is a simple test: äüöß', getline('.'))
  2131. norm! gUU
  2132. call assert_equal('THIS IS A SIMPLE TEST: ÄÜÖẞ', getline('.'))
  2133. norm! 010~
  2134. call assert_equal('this is a SIMPLE TEST: ÄÜÖẞ', getline('.'))
  2135. norm! V~
  2136. call assert_equal('THIS IS A simple test: äüöß', getline('.'))
  2137. call assert_beeps('norm! c~')
  2138. %d
  2139. call assert_beeps('norm! ~')
  2140. " Test with multiple lines
  2141. call setline(1, ['AA', 'BBBB', 'CCCCCC', 'DDDDDDDD'])
  2142. norm! ggguG
  2143. call assert_equal(['aa', 'bbbb', 'cccccc', 'dddddddd'], getline(1, '$'))
  2144. norm! GgUgg
  2145. call assert_equal(['AA', 'BBBB', 'CCCCCC', 'DDDDDDDD'], getline(1, '$'))
  2146. %d
  2147. " Test for changing case across lines using 'whichwrap'
  2148. call setline(1, ['aaaaaa', 'aaaaaa'])
  2149. normal! gg10~
  2150. call assert_equal(['AAAAAA', 'aaaaaa'], getline(1, 2))
  2151. set whichwrap+=~
  2152. normal! gg10~
  2153. call assert_equal(['aaaaaa', 'AAAAaa'], getline(1, 2))
  2154. set whichwrap&
  2155. " try changing the case with a double byte encoding (DBCS)
  2156. %bw!
  2157. let enc = &enc
  2158. " set encoding=cp932
  2159. call setline(1, "\u8470")
  2160. normal ~
  2161. normal gU$gu$gUgUg~g~gugu
  2162. call assert_equal("\u8470", getline(1))
  2163. let &encoding = enc
  2164. " clean up
  2165. bw!
  2166. endfunc
  2167. " Turkish ASCII turns to multi-byte. On some systems Turkish locale
  2168. " is available but toupper()/tolower() don't do the right thing.
  2169. func Test_normal_changecase_turkish()
  2170. new
  2171. try
  2172. lang tr_TR.UTF-8
  2173. set casemap=
  2174. let iupper = toupper('i')
  2175. if iupper == "\u0130"
  2176. call setline(1, 'iI')
  2177. 1normal gUU
  2178. call assert_equal("\u0130I", getline(1))
  2179. call assert_equal("\u0130I", toupper("iI"))
  2180. call setline(1, 'iI')
  2181. 1normal guu
  2182. call assert_equal("i\u0131", getline(1))
  2183. call assert_equal("i\u0131", tolower("iI"))
  2184. elseif iupper == "I"
  2185. call setline(1, 'iI')
  2186. 1normal gUU
  2187. call assert_equal("II", getline(1))
  2188. call assert_equal("II", toupper("iI"))
  2189. call setline(1, 'iI')
  2190. 1normal guu
  2191. call assert_equal("ii", getline(1))
  2192. call assert_equal("ii", tolower("iI"))
  2193. else
  2194. call assert_true(false, "expected toupper('i') to be either 'I' or '\u0131'")
  2195. endif
  2196. set casemap&
  2197. call setline(1, 'iI')
  2198. 1normal gUU
  2199. call assert_equal("II", getline(1))
  2200. call assert_equal("II", toupper("iI"))
  2201. call setline(1, 'iI')
  2202. 1normal guu
  2203. call assert_equal("ii", getline(1))
  2204. call assert_equal("ii", tolower("iI"))
  2205. lang en_US.UTF-8
  2206. catch /E197:/
  2207. " can't use Turkish locale
  2208. throw 'Skipped: Turkish locale not available'
  2209. endtry
  2210. bwipe!
  2211. endfunc
  2212. " Test for r (replace) command
  2213. func Test_normal31_r_cmd()
  2214. new
  2215. call append(0, 'This is a simple test: abcd')
  2216. exe "norm! 1gg$r\<cr>"
  2217. call assert_equal(['This is a simple test: abc', '', ''], getline(1,'$'))
  2218. exe "norm! 1gg2wlr\<cr>"
  2219. call assert_equal(['This is a', 'simple test: abc', '', ''], getline(1,'$'))
  2220. exe "norm! 2gg0W5r\<cr>"
  2221. call assert_equal(['This is a', 'simple ', ' abc', '', ''], getline('1', '$'))
  2222. set autoindent
  2223. call setline(2, ['simple test: abc', ''])
  2224. exe "norm! 2gg0W5r\<cr>"
  2225. call assert_equal(['This is a', 'simple ', 'abc', '', '', ''], getline('1', '$'))
  2226. exe "norm! 1ggVr\<cr>"
  2227. call assert_equal('^M^M^M^M^M^M^M^M^M', strtrans(getline(1)))
  2228. call setline(1, 'This is a')
  2229. exe "norm! 1gg05rf"
  2230. call assert_equal('fffffis a', getline(1))
  2231. " When replacing characters, copy characters from above and below lines
  2232. " using CTRL-Y and CTRL-E.
  2233. " Different code paths are used for utf-8 and latin1 encodings
  2234. set showmatch
  2235. " for enc in ['latin1', 'utf-8']
  2236. for enc in ['utf-8']
  2237. enew!
  2238. let &encoding = enc
  2239. call setline(1, [' {a}', 'xxxxxxxxxx', ' [b]'])
  2240. exe "norm! 2gg5r\<C-Y>l5r\<C-E>"
  2241. call assert_equal(' {a}x [b]x', getline(2))
  2242. endfor
  2243. set showmatch&
  2244. " r command should fail in operator pending mode
  2245. call assert_beeps('normal! cr')
  2246. " replace a tab character in visual mode
  2247. %d
  2248. call setline(1, ["a\tb", "c\td", "e\tf"])
  2249. normal gglvjjrx
  2250. call assert_equal(['axx', 'xxx', 'xxf'], getline(1, '$'))
  2251. " replace with a multibyte character (with multiple composing characters)
  2252. %d
  2253. new
  2254. call setline(1, 'aaa')
  2255. exe "normal $ra\u0328\u0301"
  2256. call assert_equal("aaa\u0328\u0301", getline(1))
  2257. " clean up
  2258. set noautoindent
  2259. bw!
  2260. endfunc
  2261. " Test for g*, g#
  2262. func Test_normal32_g_cmd1()
  2263. new
  2264. call append(0, ['abc.x_foo', 'x_foobar.abc'])
  2265. 1
  2266. norm! $g*
  2267. call assert_equal('x_foo', @/)
  2268. call assert_equal('x_foobar.abc', getline('.'))
  2269. norm! $g#
  2270. call assert_equal('abc', @/)
  2271. call assert_equal('abc.x_foo', getline('.'))
  2272. " clean up
  2273. bw!
  2274. endfunc
  2275. " Test for g`, g;, g,, g&, gv, gk, gj, gJ, g0, g^, g_, gm, g$, gM, g CTRL-G,
  2276. " gi and gI commands
  2277. func Test_normal33_g_cmd2()
  2278. call Setup_NewWindow()
  2279. " Test for g`
  2280. clearjumps
  2281. norm! ma10j
  2282. let a=execute(':jumps')
  2283. " empty jumplist
  2284. call assert_equal('>', a[-1:])
  2285. norm! g`a
  2286. call assert_equal('>', a[-1:])
  2287. call assert_equal(1, line('.'))
  2288. call assert_equal('1', getline('.'))
  2289. call cursor(10, 1)
  2290. norm! g'a
  2291. call assert_equal('>', a[-1:])
  2292. call assert_equal(1, line('.'))
  2293. let v:errmsg = ''
  2294. call assert_nobeep("normal! g`\<Esc>")
  2295. call assert_equal('', v:errmsg)
  2296. call assert_nobeep("normal! g'\<Esc>")
  2297. call assert_equal('', v:errmsg)
  2298. " Test for g; and g,
  2299. norm! g;
  2300. " there is only one change in the changelist
  2301. " currently, when we setup the window
  2302. call assert_equal(2, line('.'))
  2303. call assert_fails(':norm! g;', 'E662')
  2304. call assert_fails(':norm! g,', 'E663')
  2305. let &ul = &ul
  2306. call append('$', ['a', 'b', 'c', 'd'])
  2307. let &ul = &ul
  2308. call append('$', ['Z', 'Y', 'X', 'W'])
  2309. let a = execute(':changes')
  2310. call assert_match('2\s\+0\s\+2', a)
  2311. call assert_match('101\s\+0\s\+a', a)
  2312. call assert_match('105\s\+0\s\+Z', a)
  2313. norm! 3g;
  2314. call assert_equal(2, line('.'))
  2315. norm! 2g,
  2316. call assert_equal(105, line('.'))
  2317. " Test for g& - global substitute
  2318. %d
  2319. call setline(1, range(1,10))
  2320. call append('$', ['a', 'b', 'c', 'd'])
  2321. $s/\w/&&/g
  2322. exe "norm! /[1-8]\<cr>"
  2323. norm! g&
  2324. call assert_equal(['11', '22', '33', '44', '55', '66', '77', '88', '9', '110', 'a', 'b', 'c', 'dd'], getline(1, '$'))
  2325. " Jumping to a fold using gg should open the fold
  2326. set foldenable
  2327. set foldopen+=jump
  2328. 5,8fold
  2329. call feedkeys('6gg', 'xt')
  2330. call assert_equal(1, foldlevel('.'))
  2331. call assert_equal(-1, foldclosed('.'))
  2332. set foldopen-=jump
  2333. set foldenable&
  2334. " Test for gv
  2335. %d
  2336. call append('$', repeat(['abcdefgh'], 8))
  2337. exe "norm! 2gg02l\<c-v>2j2ly"
  2338. call assert_equal(['cde', 'cde', 'cde'], getreg(0, 1, 1))
  2339. " in visual mode, gv swaps current and last selected region
  2340. exe "norm! G0\<c-v>4k4lgvd"
  2341. call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh', 'abcdefgh'], getline(1,'$'))
  2342. exe "norm! G0\<c-v>4k4ly"
  2343. exe "norm! gvood"
  2344. call assert_equal(['', 'abfgh', 'abfgh', 'abfgh', 'fgh', 'fgh', 'fgh', 'fgh', 'fgh'], getline(1,'$'))
  2345. " gv cannot be used in operator pending mode
  2346. call assert_beeps('normal! cgv')
  2347. " gv should beep without a previously selected visual area
  2348. new
  2349. call assert_beeps('normal! gv')
  2350. close
  2351. " Test for gk/gj
  2352. %d
  2353. 15vsp
  2354. set wrap listchars= sbr=
  2355. let lineA = 'abcdefghijklmnopqrstuvwxyz'
  2356. let lineB = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  2357. let lineC = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
  2358. $put =lineA
  2359. $put =lineB
  2360. norm! 3gg0dgk
  2361. call assert_equal(['', 'abcdefghijklmno', '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'], getline(1, '$'))
  2362. set nu
  2363. norm! 3gg0gjdgj
  2364. call assert_equal(['', 'abcdefghijklmno', '0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
  2365. " Test for gJ
  2366. norm! 2gggJ
  2367. call assert_equal(['', 'abcdefghijklmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
  2368. call assert_equal(16, col('.'))
  2369. " shouldn't do anything
  2370. norm! 10gJ
  2371. call assert_equal(1, col('.'))
  2372. " Test for g0 g^ gm g$
  2373. exe "norm! 2gg0gji "
  2374. call assert_equal(['', 'abcdefghijk lmno0123456789AMNOPQRSTUVWXYZ'], getline(1,'$'))
  2375. norm! g0yl
  2376. call assert_equal(12, col('.'))
  2377. call assert_equal(' ', getreg(0))
  2378. norm! g$yl
  2379. call assert_equal(22, col('.'))
  2380. call assert_equal('3', getreg(0))
  2381. norm! gmyl
  2382. call assert_equal(17, col('.'))
  2383. call assert_equal('n', getreg(0))
  2384. norm! g^yl
  2385. call assert_equal(15, col('.'))
  2386. call assert_equal('l', getreg(0))
  2387. call assert_beeps('normal 5g$')
  2388. " Test for g$ with double-width character half displayed
  2389. vsplit
  2390. 9wincmd |
  2391. setlocal nowrap nonumber
  2392. call setline(2, 'asdfasdfヨ')
  2393. 2
  2394. normal 0g$
  2395. call assert_equal(8, col('.'))
  2396. 10wincmd |
  2397. normal 0g$
  2398. call assert_equal(9, col('.'))
  2399. setlocal signcolumn=yes
  2400. 11wincmd |
  2401. normal 0g$
  2402. call assert_equal(8, col('.'))
  2403. 12wincmd |
  2404. normal 0g$
  2405. call assert_equal(9, col('.'))
  2406. close
  2407. " Test for g_
  2408. call assert_beeps('normal! 100g_')
  2409. call setline(2, [' foo ', ' foobar '])
  2410. normal! 2ggg_
  2411. call assert_equal(5, col('.'))
  2412. normal! 2g_
  2413. call assert_equal(8, col('.'))
  2414. norm! 2ggdG
  2415. $put =lineC
  2416. " Test for gM
  2417. norm! gMyl
  2418. call assert_equal(73, col('.'))
  2419. call assert_equal('0', getreg(0))
  2420. " Test for 20gM
  2421. norm! 20gMyl
  2422. call assert_equal(29, col('.'))
  2423. call assert_equal('S', getreg(0))
  2424. " Test for 60gM
  2425. norm! 60gMyl
  2426. call assert_equal(87, col('.'))
  2427. call assert_equal('E', getreg(0))
  2428. " Test for gM with Tab characters
  2429. call setline('.', "\ta\tb\tc\td\te\tf")
  2430. norm! gMyl
  2431. call assert_equal(6, col('.'))
  2432. call assert_equal("c", getreg(0))
  2433. " Test for g Ctrl-G
  2434. call setline('.', lineC)
  2435. norm! 60gMyl
  2436. set ff=unix
  2437. let a=execute(":norm! g\<c-g>")
  2438. call assert_match('Col 87 of 144; Line 2 of 2; Word 1 of 1; Byte 88 of 146', a)
  2439. " Test for gI
  2440. norm! gIfoo
  2441. call assert_equal(['', 'foo0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz01234567890123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'], getline(1,'$'))
  2442. " Test for gi
  2443. wincmd c
  2444. %d
  2445. set tw=0
  2446. call setline(1, ['foobar', 'new line'])
  2447. norm! A next word
  2448. $put ='third line'
  2449. norm! gi another word
  2450. call assert_equal(['foobar next word another word', 'new line', 'third line'], getline(1,'$'))
  2451. call setline(1, 'foobar')
  2452. normal! Ggifirst line
  2453. call assert_equal('foobarfirst line', getline(1))
  2454. " Test gi in 'virtualedit' mode with cursor after the end of the line
  2455. set virtualedit=all
  2456. call setline(1, 'foo')
  2457. exe "normal! Abar\<Right>\<Right>\<Right>\<Right>"
  2458. call setline(1, 'foo')
  2459. normal! Ggifirst line
  2460. call assert_equal('foo first line', getline(1))
  2461. set virtualedit&
  2462. " Test for aborting a g command using CTRL-\ CTRL-G
  2463. exe "normal! g\<C-\>\<C-G>"
  2464. call assert_equal('foo first line', getline('.'))
  2465. " clean up
  2466. bw!
  2467. endfunc
  2468. func Test_normal_ex_substitute()
  2469. " This was hanging on the substitute prompt.
  2470. new
  2471. call setline(1, 'a')
  2472. exe "normal! gggQs/a/b/c\<CR>"
  2473. call assert_equal('a', getline(1))
  2474. bwipe!
  2475. endfunc
  2476. " Test for g CTRL-G
  2477. func Test_g_ctrl_g()
  2478. new
  2479. let a = execute(":norm! g\<c-g>")
  2480. call assert_equal("\n--No lines in buffer--", a)
  2481. " Test for CTRL-G (same as :file)
  2482. let a = execute(":norm! \<c-g>")
  2483. call assert_equal("\n\n\"[No Name]\" --No lines in buffer--", a)
  2484. call setline(1, ['first line', 'second line'])
  2485. " Test g CTRL-g with dos, mac and unix file type.
  2486. norm! gojll
  2487. set ff=dos
  2488. let a = execute(":norm! g\<c-g>")
  2489. call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 15 of 25", a)
  2490. set ff=mac
  2491. let a = execute(":norm! g\<c-g>")
  2492. call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a)
  2493. set ff=unix
  2494. let a = execute(":norm! g\<c-g>")
  2495. call assert_equal("\nCol 3 of 11; Line 2 of 2; Word 3 of 4; Byte 14 of 23", a)
  2496. " Test g CTRL-g in visual mode (v)
  2497. let a = execute(":norm! gojllvlg\<c-g>")
  2498. call assert_equal("\nSelected 1 of 2 Lines; 1 of 4 Words; 2 of 23 Bytes", a)
  2499. " Test g CTRL-g in visual mode (CTRL-V) with end col > start col
  2500. let a = execute(":norm! \<Esc>gojll\<C-V>kllg\<c-g>")
  2501. call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a)
  2502. " Test g_CTRL-g in visual mode (CTRL-V) with end col < start col
  2503. let a = execute(":norm! \<Esc>goll\<C-V>jhhg\<c-g>")
  2504. call assert_equal("\nSelected 3 Cols; 2 of 2 Lines; 2 of 4 Words; 6 of 23 Bytes", a)
  2505. " Test g CTRL-g in visual mode (CTRL-V) with end_vcol being MAXCOL
  2506. let a = execute(":norm! \<Esc>gojll\<C-V>k$g\<c-g>")
  2507. call assert_equal("\nSelected 2 of 2 Lines; 4 of 4 Words; 17 of 23 Bytes", a)
  2508. " There should be one byte less with noeol
  2509. set bin noeol
  2510. let a = execute(":norm! \<Esc>gog\<c-g>")
  2511. call assert_equal("\nCol 1 of 10; Line 1 of 2; Word 1 of 4; Char 1 of 23; Byte 1 of 22", a)
  2512. set bin & eol&
  2513. call setline(1, ['Français', '日本語'])
  2514. let a = execute(":norm! \<Esc>gojlg\<c-g>")
  2515. 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)
  2516. let a = execute(":norm! \<Esc>gojvlg\<c-g>")
  2517. call assert_equal("\nSelected 1 of 2 Lines; 1 of 2 Words; 2 of 13 Chars; 6 of 20 Bytes", a)
  2518. let a = execute(":norm! \<Esc>goll\<c-v>jlg\<c-g>")
  2519. call assert_equal("\nSelected 4 Cols; 2 of 2 Lines; 2 of 2 Words; 6 of 13 Chars; 11 of 20 Bytes", a)
  2520. set fenc=utf8 bomb
  2521. let a = execute(":norm! \<Esc>gojlg\<c-g>")
  2522. 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)
  2523. set fenc=utf16 bomb
  2524. let a = execute(":norm! g\<c-g>")
  2525. 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)
  2526. set fenc=utf32 bomb
  2527. let a = execute(":norm! g\<c-g>")
  2528. 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)
  2529. set fenc& bomb&
  2530. set ff&
  2531. bwipe!
  2532. endfunc
  2533. " Test for g8
  2534. func Test_normal34_g_cmd3()
  2535. new
  2536. let a=execute(':norm! 1G0g8')
  2537. call assert_equal("\nNUL", a)
  2538. call setline(1, 'abcdefghijklmnopqrstuvwxyzäüö')
  2539. let a=execute(':norm! 1G$g8')
  2540. call assert_equal("\nc3 b6 ", a)
  2541. call setline(1, "a\u0302")
  2542. let a=execute(':norm! 1G0g8')
  2543. call assert_equal("\n61 + cc 82 ", a)
  2544. " clean up
  2545. bw!
  2546. endfunc
  2547. " Test 8g8 which finds invalid utf8 at or after the cursor.
  2548. func Test_normal_8g8()
  2549. new
  2550. " With invalid byte.
  2551. call setline(1, "___\xff___")
  2552. norm! 1G08g8g
  2553. call assert_equal([0, 1, 4, 0, 1], getcurpos())
  2554. " With invalid byte before the cursor.
  2555. call setline(1, "___\xff___")
  2556. norm! 1G$h8g8g
  2557. call assert_equal([0, 1, 6, 0, 9], getcurpos())
  2558. " With truncated sequence.
  2559. call setline(1, "___\xE2\x82___")
  2560. norm! 1G08g8g
  2561. call assert_equal([0, 1, 4, 0, 1], getcurpos())
  2562. " With overlong sequence.
  2563. call setline(1, "___\xF0\x82\x82\xAC___")
  2564. norm! 1G08g8g
  2565. call assert_equal([0, 1, 4, 0, 1], getcurpos())
  2566. " With valid utf8.
  2567. call setline(1, "café")
  2568. norm! 1G08g8
  2569. call assert_equal([0, 1, 1, 0, 1], getcurpos())
  2570. bw!
  2571. endfunc
  2572. " Test for g<
  2573. func Test_normal35_g_cmd4()
  2574. " Cannot capture its output,
  2575. " probably a bug, therefore, test disabled:
  2576. throw "Skipped: output of g< can't be tested currently"
  2577. echo "a\nb\nc\nd"
  2578. let b=execute(':norm! g<')
  2579. call assert_true(!empty(b), 'failed `execute(g<)`')
  2580. endfunc
  2581. " Test for gp gP go
  2582. func Test_normal36_g_cmd5()
  2583. new
  2584. call append(0, 'abcdefghijklmnopqrstuvwxyz')
  2585. set ff=unix
  2586. " Test for gp gP
  2587. call append(1, range(1,10))
  2588. 1
  2589. norm! 1yy
  2590. 3
  2591. norm! gp
  2592. call assert_equal([0, 5, 1, 0, 1], getcurpos())
  2593. $
  2594. norm! gP
  2595. call assert_equal([0, 14, 1, 0, 1], getcurpos())
  2596. " Test for go
  2597. norm! 26go
  2598. call assert_equal([0, 1, 26, 0, 26], getcurpos())
  2599. norm! 27go
  2600. call assert_equal([0, 1, 26, 0, 26], getcurpos())
  2601. norm! 28go
  2602. call assert_equal([0, 2, 1, 0, 1], getcurpos())
  2603. set ff=dos
  2604. norm! 29go
  2605. call assert_equal([0, 2, 1, 0, 1], getcurpos())
  2606. set ff=unix
  2607. norm! gg0
  2608. norm! 101go
  2609. call assert_equal([0, 13, 26, 0, 26], getcurpos())
  2610. norm! 103go
  2611. call assert_equal([0, 14, 1, 0, 1], getcurpos())
  2612. " count > buffer content
  2613. norm! 120go
  2614. call assert_equal([0, 14, 1, 0, v:maxcol], getcurpos())
  2615. " clean up
  2616. bw!
  2617. endfunc
  2618. " Test for gt and gT
  2619. func Test_normal37_g_cmd6()
  2620. tabnew 1.txt
  2621. tabnew 2.txt
  2622. tabnew 3.txt
  2623. norm! 1gt
  2624. call assert_equal(1, tabpagenr())
  2625. norm! 3gt
  2626. call assert_equal(3, tabpagenr())
  2627. norm! 1gT
  2628. " count gT goes not to the absolute tabpagenumber
  2629. " but, but goes to the count previous tabpagenumber
  2630. call assert_equal(2, tabpagenr())
  2631. " wrap around
  2632. norm! 3gT
  2633. call assert_equal(3, tabpagenr())
  2634. " gt does not wrap around
  2635. norm! 5gt
  2636. call assert_equal(3, tabpagenr())
  2637. for i in range(3)
  2638. tabclose
  2639. endfor
  2640. " clean up
  2641. call assert_fails(':tabclose', 'E784:')
  2642. endfunc
  2643. " Test for <Home> and <C-Home> key
  2644. func Test_normal38_nvhome()
  2645. new
  2646. call setline(1, range(10))
  2647. $
  2648. setl et sw=2
  2649. norm! V10>$
  2650. " count is ignored
  2651. exe "norm! 10\<home>"
  2652. call assert_equal(1, col('.'))
  2653. exe "norm! \<home>"
  2654. call assert_equal([0, 10, 1, 0, 1], getcurpos())
  2655. exe "norm! 5\<c-home>"
  2656. call assert_equal([0, 5, 1, 0, 1], getcurpos())
  2657. exe "norm! \<c-home>"
  2658. call assert_equal([0, 1, 1, 0, 1], getcurpos())
  2659. exe "norm! G\<c-kHome>"
  2660. call assert_equal([0, 1, 1, 0, 1], getcurpos())
  2661. " clean up
  2662. bw!
  2663. endfunc
  2664. " Test for <End> and <C-End> keys
  2665. func Test_normal_nvend()
  2666. new
  2667. call setline(1, map(range(1, 10), '"line" .. v:val'))
  2668. exe "normal! \<End>"
  2669. call assert_equal(5, col('.'))
  2670. exe "normal! 4\<End>"
  2671. call assert_equal([4, 5], [line('.'), col('.')])
  2672. exe "normal! \<C-End>"
  2673. call assert_equal([10, 6], [line('.'), col('.')])
  2674. bwipe!
  2675. endfunc
  2676. " Test for cw cW ce
  2677. func Test_normal39_cw()
  2678. " Test for cw and cW on whitespace
  2679. new
  2680. set tw=0
  2681. call append(0, 'here are some words')
  2682. norm! 1gg0elcwZZZ
  2683. call assert_equal('hereZZZare some words', getline('.'))
  2684. norm! 1gg0elcWYYY
  2685. call assert_equal('hereZZZareYYYsome words', getline('.'))
  2686. norm! 2gg0cwfoo
  2687. call assert_equal('foo', getline('.'))
  2688. call setline(1, 'one; two')
  2689. call cursor(1, 1)
  2690. call feedkeys('cwvim', 'xt')
  2691. call assert_equal('vim; two', getline(1))
  2692. call feedkeys('0cWone', 'xt')
  2693. call assert_equal('one two', getline(1))
  2694. "When cursor is at the end of a word 'ce' will change until the end of the
  2695. "next word, but 'cw' will change only one character
  2696. call setline(1, 'one two')
  2697. call feedkeys('0ecwce', 'xt')
  2698. call assert_equal('once two', getline(1))
  2699. call setline(1, 'one two')
  2700. call feedkeys('0ecely', 'xt')
  2701. call assert_equal('only', getline(1))
  2702. " clean up
  2703. bw!
  2704. endfunc
  2705. " Test for CTRL-\ commands
  2706. func Test_normal40_ctrl_bsl()
  2707. new
  2708. call append(0, 'here are some words')
  2709. exe "norm! 1gg0a\<C-\>\<C-N>"
  2710. call assert_equal('n', mode())
  2711. call assert_equal(1, col('.'))
  2712. call assert_equal('', visualmode())
  2713. exe "norm! 1gg0viw\<C-\>\<C-N>"
  2714. call assert_equal('n', mode())
  2715. call assert_equal(4, col('.'))
  2716. exe "norm! 1gg0a\<C-\>\<C-G>"
  2717. call assert_equal('n', mode())
  2718. call assert_equal(1, col('.'))
  2719. "imap <buffer> , <c-\><c-n>
  2720. " set im
  2721. exe ":norm! \<c-\>\<c-n>dw"
  2722. " set noim
  2723. call assert_equal('are some words', getline(1))
  2724. call assert_false(&insertmode)
  2725. call assert_beeps("normal! \<C-\>\<C-A>")
  2726. " Using CTRL-\ CTRL-N in cmd window should close the window
  2727. call feedkeys("q:\<C-\>\<C-N>", 'xt')
  2728. call assert_equal('', getcmdwintype())
  2729. " clean up
  2730. bw!
  2731. endfunc
  2732. " Test for <c-r>=, <c-r><c-r>= and <c-r><c-o>= in insert mode
  2733. func Test_normal41_insert_reg()
  2734. new
  2735. set sts=2 sw=2 ts=8 tw=0
  2736. call append(0, ["aaa\tbbb\tccc", '', '', ''])
  2737. let a=getline(1)
  2738. norm! 2gg0
  2739. exe "norm! a\<c-r>=a\<cr>"
  2740. norm! 3gg0
  2741. exe "norm! a\<c-r>\<c-r>=a\<cr>"
  2742. norm! 4gg0
  2743. exe "norm! a\<c-r>\<c-o>=a\<cr>"
  2744. call assert_equal(['aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', 'aaa bbb ccc', ''], getline(1, '$'))
  2745. " clean up
  2746. set sts=0 sw=8 ts=8
  2747. bw!
  2748. endfunc
  2749. " Test for Ctrl-D and Ctrl-U
  2750. func Test_normal42_halfpage()
  2751. call Setup_NewWindow()
  2752. call assert_equal(5, &scroll)
  2753. exe "norm! \<c-d>"
  2754. call assert_equal('6', getline('.'))
  2755. exe "norm! 2\<c-d>"
  2756. call assert_equal('8', getline('.'))
  2757. call assert_equal(2, &scroll)
  2758. set scroll=5
  2759. exe "norm! \<c-u>"
  2760. call assert_equal('3', getline('.'))
  2761. 1
  2762. set scrolloff=5
  2763. exe "norm! \<c-d>"
  2764. call assert_equal('10', getline('.'))
  2765. exe "norm! \<c-u>"
  2766. call assert_equal('5', getline('.'))
  2767. 1
  2768. set scrolloff=99
  2769. exe "norm! \<c-d>"
  2770. call assert_equal('10', getline('.'))
  2771. set scrolloff=0
  2772. 100
  2773. exe "norm! $\<c-u>"
  2774. call assert_equal('95', getline('.'))
  2775. call assert_equal([0, 95, 1, 0, 1], getcurpos())
  2776. 100
  2777. set nostartofline
  2778. exe "norm! $\<c-u>"
  2779. call assert_equal('95', getline('.'))
  2780. call assert_equal([0, 95, 2, 0, v:maxcol], getcurpos())
  2781. " cleanup
  2782. set startofline
  2783. bw!
  2784. endfunc
  2785. func Test_normal45_drop()
  2786. if !has('dnd')
  2787. " The ~ register does not exist
  2788. call assert_beeps('norm! "~')
  2789. return
  2790. endif
  2791. " basic test for drag-n-drop
  2792. " unfortunately, without a gui, we can't really test much here,
  2793. " so simply test that ~p fails (which uses the drop register)
  2794. new
  2795. call assert_fails(':norm! "~p', 'E353')
  2796. call assert_equal([], getreg('~', 1, 1))
  2797. " the ~ register is read only
  2798. call assert_fails(':let @~="1"', 'E354')
  2799. bw!
  2800. endfunc
  2801. func Test_normal46_ignore()
  2802. new
  2803. " How to test this?
  2804. " let's just for now test, that the buffer
  2805. " does not change
  2806. call feedkeys("\<c-s>", 't')
  2807. call assert_equal([''], getline(1,'$'))
  2808. " no valid commands
  2809. exe "norm! \<char-0x100>"
  2810. call assert_equal([''], getline(1,'$'))
  2811. exe "norm! ä"
  2812. call assert_equal([''], getline(1,'$'))
  2813. " clean up
  2814. bw!
  2815. endfunc
  2816. func Test_normal47_visual_buf_wipe()
  2817. " This was causing a crash or ml_get error.
  2818. enew!
  2819. call setline(1,'xxx')
  2820. normal $
  2821. new
  2822. call setline(1, range(1,2))
  2823. 2
  2824. exe "norm \<C-V>$"
  2825. bw!
  2826. norm yp
  2827. set nomodified
  2828. endfunc
  2829. func Test_normal48_wincmd()
  2830. new
  2831. exe "norm! \<c-w>c"
  2832. call assert_equal(1, winnr('$'))
  2833. call assert_fails(":norm! \<c-w>c", "E444")
  2834. endfunc
  2835. func Test_normal49_counts()
  2836. new
  2837. call setline(1, 'one two three four five six seven eight nine ten')
  2838. 1
  2839. norm! 3d2w
  2840. call assert_equal('seven eight nine ten', getline(1))
  2841. bw!
  2842. endfunc
  2843. func Test_normal50_commandline()
  2844. CheckFeature timers
  2845. CheckFeature cmdline_hist
  2846. func! DoTimerWork(id)
  2847. call assert_equal(1, getbufinfo('')[0].command)
  2848. " should fail, with E11, but does fail with E23?
  2849. "call feedkeys("\<c-^>", 'tm')
  2850. " should fail with E11 - "Invalid in command-line window"
  2851. call assert_fails(":wincmd p", 'E11')
  2852. " Return from commandline window.
  2853. call feedkeys("\<CR>", 't')
  2854. endfunc
  2855. let oldlang=v:lang
  2856. lang C
  2857. set updatetime=20
  2858. call timer_start(100, 'DoTimerWork')
  2859. try
  2860. " throws E23, for whatever reason...
  2861. call feedkeys('q:', 'x!')
  2862. catch /E23/
  2863. " no-op
  2864. endtry
  2865. " clean up
  2866. delfunc DoTimerWork
  2867. set updatetime=4000
  2868. exe "lang" oldlang
  2869. bw!
  2870. endfunc
  2871. func Test_normal51_FileChangedRO()
  2872. CheckFeature autocmd
  2873. call writefile(['foo'], 'Xreadonly.log')
  2874. new Xreadonly.log
  2875. setl ro
  2876. au FileChangedRO <buffer> :call feedkeys("\<c-^>", 'tix')
  2877. call assert_fails(":norm! Af", 'E788')
  2878. call assert_equal(['foo'], getline(1,'$'))
  2879. call assert_equal('Xreadonly.log', bufname(''))
  2880. " cleanup
  2881. bw!
  2882. call delete("Xreadonly.log")
  2883. endfunc
  2884. func Test_normal52_rl()
  2885. CheckFeature rightleft
  2886. new
  2887. call setline(1, 'abcde fghij klmnopq')
  2888. norm! 1gg$
  2889. set rl
  2890. call assert_equal(19, col('.'))
  2891. call feedkeys('l', 'tx')
  2892. call assert_equal(18, col('.'))
  2893. call feedkeys('h', 'tx')
  2894. call assert_equal(19, col('.'))
  2895. call feedkeys("\<right>", 'tx')
  2896. call assert_equal(18, col('.'))
  2897. call feedkeys("\<left>", 'tx')
  2898. call assert_equal(19, col('.'))
  2899. call feedkeys("\<s-right>", 'tx')
  2900. call assert_equal(13, col('.'))
  2901. call feedkeys("\<c-right>", 'tx')
  2902. call assert_equal(7, col('.'))
  2903. call feedkeys("\<c-left>", 'tx')
  2904. call assert_equal(13, col('.'))
  2905. call feedkeys("\<s-left>", 'tx')
  2906. call assert_equal(19, col('.'))
  2907. call feedkeys("<<", 'tx')
  2908. call assert_equal(' abcde fghij klmnopq',getline(1))
  2909. call feedkeys(">>", 'tx')
  2910. call assert_equal('abcde fghij klmnopq',getline(1))
  2911. " cleanup
  2912. set norl
  2913. bw!
  2914. endfunc
  2915. func Test_normal54_Ctrl_bsl()
  2916. new
  2917. call setline(1, 'abcdefghijklmn')
  2918. exe "norm! df\<c-\>\<c-n>"
  2919. call assert_equal(['abcdefghijklmn'], getline(1,'$'))
  2920. exe "norm! df\<c-\>\<c-g>"
  2921. call assert_equal(['abcdefghijklmn'], getline(1,'$'))
  2922. exe "norm! df\<c-\>m"
  2923. call assert_equal(['abcdefghijklmn'], getline(1,'$'))
  2924. call setline(2, 'abcdefghijklmnāf')
  2925. norm! 2gg0
  2926. exe "norm! df\<Char-0x101>"
  2927. call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$'))
  2928. norm! 1gg0
  2929. exe "norm! df\<esc>"
  2930. call assert_equal(['abcdefghijklmn', 'f'], getline(1,'$'))
  2931. " clean up
  2932. bw!
  2933. endfunc
  2934. func Test_normal_large_count()
  2935. " This may fail with 32bit long, how do we detect that?
  2936. new
  2937. normal o
  2938. normal 6666666666dL
  2939. bwipe!
  2940. endfunc
  2941. func Test_delete_until_paragraph()
  2942. new
  2943. normal grádv}
  2944. call assert_equal('á', getline(1))
  2945. normal grád}
  2946. call assert_equal('', getline(1))
  2947. bwipe!
  2948. endfunc
  2949. " Test for the gr (virtual replace) command
  2950. func Test_gr_command()
  2951. enew!
  2952. " Test for the bug fixed by 7.4.387
  2953. let save_cpo = &cpo
  2954. call append(0, ['First line', 'Second line', 'Third line'])
  2955. exe "normal i\<C-G>u"
  2956. call cursor(2, 1)
  2957. set cpo-=X
  2958. normal 4gro
  2959. call assert_equal('oooond line', getline(2))
  2960. undo
  2961. set cpo+=X
  2962. normal 4gro
  2963. call assert_equal('ooooecond line', getline(2))
  2964. let &cpo = save_cpo
  2965. normal! ggvegrx
  2966. call assert_equal('xxxxx line', getline(1))
  2967. exe "normal! gggr\<C-V>122"
  2968. call assert_equal('zxxxx line', getline(1))
  2969. set virtualedit=all
  2970. normal! 15|grl
  2971. call assert_equal('zxxxx line l', getline(1))
  2972. set virtualedit&
  2973. set nomodifiable
  2974. call assert_fails('normal! grx', 'E21:')
  2975. call assert_fails('normal! gRx', 'E21:')
  2976. call assert_nobeep("normal! gr\<Esc>")
  2977. set modifiable&
  2978. call assert_nobeep("normal! gr\<Esc>")
  2979. call assert_nobeep("normal! cgr\<Esc>")
  2980. call assert_beeps("normal! cgrx")
  2981. call assert_equal('zxxxx line l', getline(1))
  2982. exe "normal! 2|gr\<C-V>\<Esc>"
  2983. call assert_equal("z\<Esc>xx line l", getline(1))
  2984. call setline(1, 'abcdef')
  2985. exe "normal! 0gr\<C-O>lx"
  2986. call assert_equal("\<C-O>def", getline(1))
  2987. call setline(1, 'abcdef')
  2988. exe "normal! 0gr\<C-G>lx"
  2989. call assert_equal("\<C-G>def", getline(1))
  2990. bwipe!
  2991. endfunc
  2992. func Test_nv_hat_count()
  2993. %bwipeout!
  2994. let l:nr = bufnr('%') + 1
  2995. call assert_fails(':execute "normal! ' . l:nr . '\<C-^>"', 'E92:')
  2996. edit Xfoo
  2997. let l:foo_nr = bufnr('Xfoo')
  2998. edit Xbar
  2999. let l:bar_nr = bufnr('Xbar')
  3000. " Make sure we are not just using the alternate file.
  3001. edit Xbaz
  3002. call feedkeys(l:foo_nr . "\<C-^>", 'tx')
  3003. call assert_equal('Xfoo', fnamemodify(bufname('%'), ':t'))
  3004. call feedkeys(l:bar_nr . "\<C-^>", 'tx')
  3005. call assert_equal('Xbar', fnamemodify(bufname('%'), ':t'))
  3006. %bwipeout!
  3007. endfunc
  3008. func Test_message_when_using_ctrl_c()
  3009. " Make sure no buffers are changed.
  3010. %bwipe!
  3011. exe "normal \<C-C>"
  3012. call assert_match("Type :qa and press <Enter> to exit Nvim", Screenline(&lines))
  3013. new
  3014. cal setline(1, 'hi!')
  3015. exe "normal \<C-C>"
  3016. call assert_match("Type :qa! and press <Enter> to abandon all changes and exit Nvim", Screenline(&lines))
  3017. bwipe!
  3018. endfunc
  3019. func Test_mode_updated_after_ctrl_c()
  3020. CheckScreendump
  3021. let buf = RunVimInTerminal('', {'rows': 5})
  3022. call term_sendkeys(buf, "i")
  3023. call term_sendkeys(buf, "\<C-O>")
  3024. " wait a moment so that the "-- (insert) --" message is displayed
  3025. call TermWait(buf, 50)
  3026. call term_sendkeys(buf, "\<C-C>")
  3027. call VerifyScreenDump(buf, 'Test_mode_updated_1', {})
  3028. call StopVimInTerminal(buf)
  3029. endfunc
  3030. " Test for '[m', ']m', '[M' and ']M'
  3031. " Jumping to beginning and end of methods in Java-like languages
  3032. func Test_java_motion()
  3033. new
  3034. call assert_beeps('normal! [m')
  3035. call assert_beeps('normal! ]m')
  3036. call assert_beeps('normal! [M')
  3037. call assert_beeps('normal! ]M')
  3038. let lines =<< trim [CODE]
  3039. Piece of Java
  3040. {
  3041. tt m1 {
  3042. t1;
  3043. } e1
  3044. tt m2 {
  3045. t2;
  3046. } e2
  3047. tt m3 {
  3048. if (x)
  3049. {
  3050. t3;
  3051. }
  3052. } e3
  3053. }
  3054. [CODE]
  3055. call setline(1, lines)
  3056. normal gg
  3057. normal 2]maA
  3058. call assert_equal("\ttt m1 {A", getline('.'))
  3059. call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')])
  3060. normal j]maB
  3061. call assert_equal("\ttt m2 {B", getline('.'))
  3062. call assert_equal([7, 9, 16], [line('.'), col('.'), virtcol('.')])
  3063. normal ]maC
  3064. call assert_equal("\ttt m3 {C", getline('.'))
  3065. call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')])
  3066. normal [maD
  3067. call assert_equal("\ttt m3 {DC", getline('.'))
  3068. call assert_equal([11, 9, 16], [line('.'), col('.'), virtcol('.')])
  3069. normal k2[maE
  3070. call assert_equal("\ttt m1 {EA", getline('.'))
  3071. call assert_equal([3, 9, 16], [line('.'), col('.'), virtcol('.')])
  3072. normal 3[maF
  3073. call assert_equal("{F", getline('.'))
  3074. call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')])
  3075. normal ]MaG
  3076. call assert_equal("\t}G e1", getline('.'))
  3077. call assert_equal([5, 3, 10], [line('.'), col('.'), virtcol('.')])
  3078. normal j2]MaH
  3079. call assert_equal("\t}H e3", getline('.'))
  3080. call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')])
  3081. normal ]M]M
  3082. normal aI
  3083. call assert_equal("}I", getline('.'))
  3084. call assert_equal([17, 2, 2], [line('.'), col('.'), virtcol('.')])
  3085. normal 2[MaJ
  3086. call assert_equal("\t}JH e3", getline('.'))
  3087. call assert_equal([16, 3, 10], [line('.'), col('.'), virtcol('.')])
  3088. normal k[MaK
  3089. call assert_equal("\t}K e2", getline('.'))
  3090. call assert_equal([9, 3, 10], [line('.'), col('.'), virtcol('.')])
  3091. normal 3[MaL
  3092. call assert_equal("{LF", getline('.'))
  3093. call assert_equal([2, 2, 2], [line('.'), col('.'), virtcol('.')])
  3094. call cursor(2, 1)
  3095. call assert_beeps('norm! 5]m')
  3096. " jumping to a method in a fold should open the fold
  3097. 6,10fold
  3098. call feedkeys("gg3]m", 'xt')
  3099. call assert_equal([7, 8, 15], [line('.'), col('.'), virtcol('.')])
  3100. call assert_equal(-1, foldclosedend(7))
  3101. bwipe!
  3102. endfunc
  3103. " Tests for g cmds
  3104. func Test_normal_gdollar_cmd()
  3105. call Setup_NewWindow()
  3106. " Make long lines that will wrap
  3107. %s/$/\=repeat(' foobar', 10)/
  3108. 20vsp
  3109. set wrap
  3110. " Test for g$ with count
  3111. norm! gg
  3112. norm! 0vg$y
  3113. call assert_equal(20, col("'>"))
  3114. call assert_equal('1 foobar foobar foob', getreg(0))
  3115. norm! gg
  3116. norm! 0v4g$y
  3117. call assert_equal(72, col("'>"))
  3118. call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.."\n", getreg(0))
  3119. norm! gg
  3120. norm! 0v6g$y
  3121. call assert_equal(40, col("'>"))
  3122. call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
  3123. \ '2 foobar foobar foobar foobar foobar foo', getreg(0))
  3124. set nowrap
  3125. " clean up
  3126. norm! gg
  3127. norm! 0vg$y
  3128. call assert_equal(20, col("'>"))
  3129. call assert_equal('1 foobar foobar foob', getreg(0))
  3130. norm! gg
  3131. norm! 0v4g$y
  3132. call assert_equal(20, col("'>"))
  3133. call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
  3134. \ '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
  3135. \ '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
  3136. \ '4 foobar foobar foob', getreg(0))
  3137. norm! gg
  3138. norm! 0v6g$y
  3139. call assert_equal(20, col("'>"))
  3140. call assert_equal('1 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
  3141. \ '2 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
  3142. \ '3 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
  3143. \ '4 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
  3144. \ '5 foobar foobar foobar foobar foobar foobar foobar foobar foobar foobar'.. "\n"..
  3145. \ '6 foobar foobar foob', getreg(0))
  3146. " Move to last line, also down movement is not possible, should still move
  3147. " the cursor to the last visible char
  3148. norm! G
  3149. norm! 0v6g$y
  3150. call assert_equal(20, col("'>"))
  3151. call assert_equal('100 foobar foobar fo', getreg(0))
  3152. bw!
  3153. endfunc
  3154. func Test_normal_gk_gj()
  3155. " needs 80 column new window
  3156. new
  3157. vert 80new
  3158. call assert_beeps('normal gk')
  3159. put =[repeat('x',90)..' {{{1', 'x {{{1']
  3160. norm! gk
  3161. " In a 80 column wide terminal the window will be only 78 char
  3162. " (because Vim will leave space for the other window),
  3163. " but if the terminal is larger, it will be 80 chars, so verify the
  3164. " cursor column correctly.
  3165. call assert_equal(winwidth(0)+1, col('.'))
  3166. call assert_equal(winwidth(0)+1, virtcol('.'))
  3167. norm! j
  3168. call assert_equal(6, col('.'))
  3169. call assert_equal(6, virtcol('.'))
  3170. norm! gk
  3171. call assert_equal(95, col('.'))
  3172. call assert_equal(95, virtcol('.'))
  3173. %bw!
  3174. " needs 80 column new window
  3175. new
  3176. vert 80new
  3177. call assert_beeps('normal gj')
  3178. set number
  3179. set numberwidth=10
  3180. set cpoptions+=n
  3181. put =[repeat('0',90), repeat('1',90)]
  3182. norm! 075l
  3183. call assert_equal(76, col('.'))
  3184. norm! gk
  3185. call assert_equal(1, col('.'))
  3186. norm! gk
  3187. call assert_equal(76, col('.'))
  3188. norm! gk
  3189. call assert_equal(1, col('.'))
  3190. norm! gj
  3191. call assert_equal(76, col('.'))
  3192. norm! gj
  3193. call assert_equal(1, col('.'))
  3194. norm! gj
  3195. call assert_equal(76, col('.'))
  3196. " When 'nowrap' is set, gk and gj behave like k and j
  3197. set nowrap
  3198. normal! gk
  3199. call assert_equal([2, 76], [line('.'), col('.')])
  3200. normal! gj
  3201. call assert_equal([3, 76], [line('.'), col('.')])
  3202. %bw!
  3203. set cpoptions& number& numberwidth& wrap&
  3204. endfunc
  3205. " Test for using : to run a multi-line Ex command in operator pending mode
  3206. func Test_normal_yank_with_excmd()
  3207. new
  3208. call setline(1, ['foo', 'bar', 'baz'])
  3209. let @a = ''
  3210. call feedkeys("\"ay:if v:true\<CR>normal l\<CR>endif\<CR>", 'xt')
  3211. call assert_equal('f', @a)
  3212. bwipe!
  3213. endfunc
  3214. " Test for supplying a count to a normal-mode command across a cursorhold call
  3215. func Test_normal_cursorhold_with_count()
  3216. throw 'Skipped: Nvim removed <CursorHold> key'
  3217. func s:cHold()
  3218. let g:cHold_Called += 1
  3219. endfunc
  3220. new
  3221. augroup normalcHoldTest
  3222. au!
  3223. au CursorHold <buffer> call s:cHold()
  3224. augroup END
  3225. let g:cHold_Called = 0
  3226. call feedkeys("3\<CursorHold>2ix", 'xt')
  3227. call assert_equal(1, g:cHold_Called)
  3228. call assert_equal(repeat('x', 32), getline(1))
  3229. augroup normalcHoldTest
  3230. au!
  3231. augroup END
  3232. au! normalcHoldTest
  3233. bwipe!
  3234. delfunc s:cHold
  3235. endfunc
  3236. " Test for using a count and a command with CTRL-W
  3237. func Test_wincmd_with_count()
  3238. call feedkeys("\<C-W>12n", 'xt')
  3239. call assert_equal(12, winheight(0))
  3240. endfunc
  3241. " Test for 'b', 'B' 'ge' and 'gE' commands
  3242. func Test_horiz_motion()
  3243. new
  3244. normal! gg
  3245. call assert_beeps('normal! b')
  3246. call assert_beeps('normal! B')
  3247. call assert_beeps('normal! gE')
  3248. call assert_beeps('normal! ge')
  3249. " <S-Backspace> moves one word left and <C-Backspace> moves one WORD left
  3250. call setline(1, 'one ,two ,three')
  3251. exe "normal! $\<S-BS>"
  3252. call assert_equal(11, col('.'))
  3253. exe "normal! $\<C-BS>"
  3254. call assert_equal(10, col('.'))
  3255. bwipe!
  3256. endfunc
  3257. " Test for using a ":" command in operator pending mode
  3258. func Test_normal_colon_op()
  3259. new
  3260. call setline(1, ['one', 'two'])
  3261. call assert_beeps("normal! Gc:d\<CR>")
  3262. call assert_equal(['one'], getline(1, '$'))
  3263. call setline(1, ['one…two…three!'])
  3264. normal! $
  3265. " Using ":" as a movement is characterwise exclusive
  3266. call feedkeys("d:normal! F…\<CR>", 'xt')
  3267. call assert_equal(['one…two!'], getline(1, '$'))
  3268. " Check that redoing a command with 0x80 bytes works
  3269. call feedkeys('.', 'xt')
  3270. call assert_equal(['one!'], getline(1, '$'))
  3271. call setline(1, ['one', 'two', 'three', 'four', 'five'])
  3272. " Add this to the command history
  3273. call feedkeys(":normal! G0\<CR>", 'xt')
  3274. " Use :normal! with control characters in operator pending mode
  3275. call feedkeys("d:normal! \<C-V>\<C-P>\<C-V>\<C-P>\<CR>", 'xt')
  3276. call assert_equal(['one', 'two', 'five'], getline(1, '$'))
  3277. " Check that redoing a command with control characters works
  3278. call feedkeys('.', 'xt')
  3279. call assert_equal(['five'], getline(1, '$'))
  3280. bwipe!
  3281. endfunc
  3282. " Test for d and D commands
  3283. func Test_normal_delete_cmd()
  3284. new
  3285. " D in an empty line
  3286. call setline(1, '')
  3287. normal D
  3288. call assert_equal('', getline(1))
  3289. " D in an empty line in virtualedit mode
  3290. set virtualedit=all
  3291. normal D
  3292. call assert_equal('', getline(1))
  3293. set virtualedit&
  3294. " delete to a readonly register
  3295. call setline(1, ['abcd'])
  3296. call assert_beeps('normal ":d2l')
  3297. " D and d with 'nomodifiable'
  3298. call setline(1, ['abcd'])
  3299. setlocal nomodifiable
  3300. call assert_fails('normal D', 'E21:')
  3301. call assert_fails('normal d$', 'E21:')
  3302. bwipe!
  3303. endfunc
  3304. " Test for deleting or changing characters across lines with 'whichwrap'
  3305. " containing 's'. Should count <EOL> as one character.
  3306. func Test_normal_op_across_lines()
  3307. new
  3308. set whichwrap&
  3309. call setline(1, ['one two', 'three four'])
  3310. exe "norm! $3d\<Space>"
  3311. call assert_equal(['one twhree four'], getline(1, '$'))
  3312. call setline(1, ['one two', 'three four'])
  3313. exe "norm! $3c\<Space>x"
  3314. call assert_equal(['one twxhree four'], getline(1, '$'))
  3315. set whichwrap+=l
  3316. call setline(1, ['one two', 'three four'])
  3317. exe "norm! $3x"
  3318. call assert_equal(['one twhree four'], getline(1, '$'))
  3319. bwipe!
  3320. set whichwrap&
  3321. endfunc
  3322. " Test for 'w' and 'b' commands
  3323. func Test_normal_word_move()
  3324. new
  3325. call setline(1, ['foo bar a', '', 'foo bar b'])
  3326. " copy a single character word at the end of a line
  3327. normal 1G$yw
  3328. call assert_equal('a', @")
  3329. " copy a single character word at the end of a file
  3330. normal G$yw
  3331. call assert_equal('b', @")
  3332. " check for a word movement handling an empty line properly
  3333. normal 1G$vwy
  3334. call assert_equal("a\n\n", @")
  3335. " copy using 'b' command
  3336. %d
  3337. " non-empty blank line at the start of file
  3338. call setline(1, [' ', 'foo bar'])
  3339. normal 2Gyb
  3340. call assert_equal(" \n", @")
  3341. " try to copy backwards from the start of the file
  3342. call setline(1, ['one two', 'foo bar'])
  3343. call assert_beeps('normal ggyb')
  3344. " 'b' command should stop at an empty line
  3345. call setline(1, ['one two', '', 'foo bar'])
  3346. normal 3Gyb
  3347. call assert_equal("\n", @")
  3348. normal 3Gy2b
  3349. call assert_equal("two\n", @")
  3350. " 'b' command should not stop at a non-empty blank line
  3351. call setline(1, ['one two', ' ', 'foo bar'])
  3352. normal 3Gyb
  3353. call assert_equal("two\n ", @")
  3354. bwipe!
  3355. endfunc
  3356. " Test for 'scrolloff' with a long line that doesn't fit in the screen
  3357. func Test_normal_scrolloff()
  3358. 10new
  3359. 60vnew
  3360. call setline(1, ' 1 ' .. repeat('a', 57)
  3361. \ .. ' 2 ' .. repeat('b', 57)
  3362. \ .. ' 3 ' .. repeat('c', 57)
  3363. \ .. ' 4 ' .. repeat('d', 57)
  3364. \ .. ' 5 ' .. repeat('e', 57)
  3365. \ .. ' 6 ' .. repeat('f', 57)
  3366. \ .. ' 7 ' .. repeat('g', 57)
  3367. \ .. ' 8 ' .. repeat('h', 57)
  3368. \ .. ' 9 ' .. repeat('i', 57)
  3369. \ .. '10 ' .. repeat('j', 57)
  3370. \ .. '11 ' .. repeat('k', 57)
  3371. \ .. '12 ' .. repeat('l', 57)
  3372. \ .. '13 ' .. repeat('m', 57)
  3373. \ .. '14 ' .. repeat('n', 57)
  3374. \ .. '15 ' .. repeat('o', 57)
  3375. \ .. '16 ' .. repeat('p', 57)
  3376. \ .. '17 ' .. repeat('q', 57)
  3377. \ .. '18 ' .. repeat('r', 57)
  3378. \ .. '19 ' .. repeat('s', 57)
  3379. \ .. '20 ' .. repeat('t', 57)
  3380. \ .. '21 ' .. repeat('u', 57)
  3381. \ .. '22 ' .. repeat('v', 57)
  3382. \ .. '23 ' .. repeat('w', 57)
  3383. \ .. '24 ' .. repeat('x', 57)
  3384. \ .. '25 ' .. repeat('y', 57)
  3385. \ .. '26 ' .. repeat('z', 57)
  3386. \ )
  3387. set scrolloff=10
  3388. normal gg10gj
  3389. call assert_equal(6, winline())
  3390. normal 10gj
  3391. call assert_equal(6, winline())
  3392. normal 10gk
  3393. call assert_equal(6, winline())
  3394. normal 0
  3395. call assert_equal(1, winline())
  3396. normal $
  3397. call assert_equal(10, winline())
  3398. set scrolloff&
  3399. bwipe!
  3400. endfunc
  3401. " Test for vertical scrolling with CTRL-F and CTRL-B with a long line
  3402. func Test_normal_vert_scroll_longline()
  3403. 10new
  3404. 80vnew
  3405. call setline(1, range(1, 10))
  3406. call append(5, repeat('a', 1000))
  3407. exe "normal gg\<C-F>"
  3408. call assert_equal(6, line('.'))
  3409. exe "normal \<C-F>\<C-F>"
  3410. call assert_equal(11, line('.'))
  3411. call assert_equal(1, winline())
  3412. exe "normal \<C-B>"
  3413. call assert_equal(11, line('.'))
  3414. call assert_equal(5, winline())
  3415. exe "normal \<C-B>\<C-B>"
  3416. call assert_equal(5, line('.'))
  3417. call assert_equal(5, winline())
  3418. bwipe!
  3419. endfunc
  3420. " Test for jumping in a file using %
  3421. func Test_normal_percent_jump()
  3422. new
  3423. call setline(1, range(1, 100))
  3424. " jumping to a folded line should open the fold
  3425. 25,75fold
  3426. call feedkeys('50%', 'xt')
  3427. call assert_equal(50, line('.'))
  3428. call assert_equal(-1, foldclosedend(50))
  3429. bwipe!
  3430. endfunc
  3431. " Test for << and >> commands to shift text by 'shiftwidth'
  3432. func Test_normal_shift_rightleft()
  3433. new
  3434. call setline(1, ['one', '', "\t", ' two', "\tthree", ' four'])
  3435. set shiftwidth=2 tabstop=8
  3436. normal gg6>>
  3437. call assert_equal([' one', '', "\t ", ' two', "\t three", "\tfour"],
  3438. \ getline(1, '$'))
  3439. normal ggVG2>>
  3440. call assert_equal([' one', '', "\t ", "\ttwo",
  3441. \ "\t three", "\t four"], getline(1, '$'))
  3442. normal gg6<<
  3443. call assert_equal([' one', '', "\t ", ' two', "\t three",
  3444. \ "\t four"], getline(1, '$'))
  3445. normal ggVG2<<
  3446. call assert_equal(['one', '', "\t", ' two', "\tthree", ' four'],
  3447. \ getline(1, '$'))
  3448. set shiftwidth& tabstop&
  3449. bw!
  3450. endfunc
  3451. " Some commands like yy, cc, dd, >>, << and !! accept a count after
  3452. " typing the first letter of the command.
  3453. func Test_normal_count_after_operator()
  3454. new
  3455. setlocal shiftwidth=4 tabstop=8 autoindent
  3456. call setline(1, ['one', 'two', 'three', 'four', 'five'])
  3457. let @a = ''
  3458. normal! j"ay4y
  3459. call assert_equal("two\nthree\nfour\nfive\n", @a)
  3460. normal! 3G>2>
  3461. call assert_equal(['one', 'two', ' three', ' four', 'five'],
  3462. \ getline(1, '$'))
  3463. exe "normal! 3G0c2cred\nblue"
  3464. call assert_equal(['one', 'two', ' red', ' blue', 'five'],
  3465. \ getline(1, '$'))
  3466. exe "normal! gg<8<"
  3467. call assert_equal(['one', 'two', 'red', 'blue', 'five'],
  3468. \ getline(1, '$'))
  3469. exe "normal! ggd3d"
  3470. call assert_equal(['blue', 'five'], getline(1, '$'))
  3471. call setline(1, range(1, 4))
  3472. call feedkeys("gg!3!\<C-B>\"\<CR>", 'xt')
  3473. call assert_equal('".,.+2!', @:)
  3474. call feedkeys("gg!1!\<C-B>\"\<CR>", 'xt')
  3475. call assert_equal('".!', @:)
  3476. call feedkeys("gg!9!\<C-B>\"\<CR>", 'xt')
  3477. call assert_equal('".,$!', @:)
  3478. bw!
  3479. endfunc
  3480. func Test_normal_gj_on_6_cell_wide_unprintable_char()
  3481. new | 25vsp
  3482. let text='1 foooooooo ar e ins​zwe1 foooooooo ins​zwei' .
  3483. \ ' i drei vier fünf sechs sieben acht un zehn elf zwöfl' .
  3484. \ ' dreizehn v ierzehn fünfzehn'
  3485. put =text
  3486. call cursor(2,1)
  3487. norm! gj
  3488. call assert_equal([0,2,25,0], getpos('.'))
  3489. bw!
  3490. endfunc
  3491. func Test_normal_count_out_of_range()
  3492. new
  3493. call setline(1, 'text')
  3494. normal 44444444444|
  3495. call assert_equal(999999999, v:count)
  3496. normal 444444444444|
  3497. call assert_equal(999999999, v:count)
  3498. normal 4444444444444|
  3499. call assert_equal(999999999, v:count)
  3500. normal 4444444444444444444|
  3501. call assert_equal(999999999, v:count)
  3502. normal 9y99999999|
  3503. call assert_equal(899999991, v:count)
  3504. normal 10y99999999|
  3505. call assert_equal(999999999, v:count)
  3506. normal 44444444444y44444444444|
  3507. call assert_equal(999999999, v:count)
  3508. bwipe!
  3509. endfunc
  3510. " Test that mouse shape is restored to Normal mode after failed "c" operation.
  3511. func Test_mouse_shape_after_failed_change()
  3512. CheckFeature mouseshape
  3513. CheckCanRunGui
  3514. let lines =<< trim END
  3515. vim9script
  3516. set mouseshape+=o:busy
  3517. setlocal nomodifiable
  3518. var mouse_shapes = []
  3519. feedkeys('c')
  3520. timer_start(50, (_) => {
  3521. mouse_shapes += [getmouseshape()]
  3522. timer_start(50, (_) => {
  3523. feedkeys('c')
  3524. timer_start(50, (_) => {
  3525. mouse_shapes += [getmouseshape()]
  3526. timer_start(50, (_) => {
  3527. writefile(mouse_shapes, 'Xmouseshapes')
  3528. quit
  3529. })
  3530. })
  3531. })
  3532. })
  3533. END
  3534. call writefile(lines, 'Xmouseshape.vim', 'D')
  3535. call RunVim([], [], "-g -S Xmouseshape.vim")
  3536. call WaitForAssert({-> assert_equal(['busy', 'arrow'], readfile('Xmouseshapes'))}, 300)
  3537. call delete('Xmouseshapes')
  3538. endfunc
  3539. " Test that mouse shape is restored to Normal mode after cancelling "gr".
  3540. func Test_mouse_shape_after_cancelling_gr()
  3541. CheckFeature mouseshape
  3542. CheckCanRunGui
  3543. let lines =<< trim END
  3544. vim9script
  3545. var mouse_shapes = []
  3546. feedkeys('gr')
  3547. timer_start(50, (_) => {
  3548. mouse_shapes += [getmouseshape()]
  3549. timer_start(50, (_) => {
  3550. feedkeys("\<Esc>")
  3551. timer_start(50, (_) => {
  3552. mouse_shapes += [getmouseshape()]
  3553. timer_start(50, (_) => {
  3554. writefile(mouse_shapes, 'Xmouseshapes')
  3555. quit
  3556. })
  3557. })
  3558. })
  3559. })
  3560. END
  3561. call writefile(lines, 'Xmouseshape.vim', 'D')
  3562. call RunVim([], [], "-g -S Xmouseshape.vim")
  3563. call WaitForAssert({-> assert_equal(['beam', 'arrow'], readfile('Xmouseshapes'))}, 300)
  3564. call delete('Xmouseshapes')
  3565. endfunc
  3566. " Test that "j" does not skip lines when scrolling below botline and
  3567. " 'foldmethod' is not "manual".
  3568. func Test_normal_j_below_botline()
  3569. CheckScreendump
  3570. let lines =<< trim END
  3571. set number foldmethod=diff scrolloff=0
  3572. call setline(1, map(range(1, 9), 'repeat(v:val, 200)'))
  3573. norm Lj
  3574. END
  3575. call writefile(lines, 'XNormalJBelowBotline', 'D')
  3576. let buf = RunVimInTerminal('-S XNormalJBelowBotline', #{rows: 19, cols: 40})
  3577. call VerifyScreenDump(buf, 'Test_normal_j_below_botline', {})
  3578. call StopVimInTerminal(buf)
  3579. endfunc
  3580. " Test for r (replace) command with CTRL_V and CTRL_Q
  3581. func Test_normal_r_ctrl_v_cmd()
  3582. new
  3583. call append(0, 'This is a simple test: abcd')
  3584. exe "norm! 1gg$r\<C-V>\<C-V>"
  3585. call assert_equal(['This is a simple test: abc', ''], getline(1,'$'))
  3586. exe "norm! 1gg$hr\<C-Q>\<C-Q>"
  3587. call assert_equal(['This is a simple test: ab', ''], getline(1,'$'))
  3588. exe "norm! 1gg$2hr\<C-V>x7e"
  3589. call assert_equal(['This is a simple test: a~', ''], getline(1,'$'))
  3590. exe "norm! 1gg$3hr\<C-Q>x7e"
  3591. call assert_equal(['This is a simple test: ~~', ''], getline(1,'$'))
  3592. if &encoding == 'utf-8'
  3593. exe "norm! 1gg$4hr\<C-V>u20ac"
  3594. call assert_equal(['This is a simple test:€~~', ''], getline(1,'$'))
  3595. exe "norm! 1gg$5hr\<C-Q>u20ac"
  3596. call assert_equal(['This is a simple test€€~~', ''], getline(1,'$'))
  3597. exe "norm! 1gg0R\<C-V>xff WAS \<esc>"
  3598. call assert_equal(['ÿ WAS a simple test€€~~', ''], getline(1,'$'))
  3599. exe "norm! 1gg0elR\<C-Q>xffNOT\<esc>"
  3600. call assert_equal(['ÿ WASÿNOT simple test€€~~', ''], getline(1,'$'))
  3601. endif
  3602. call setline(1, 'This is a simple test: abcd')
  3603. exe "norm! 1gg$gr\<C-V>\<C-V>"
  3604. call assert_equal(['This is a simple test: abc', ''], getline(1,'$'))
  3605. exe "norm! 1gg$hgr\<C-Q>\<C-Q>"
  3606. call assert_equal(['This is a simple test: ab ', ''], getline(1,'$'))
  3607. exe "norm! 1gg$2hgr\<C-V>x7e"
  3608. call assert_equal(['This is a simple test: a~ ', ''], getline(1,'$'))
  3609. exe "norm! 1gg$3hgr\<C-Q>x7e"
  3610. call assert_equal(['This is a simple test: ~~ ', ''], getline(1,'$'))
  3611. " clean up
  3612. bw!
  3613. endfunc
  3614. " Test clicking on a TAB or an unprintable character in Normal mode
  3615. func Test_normal_click_on_ctrl_char()
  3616. let save_mouse = &mouse
  3617. set mouse=a
  3618. new
  3619. call setline(1, "a\<Tab>b\<C-K>c")
  3620. redraw
  3621. call Ntest_setmouse(1, 1)
  3622. call feedkeys("\<LeftMouse>", 'xt')
  3623. call assert_equal([0, 1, 1, 0, 1], getcurpos())
  3624. call Ntest_setmouse(1, 2)
  3625. call feedkeys("\<LeftMouse>", 'xt')
  3626. call assert_equal([0, 1, 2, 0, 2], getcurpos())
  3627. call Ntest_setmouse(1, 3)
  3628. call feedkeys("\<LeftMouse>", 'xt')
  3629. call assert_equal([0, 1, 2, 0, 3], getcurpos())
  3630. call Ntest_setmouse(1, 7)
  3631. call feedkeys("\<LeftMouse>", 'xt')
  3632. call assert_equal([0, 1, 2, 0, 7], getcurpos())
  3633. call Ntest_setmouse(1, 8)
  3634. call feedkeys("\<LeftMouse>", 'xt')
  3635. call assert_equal([0, 1, 2, 0, 8], getcurpos())
  3636. call Ntest_setmouse(1, 9)
  3637. call feedkeys("\<LeftMouse>", 'xt')
  3638. call assert_equal([0, 1, 3, 0, 9], getcurpos())
  3639. call Ntest_setmouse(1, 10)
  3640. call feedkeys("\<LeftMouse>", 'xt')
  3641. call assert_equal([0, 1, 4, 0, 10], getcurpos())
  3642. call Ntest_setmouse(1, 11)
  3643. call feedkeys("\<LeftMouse>", 'xt')
  3644. call assert_equal([0, 1, 4, 0, 11], getcurpos())
  3645. call Ntest_setmouse(1, 12)
  3646. call feedkeys("\<LeftMouse>", 'xt')
  3647. call assert_equal([0, 1, 5, 0, 12], getcurpos())
  3648. call Ntest_setmouse(1, 13)
  3649. call feedkeys("\<LeftMouse>", 'xt')
  3650. call assert_equal([0, 1, 5, 0, 13], getcurpos())
  3651. bwipe!
  3652. let &mouse = save_mouse
  3653. endfunc
  3654. " Test clicking on a double-width character in Normal mode
  3655. func Test_normal_click_on_double_width_char()
  3656. let save_mouse = &mouse
  3657. set mouse=a
  3658. new
  3659. call setline(1, "口口")
  3660. redraw
  3661. call Ntest_setmouse(1, 1)
  3662. call feedkeys("\<LeftMouse>", 'xt')
  3663. call assert_equal([0, 1, 1, 0, 1], getcurpos())
  3664. call Ntest_setmouse(1, 2)
  3665. call feedkeys("\<LeftMouse>", 'xt')
  3666. call assert_equal([0, 1, 1, 0, 2], getcurpos())
  3667. call Ntest_setmouse(1, 3)
  3668. call feedkeys("\<LeftMouse>", 'xt')
  3669. call assert_equal([0, 1, 4, 0, 3], getcurpos())
  3670. call Ntest_setmouse(1, 4)
  3671. call feedkeys("\<LeftMouse>", 'xt')
  3672. call assert_equal([0, 1, 4, 0, 4], getcurpos())
  3673. bwipe!
  3674. let &mouse = save_mouse
  3675. endfunc
  3676. func Test_normal_click_on_empty_line()
  3677. let save_mouse = &mouse
  3678. set mouse=a
  3679. botright new
  3680. call setline(1, ['', '', ''])
  3681. let row = win_screenpos(0)[0] + 2
  3682. 20vsplit
  3683. redraw
  3684. call Ntest_setmouse(row, 1)
  3685. call feedkeys("\<LeftMouse>", 'xt')
  3686. call assert_equal([0, 3, 1, 0, 1], getcurpos())
  3687. call Ntest_setmouse(row, 2)
  3688. call feedkeys("\<LeftMouse>", 'xt')
  3689. call assert_equal([0, 3, 1, 0, 2], getcurpos())
  3690. call Ntest_setmouse(row, 10)
  3691. call feedkeys("\<LeftMouse>", 'xt')
  3692. call assert_equal([0, 3, 1, 0, 10], getcurpos())
  3693. call Ntest_setmouse(row, 21 + 1)
  3694. call feedkeys("\<LeftMouse>", 'xt')
  3695. call assert_equal([0, 3, 1, 0, 1], getcurpos())
  3696. call Ntest_setmouse(row, 21 + 2)
  3697. call feedkeys("\<LeftMouse>", 'xt')
  3698. call assert_equal([0, 3, 1, 0, 2], getcurpos())
  3699. call Ntest_setmouse(row, 21 + 10)
  3700. call feedkeys("\<LeftMouse>", 'xt')
  3701. call assert_equal([0, 3, 1, 0, 10], getcurpos())
  3702. bwipe!
  3703. let &mouse = save_mouse
  3704. endfunc
  3705. func Test_normal33_g_cmd_nonblank()
  3706. " Test that g<End> goes to the last non-blank char and g$ to the last
  3707. " visible column
  3708. 20vnew
  3709. setlocal nowrap nonumber signcolumn=no
  3710. call setline(1, ['fooo fooo fooo fooo fooo fooo fooo fooo '])
  3711. exe "normal 0g\<End>"
  3712. call assert_equal(11, col('.'))
  3713. normal 0g$
  3714. call assert_equal(20, col('.'))
  3715. exe "normal 0g\<kEnd>"
  3716. call assert_equal(11, col('.'))
  3717. setlocal wrap
  3718. exe "normal 0g\<End>"
  3719. call assert_equal(11, col('.'))
  3720. normal 0g$
  3721. call assert_equal(20, col('.'))
  3722. exe "normal 0g\<kEnd>"
  3723. call assert_equal(11, col('.'))
  3724. bw!
  3725. endfunc
  3726. func Test_normal34_zet_large()
  3727. " shouldn't cause overflow
  3728. norm! z9765405999999999999
  3729. endfunc
  3730. " Test for { and } paragraph movements in a single line
  3731. func Test_brace_single_line()
  3732. new
  3733. call setline(1, ['foobar one two three'])
  3734. 1
  3735. norm! 0}
  3736. call assert_equal([0, 1, 20, 0], getpos('.'))
  3737. norm! {
  3738. call assert_equal([0, 1, 1, 0], getpos('.'))
  3739. bw!
  3740. endfunc
  3741. " Test for Ctrl-B/Ctrl-U in buffer with a single line
  3742. func Test_single_line_scroll()
  3743. CheckFeature textprop
  3744. new
  3745. call setline(1, ['foobar one two three'])
  3746. let vt = 'virt_above'
  3747. call prop_type_add(vt, {'highlight': 'IncSearch'})
  3748. call prop_add(1, 0, {'type': vt, 'text': '---', 'text_align': 'above'})
  3749. call cursor(1, 1)
  3750. " Ctrl-B/Ctrl-U scroll up with hidden "above" virtual text.
  3751. set smoothscroll
  3752. exe "normal \<C-E>"
  3753. call assert_notequal(0, winsaveview().skipcol)
  3754. exe "normal \<C-B>"
  3755. call assert_equal(0, winsaveview().skipcol)
  3756. exe "normal \<C-E>"
  3757. call assert_notequal(0, winsaveview().skipcol)
  3758. exe "normal \<C-U>"
  3759. call assert_equal(0, winsaveview().skipcol)
  3760. set smoothscroll&
  3761. bw!
  3762. call prop_type_delete(vt)
  3763. endfunc
  3764. " Test for zb in buffer with a single line and filler lines
  3765. func Test_single_line_filler_zb()
  3766. call setline(1, ['', 'foobar one two three'])
  3767. diffthis
  3768. new
  3769. call setline(1, ['foobar one two three'])
  3770. diffthis
  3771. " zb scrolls to reveal filler lines at the start of the buffer.
  3772. exe "normal \<C-E>zb"
  3773. call assert_equal(1, winsaveview().topfill)
  3774. bw!
  3775. endfunc
  3776. " Test for Ctrl-U not getting stuck at end of buffer with 'scrolloff'.
  3777. func Test_halfpage_scrolloff_eob()
  3778. set scrolloff=5
  3779. call setline(1, range(1, 100))
  3780. exe "norm! Gzz\<C-U>zz"
  3781. call assert_notequal(100, line('.'))
  3782. set scrolloff&
  3783. bwipe!
  3784. endfunc
  3785. " Test for Ctrl-U/D moving the cursor at the buffer boundaries.
  3786. func Test_halfpage_cursor_startend()
  3787. call setline(1, range(1, 100))
  3788. exe "norm! jztj\<C-U>"
  3789. call assert_equal(1, line('.'))
  3790. exe "norm! G\<C-Y>k\<C-D>"
  3791. call assert_equal(100, line('.'))
  3792. bwipe!
  3793. endfunc
  3794. " Test for Ctrl-F/B moving the cursor to the window boundaries.
  3795. func Test_page_cursor_topbot()
  3796. 10new
  3797. call setline(1, range(1, 100))
  3798. exe "norm! gg2\<C-F>"
  3799. call assert_equal(17, line('.'))
  3800. exe "norm! \<C-B>"
  3801. call assert_equal(18, line('.'))
  3802. exe "norm! \<C-B>\<C-F>"
  3803. call assert_equal(9, line('.'))
  3804. " Not when already at the start of the buffer.
  3805. exe "norm! ggj\<C-B>"
  3806. call assert_equal(2, line('.'))
  3807. bwipe!
  3808. endfunc
  3809. " Test for Ctrl-D with long line
  3810. func Test_halfpage_longline()
  3811. 10new
  3812. 40vsplit
  3813. call setline(1, ['long'->repeat(1000), 'short'])
  3814. exe "norm! \<C-D>"
  3815. call assert_equal(2, line('.'))
  3816. bwipe!
  3817. endfunc
  3818. " Test for Ctrl-E with long line and very narrow window,
  3819. " used to cause an infinite loop
  3820. func Test_scroll_longline_no_loop()
  3821. 4vnew
  3822. setl smoothscroll number showbreak=> scrolloff=2
  3823. call setline(1, repeat(['Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'], 3))
  3824. exe "normal! \<C-E>"
  3825. bwipe!
  3826. endfunc
  3827. " Test for go command
  3828. func Test_normal_go()
  3829. new
  3830. call setline(1, ['one two three four'])
  3831. call cursor(1, 5)
  3832. norm! dvgo
  3833. call assert_equal('wo three four', getline(1))
  3834. norm! ...
  3835. call assert_equal('three four', getline(1))
  3836. bwipe!
  3837. endfunc
  3838. " vim: shiftwidth=2 sts=2 expandtab nofoldenable