window_spec.lua 95 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local Screen = require('test.functional.ui.screen')
  4. local clear, curbuf, curbuf_contents, curwin, eq, neq, matches, ok, feed, insert, eval =
  5. n.clear,
  6. n.api.nvim_get_current_buf,
  7. n.curbuf_contents,
  8. n.api.nvim_get_current_win,
  9. t.eq,
  10. t.neq,
  11. t.matches,
  12. t.ok,
  13. n.feed,
  14. n.insert,
  15. n.eval
  16. local poke_eventloop = n.poke_eventloop
  17. local exec = n.exec
  18. local exec_lua = n.exec_lua
  19. local fn = n.fn
  20. local request = n.request
  21. local NIL = vim.NIL
  22. local api = n.api
  23. local command = n.command
  24. local pcall_err = t.pcall_err
  25. local assert_alive = n.assert_alive
  26. describe('API/win', function()
  27. before_each(clear)
  28. describe('get_buf', function()
  29. it('works', function()
  30. eq(curbuf(), api.nvim_win_get_buf(api.nvim_list_wins()[1]))
  31. command('new')
  32. api.nvim_set_current_win(api.nvim_list_wins()[2])
  33. eq(curbuf(), api.nvim_win_get_buf(api.nvim_list_wins()[2]))
  34. neq(
  35. api.nvim_win_get_buf(api.nvim_list_wins()[1]),
  36. api.nvim_win_get_buf(api.nvim_list_wins()[2])
  37. )
  38. end)
  39. end)
  40. describe('set_buf', function()
  41. it('works', function()
  42. command('new')
  43. local windows = api.nvim_list_wins()
  44. neq(api.nvim_win_get_buf(windows[2]), api.nvim_win_get_buf(windows[1]))
  45. api.nvim_win_set_buf(windows[2], api.nvim_win_get_buf(windows[1]))
  46. eq(api.nvim_win_get_buf(windows[2]), api.nvim_win_get_buf(windows[1]))
  47. end)
  48. it('validates args', function()
  49. eq('Invalid buffer id: 23', pcall_err(api.nvim_win_set_buf, api.nvim_get_current_win(), 23))
  50. eq('Invalid window id: 23', pcall_err(api.nvim_win_set_buf, 23, api.nvim_get_current_buf()))
  51. end)
  52. it('disallowed in cmdwin if win=cmdwin_{old_cur}win or buf=cmdwin_buf', function()
  53. local new_buf = api.nvim_create_buf(true, true)
  54. local old_win = api.nvim_get_current_win()
  55. local new_win = api.nvim_open_win(new_buf, false, {
  56. relative = 'editor',
  57. row = 10,
  58. col = 10,
  59. width = 50,
  60. height = 10,
  61. })
  62. feed('q:')
  63. eq(
  64. 'E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
  65. pcall_err(api.nvim_win_set_buf, 0, new_buf)
  66. )
  67. eq(
  68. 'E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
  69. pcall_err(api.nvim_win_set_buf, old_win, new_buf)
  70. )
  71. eq(
  72. 'E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
  73. pcall_err(api.nvim_win_set_buf, new_win, 0)
  74. )
  75. matches(
  76. 'E11: Invalid in command%-line window; <CR> executes, CTRL%-C quits$',
  77. pcall_err(
  78. exec_lua,
  79. [[
  80. local cmdwin_buf = vim.api.nvim_get_current_buf()
  81. local new_win, new_buf = ...
  82. vim._with({buf = new_buf}, function()
  83. vim.api.nvim_win_set_buf(new_win, cmdwin_buf)
  84. end)
  85. ]],
  86. new_win,
  87. new_buf
  88. )
  89. )
  90. matches(
  91. 'E11: Invalid in command%-line window; <CR> executes, CTRL%-C quits$',
  92. pcall_err(
  93. exec_lua,
  94. [[
  95. local cmdwin_win = vim.api.nvim_get_current_win()
  96. local new_win, new_buf = ...
  97. vim._with({win = new_win}, function()
  98. vim.api.nvim_win_set_buf(cmdwin_win, new_buf)
  99. end)
  100. ]],
  101. new_win,
  102. new_buf
  103. )
  104. )
  105. local next_buf = api.nvim_create_buf(true, true)
  106. api.nvim_win_set_buf(new_win, next_buf)
  107. eq(next_buf, api.nvim_win_get_buf(new_win))
  108. end)
  109. describe("with 'autochdir'", function()
  110. local topdir
  111. local otherbuf
  112. local oldwin
  113. local newwin
  114. before_each(function()
  115. command('set shellslash')
  116. topdir = fn.getcwd()
  117. t.mkdir(topdir .. '/Xacd')
  118. t.mkdir(topdir .. '/Xacd/foo')
  119. otherbuf = api.nvim_create_buf(false, true)
  120. api.nvim_buf_set_name(otherbuf, topdir .. '/Xacd/baz.txt')
  121. command('set autochdir')
  122. command('edit Xacd/foo/bar.txt')
  123. eq(topdir .. '/Xacd/foo', fn.getcwd())
  124. oldwin = api.nvim_get_current_win()
  125. command('vsplit')
  126. newwin = api.nvim_get_current_win()
  127. end)
  128. after_each(function()
  129. n.rmdir(topdir .. '/Xacd')
  130. end)
  131. it('does not change cwd with non-current window', function()
  132. api.nvim_win_set_buf(oldwin, otherbuf)
  133. eq(topdir .. '/Xacd/foo', fn.getcwd())
  134. end)
  135. it('changes cwd with current window', function()
  136. api.nvim_win_set_buf(newwin, otherbuf)
  137. eq(topdir .. '/Xacd', fn.getcwd())
  138. end)
  139. end)
  140. end)
  141. describe('{get,set}_cursor', function()
  142. it('works', function()
  143. eq({ 1, 0 }, api.nvim_win_get_cursor(0))
  144. command('normal ityping\027o some text')
  145. eq('typing\n some text', curbuf_contents())
  146. eq({ 2, 10 }, api.nvim_win_get_cursor(0))
  147. api.nvim_win_set_cursor(0, { 2, 6 })
  148. command('normal i dumb')
  149. eq('typing\n some dumb text', curbuf_contents())
  150. end)
  151. it('no memory leak when using invalid window ID with invalid pos', function()
  152. eq('Invalid window id: 1', pcall_err(api.nvim_win_set_cursor, 1, { 'b\na' }))
  153. end)
  154. it('updates the screen, and also when the window is unfocused', function()
  155. local screen = Screen.new(30, 9)
  156. insert('prologue')
  157. feed('100o<esc>')
  158. insert('epilogue')
  159. local win = curwin()
  160. feed('gg')
  161. screen:expect {
  162. grid = [[
  163. ^prologue |
  164. |*8
  165. ]],
  166. }
  167. -- cursor position is at beginning
  168. eq({ 1, 0 }, api.nvim_win_get_cursor(win))
  169. -- move cursor to end
  170. api.nvim_win_set_cursor(win, { 101, 0 })
  171. screen:expect {
  172. grid = [[
  173. |*7
  174. ^epilogue |
  175. |
  176. ]],
  177. }
  178. -- move cursor to the beginning again
  179. api.nvim_win_set_cursor(win, { 1, 0 })
  180. screen:expect {
  181. grid = [[
  182. ^prologue |
  183. |*8
  184. ]],
  185. }
  186. -- move focus to new window
  187. command('new')
  188. neq(win, curwin())
  189. -- sanity check, cursor position is kept
  190. eq({ 1, 0 }, api.nvim_win_get_cursor(win))
  191. screen:expect {
  192. grid = [[
  193. ^ |
  194. {1:~ }|*2
  195. {3:[No Name] }|
  196. prologue |
  197. |*2
  198. {2:[No Name] [+] }|
  199. |
  200. ]],
  201. }
  202. -- move cursor to end
  203. api.nvim_win_set_cursor(win, { 101, 0 })
  204. screen:expect {
  205. grid = [[
  206. ^ |
  207. {1:~ }|*2
  208. {3:[No Name] }|
  209. |*2
  210. epilogue |
  211. {2:[No Name] [+] }|
  212. |
  213. ]],
  214. }
  215. -- move cursor to the beginning again
  216. api.nvim_win_set_cursor(win, { 1, 0 })
  217. screen:expect {
  218. grid = [[
  219. ^ |
  220. {1:~ }|*2
  221. {3:[No Name] }|
  222. prologue |
  223. |*2
  224. {2:[No Name] [+] }|
  225. |
  226. ]],
  227. }
  228. -- curwin didn't change back
  229. neq(win, curwin())
  230. end)
  231. it('remembers what column it wants to be in', function()
  232. insert('first line')
  233. feed('o<esc>')
  234. insert('second line')
  235. feed('gg')
  236. poke_eventloop() -- let nvim process the 'gg' command
  237. -- cursor position is at beginning
  238. local win = curwin()
  239. eq({ 1, 0 }, api.nvim_win_get_cursor(win))
  240. -- move cursor to column 5
  241. api.nvim_win_set_cursor(win, { 1, 5 })
  242. -- move down a line
  243. feed('j')
  244. poke_eventloop() -- let nvim process the 'j' command
  245. -- cursor is still in column 5
  246. eq({ 2, 5 }, api.nvim_win_get_cursor(win))
  247. end)
  248. it('updates cursorline and statusline ruler in non-current window', function()
  249. local screen = Screen.new(60, 8)
  250. command('set ruler')
  251. command('set cursorline')
  252. insert([[
  253. aaa
  254. bbb
  255. ccc
  256. ddd]])
  257. local oldwin = curwin()
  258. command('vsplit')
  259. screen:expect([[
  260. aaa │aaa |
  261. bbb │bbb |
  262. ccc │ccc |
  263. {21:dd^d }│{21:ddd }|
  264. {1:~ }│{1:~ }|*2
  265. {3:[No Name] [+] 4,3 All }{2:[No Name] [+] 4,3 All}|
  266. |
  267. ]])
  268. api.nvim_win_set_cursor(oldwin, { 1, 0 })
  269. screen:expect([[
  270. aaa │{21:aaa }|
  271. bbb │bbb |
  272. ccc │ccc |
  273. {21:dd^d }│ddd |
  274. {1:~ }│{1:~ }|*2
  275. {3:[No Name] [+] 4,3 All }{2:[No Name] [+] 1,1 All}|
  276. |
  277. ]])
  278. end)
  279. it('updates cursorcolumn in non-current window', function()
  280. local screen = Screen.new(60, 8)
  281. command('set cursorcolumn')
  282. insert([[
  283. aaa
  284. bbb
  285. ccc
  286. ddd]])
  287. local oldwin = curwin()
  288. command('vsplit')
  289. screen:expect([[
  290. aa{21:a} │aa{21:a} |
  291. bb{21:b} │bb{21:b} |
  292. cc{21:c} │cc{21:c} |
  293. dd^d │ddd |
  294. {1:~ }│{1:~ }|*2
  295. {3:[No Name] [+] }{2:[No Name] [+] }|
  296. |
  297. ]])
  298. api.nvim_win_set_cursor(oldwin, { 2, 0 })
  299. screen:expect([[
  300. aa{21:a} │{21:a}aa |
  301. bb{21:b} │bbb |
  302. cc{21:c} │{21:c}cc |
  303. dd^d │{21:d}dd |
  304. {1:~ }│{1:~ }|*2
  305. {3:[No Name] [+] }{2:[No Name] [+] }|
  306. |
  307. ]])
  308. end)
  309. end)
  310. describe('{get,set}_height', function()
  311. it('works', function()
  312. command('vsplit')
  313. eq(
  314. api.nvim_win_get_height(api.nvim_list_wins()[2]),
  315. api.nvim_win_get_height(api.nvim_list_wins()[1])
  316. )
  317. api.nvim_set_current_win(api.nvim_list_wins()[2])
  318. command('split')
  319. eq(
  320. api.nvim_win_get_height(api.nvim_list_wins()[2]),
  321. math.floor(api.nvim_win_get_height(api.nvim_list_wins()[1]) / 2)
  322. )
  323. api.nvim_win_set_height(api.nvim_list_wins()[2], 2)
  324. eq(2, api.nvim_win_get_height(api.nvim_list_wins()[2]))
  325. end)
  326. it('correctly handles height=1', function()
  327. command('split')
  328. api.nvim_set_current_win(api.nvim_list_wins()[1])
  329. api.nvim_win_set_height(api.nvim_list_wins()[2], 1)
  330. eq(1, api.nvim_win_get_height(api.nvim_list_wins()[2]))
  331. end)
  332. it('correctly handles height=1 with a winbar', function()
  333. command('set winbar=foobar')
  334. command('set winminheight=0')
  335. command('split')
  336. api.nvim_set_current_win(api.nvim_list_wins()[1])
  337. api.nvim_win_set_height(api.nvim_list_wins()[2], 1)
  338. eq(1, api.nvim_win_get_height(api.nvim_list_wins()[2]))
  339. end)
  340. it('do not cause ml_get errors with foldmethod=expr #19989', function()
  341. insert([[
  342. aaaaa
  343. bbbbb
  344. ccccc]])
  345. command('set foldmethod=expr')
  346. exec([[
  347. new
  348. let w = nvim_get_current_win()
  349. wincmd w
  350. call nvim_win_set_height(w, 5)
  351. ]])
  352. feed('l')
  353. eq('', api.nvim_get_vvar('errmsg'))
  354. end)
  355. end)
  356. describe('{get,set}_width', function()
  357. it('works', function()
  358. command('split')
  359. eq(
  360. api.nvim_win_get_width(api.nvim_list_wins()[2]),
  361. api.nvim_win_get_width(api.nvim_list_wins()[1])
  362. )
  363. api.nvim_set_current_win(api.nvim_list_wins()[2])
  364. command('vsplit')
  365. eq(
  366. api.nvim_win_get_width(api.nvim_list_wins()[2]),
  367. math.floor(api.nvim_win_get_width(api.nvim_list_wins()[1]) / 2)
  368. )
  369. api.nvim_win_set_width(api.nvim_list_wins()[2], 2)
  370. eq(2, api.nvim_win_get_width(api.nvim_list_wins()[2]))
  371. end)
  372. it('do not cause ml_get errors with foldmethod=expr #19989', function()
  373. insert([[
  374. aaaaa
  375. bbbbb
  376. ccccc]])
  377. command('set foldmethod=expr')
  378. exec([[
  379. vnew
  380. let w = nvim_get_current_win()
  381. wincmd w
  382. call nvim_win_set_width(w, 5)
  383. ]])
  384. feed('l')
  385. eq('', api.nvim_get_vvar('errmsg'))
  386. end)
  387. end)
  388. describe('{get,set,del}_var', function()
  389. it('works', function()
  390. api.nvim_win_set_var(0, 'lua', { 1, 2, { ['3'] = 1 } })
  391. eq({ 1, 2, { ['3'] = 1 } }, api.nvim_win_get_var(0, 'lua'))
  392. eq({ 1, 2, { ['3'] = 1 } }, api.nvim_eval('w:lua'))
  393. eq(1, fn.exists('w:lua'))
  394. api.nvim_win_del_var(0, 'lua')
  395. eq(0, fn.exists('w:lua'))
  396. eq('Key not found: lua', pcall_err(api.nvim_win_del_var, 0, 'lua'))
  397. api.nvim_win_set_var(0, 'lua', 1)
  398. command('lockvar w:lua')
  399. eq('Key is locked: lua', pcall_err(api.nvim_win_del_var, 0, 'lua'))
  400. eq('Key is locked: lua', pcall_err(api.nvim_win_set_var, 0, 'lua', 1))
  401. end)
  402. it('window_set_var returns the old value', function()
  403. local val1 = { 1, 2, { ['3'] = 1 } }
  404. local val2 = { 4, 7 }
  405. eq(NIL, request('window_set_var', 0, 'lua', val1))
  406. eq(val1, request('window_set_var', 0, 'lua', val2))
  407. end)
  408. it('window_del_var returns the old value', function()
  409. local val1 = { 1, 2, { ['3'] = 1 } }
  410. local val2 = { 4, 7 }
  411. eq(NIL, request('window_set_var', 0, 'lua', val1))
  412. eq(val1, request('window_set_var', 0, 'lua', val2))
  413. eq(val2, request('window_del_var', 0, 'lua'))
  414. end)
  415. end)
  416. describe('nvim_get_option_value, nvim_set_option_value', function()
  417. it('works', function()
  418. api.nvim_set_option_value('colorcolumn', '4,3', {})
  419. eq('4,3', api.nvim_get_option_value('colorcolumn', {}))
  420. command('set modified hidden')
  421. command('enew') -- edit new buffer, window option is preserved
  422. eq('4,3', api.nvim_get_option_value('colorcolumn', {}))
  423. -- global-local option
  424. api.nvim_set_option_value('statusline', 'window-status', { win = 0 })
  425. eq('window-status', api.nvim_get_option_value('statusline', { win = 0 }))
  426. eq('', api.nvim_get_option_value('statusline', { scope = 'global' }))
  427. command('set modified')
  428. command('enew') -- global-local: not preserved in new buffer
  429. -- confirm local value was not copied
  430. eq('', api.nvim_get_option_value('statusline', { win = 0 }))
  431. eq('', eval('&l:statusline'))
  432. end)
  433. it('after switching windows #15390', function()
  434. command('tabnew')
  435. local tab1 = unpack(api.nvim_list_tabpages())
  436. local win1 = unpack(api.nvim_tabpage_list_wins(tab1))
  437. api.nvim_set_option_value('statusline', 'window-status', { win = win1 })
  438. command('split')
  439. command('wincmd J')
  440. command('wincmd j')
  441. eq('window-status', api.nvim_get_option_value('statusline', { win = win1 }))
  442. assert_alive()
  443. end)
  444. it('returns values for unset local options', function()
  445. eq(-1, api.nvim_get_option_value('scrolloff', { win = 0, scope = 'local' }))
  446. end)
  447. end)
  448. describe('get_position', function()
  449. it('works', function()
  450. local height = api.nvim_win_get_height(api.nvim_list_wins()[1])
  451. local width = api.nvim_win_get_width(api.nvim_list_wins()[1])
  452. command('split')
  453. command('vsplit')
  454. eq({ 0, 0 }, api.nvim_win_get_position(api.nvim_list_wins()[1]))
  455. local vsplit_pos = math.floor(width / 2)
  456. local split_pos = math.floor(height / 2)
  457. local win2row, win2col = unpack(api.nvim_win_get_position(api.nvim_list_wins()[2]))
  458. local win3row, win3col = unpack(api.nvim_win_get_position(api.nvim_list_wins()[3]))
  459. eq(0, win2row)
  460. eq(0, win3col)
  461. ok(vsplit_pos - 1 <= win2col and win2col <= vsplit_pos + 1)
  462. ok(split_pos - 1 <= win3row and win3row <= split_pos + 1)
  463. end)
  464. end)
  465. describe('get_position', function()
  466. it('works', function()
  467. command('tabnew')
  468. command('vsplit')
  469. eq(api.nvim_win_get_tabpage(api.nvim_list_wins()[1]), api.nvim_list_tabpages()[1])
  470. eq(api.nvim_win_get_tabpage(api.nvim_list_wins()[2]), api.nvim_list_tabpages()[2])
  471. eq(api.nvim_win_get_tabpage(api.nvim_list_wins()[3]), api.nvim_list_tabpages()[2])
  472. end)
  473. end)
  474. describe('get_number', function()
  475. it('works', function()
  476. local wins = api.nvim_list_wins()
  477. eq(1, api.nvim_win_get_number(wins[1]))
  478. command('split')
  479. local win1, win2 = unpack(api.nvim_list_wins())
  480. eq(1, api.nvim_win_get_number(win1))
  481. eq(2, api.nvim_win_get_number(win2))
  482. command('wincmd J')
  483. eq(2, api.nvim_win_get_number(win1))
  484. eq(1, api.nvim_win_get_number(win2))
  485. command('tabnew')
  486. local win3 = api.nvim_list_wins()[3]
  487. -- First tab page
  488. eq(2, api.nvim_win_get_number(win1))
  489. eq(1, api.nvim_win_get_number(win2))
  490. -- Second tab page
  491. eq(1, api.nvim_win_get_number(win3))
  492. end)
  493. end)
  494. describe('is_valid', function()
  495. it('works', function()
  496. command('split')
  497. local win = api.nvim_list_wins()[2]
  498. api.nvim_set_current_win(win)
  499. ok(api.nvim_win_is_valid(win))
  500. command('close')
  501. ok(not api.nvim_win_is_valid(win))
  502. end)
  503. end)
  504. describe('close', function()
  505. it('can close current window', function()
  506. local oldwin = api.nvim_get_current_win()
  507. command('split')
  508. local newwin = api.nvim_get_current_win()
  509. api.nvim_win_close(newwin, false)
  510. eq({ oldwin }, api.nvim_list_wins())
  511. end)
  512. it('can close noncurrent window', function()
  513. local oldwin = api.nvim_get_current_win()
  514. command('split')
  515. local newwin = api.nvim_get_current_win()
  516. api.nvim_win_close(oldwin, false)
  517. eq({ newwin }, api.nvim_list_wins())
  518. end)
  519. it("handles changed buffer when 'hidden' is unset", function()
  520. command('set nohidden')
  521. local oldwin = api.nvim_get_current_win()
  522. insert('text')
  523. command('new')
  524. local newwin = api.nvim_get_current_win()
  525. eq(
  526. 'Vim:E37: No write since last change (add ! to override)',
  527. pcall_err(api.nvim_win_close, oldwin, false)
  528. )
  529. eq({ newwin, oldwin }, api.nvim_list_wins())
  530. end)
  531. it('handles changed buffer with force', function()
  532. local oldwin = api.nvim_get_current_win()
  533. insert('text')
  534. command('new')
  535. local newwin = api.nvim_get_current_win()
  536. api.nvim_win_close(oldwin, true)
  537. eq({ newwin }, api.nvim_list_wins())
  538. end)
  539. it('in cmdline-window #9767', function()
  540. command('split')
  541. eq(2, #api.nvim_list_wins())
  542. local oldbuf = api.nvim_get_current_buf()
  543. local oldwin = api.nvim_get_current_win()
  544. local otherwin = api.nvim_open_win(0, false, {
  545. relative = 'editor',
  546. row = 10,
  547. col = 10,
  548. width = 10,
  549. height = 10,
  550. })
  551. -- Open cmdline-window.
  552. feed('q:')
  553. eq(4, #api.nvim_list_wins())
  554. eq(':', fn.getcmdwintype())
  555. -- Not allowed to close previous window from cmdline-window.
  556. eq(
  557. 'E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
  558. pcall_err(api.nvim_win_close, oldwin, true)
  559. )
  560. -- Closing other windows is fine.
  561. api.nvim_win_close(otherwin, true)
  562. eq(false, api.nvim_win_is_valid(otherwin))
  563. -- Close cmdline-window.
  564. api.nvim_win_close(0, true)
  565. eq(2, #api.nvim_list_wins())
  566. eq('', fn.getcmdwintype())
  567. -- Closing curwin in context of a different window shouldn't close cmdwin.
  568. otherwin = api.nvim_open_win(0, false, {
  569. relative = 'editor',
  570. row = 10,
  571. col = 10,
  572. width = 10,
  573. height = 10,
  574. })
  575. feed('q:')
  576. exec_lua(
  577. [[
  578. vim._with({win = ...}, function()
  579. vim.api.nvim_win_close(0, true)
  580. end)
  581. ]],
  582. otherwin
  583. )
  584. eq(false, api.nvim_win_is_valid(otherwin))
  585. eq(':', fn.getcmdwintype())
  586. -- Closing cmdwin in context of a non-previous window is still OK.
  587. otherwin = api.nvim_open_win(oldbuf, false, {
  588. relative = 'editor',
  589. row = 10,
  590. col = 10,
  591. width = 10,
  592. height = 10,
  593. })
  594. exec_lua(
  595. [[
  596. local otherwin, cmdwin = ...
  597. vim._with({win = otherwin}, function()
  598. vim.api.nvim_win_close(cmdwin, true)
  599. end)
  600. ]],
  601. otherwin,
  602. api.nvim_get_current_win()
  603. )
  604. eq('', fn.getcmdwintype())
  605. eq(true, api.nvim_win_is_valid(otherwin))
  606. end)
  607. it('closing current (float) window of another tabpage #15313', function()
  608. command('tabedit')
  609. command('botright split')
  610. local prevwin = curwin()
  611. eq(2, eval('tabpagenr()'))
  612. local win = api.nvim_open_win(0, true, {
  613. relative = 'editor',
  614. row = 10,
  615. col = 10,
  616. width = 50,
  617. height = 10,
  618. })
  619. local tab = eval('tabpagenr()')
  620. command('tabprevious')
  621. eq(1, eval('tabpagenr()'))
  622. api.nvim_win_close(win, false)
  623. eq(prevwin, api.nvim_tabpage_get_win(tab))
  624. assert_alive()
  625. end)
  626. end)
  627. describe('hide', function()
  628. it('can hide current window', function()
  629. local oldwin = api.nvim_get_current_win()
  630. command('split')
  631. local newwin = api.nvim_get_current_win()
  632. api.nvim_win_hide(newwin)
  633. eq({ oldwin }, api.nvim_list_wins())
  634. end)
  635. it('can hide noncurrent window', function()
  636. local oldwin = api.nvim_get_current_win()
  637. command('split')
  638. local newwin = api.nvim_get_current_win()
  639. api.nvim_win_hide(oldwin)
  640. eq({ newwin }, api.nvim_list_wins())
  641. end)
  642. it('does not close the buffer', function()
  643. local oldwin = api.nvim_get_current_win()
  644. local oldbuf = api.nvim_get_current_buf()
  645. local buf = api.nvim_create_buf(true, false)
  646. local newwin = api.nvim_open_win(buf, true, {
  647. relative = 'win',
  648. row = 3,
  649. col = 3,
  650. width = 12,
  651. height = 3,
  652. })
  653. api.nvim_win_hide(newwin)
  654. eq({ oldwin }, api.nvim_list_wins())
  655. eq({ oldbuf, buf }, api.nvim_list_bufs())
  656. end)
  657. it('deletes the buffer when bufhidden=wipe', function()
  658. local oldwin = api.nvim_get_current_win()
  659. local oldbuf = api.nvim_get_current_buf()
  660. local buf = api.nvim_create_buf(true, false)
  661. local newwin = api.nvim_open_win(buf, true, {
  662. relative = 'win',
  663. row = 3,
  664. col = 3,
  665. width = 12,
  666. height = 3,
  667. })
  668. api.nvim_set_option_value('bufhidden', 'wipe', { buf = buf })
  669. api.nvim_win_hide(newwin)
  670. eq({ oldwin }, api.nvim_list_wins())
  671. eq({ oldbuf }, api.nvim_list_bufs())
  672. end)
  673. it('in the cmdwin', function()
  674. feed('q:')
  675. -- Can close the cmdwin.
  676. api.nvim_win_hide(0)
  677. eq('', fn.getcmdwintype())
  678. local old_buf = api.nvim_get_current_buf()
  679. local old_win = api.nvim_get_current_win()
  680. local other_win = api.nvim_open_win(0, false, {
  681. relative = 'win',
  682. row = 3,
  683. col = 3,
  684. width = 12,
  685. height = 3,
  686. })
  687. feed('q:')
  688. -- Cannot close the previous window.
  689. eq(
  690. 'E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
  691. pcall_err(api.nvim_win_hide, old_win)
  692. )
  693. -- Can close other windows.
  694. api.nvim_win_hide(other_win)
  695. eq(false, api.nvim_win_is_valid(other_win))
  696. -- Closing curwin in context of a different window shouldn't close cmdwin.
  697. other_win = api.nvim_open_win(old_buf, false, {
  698. relative = 'editor',
  699. row = 10,
  700. col = 10,
  701. width = 10,
  702. height = 10,
  703. })
  704. exec_lua(
  705. [[
  706. vim._with({win = ...}, function()
  707. vim.api.nvim_win_hide(0)
  708. end)
  709. ]],
  710. other_win
  711. )
  712. eq(false, api.nvim_win_is_valid(other_win))
  713. eq(':', fn.getcmdwintype())
  714. -- Closing cmdwin in context of a non-previous window is still OK.
  715. other_win = api.nvim_open_win(old_buf, false, {
  716. relative = 'editor',
  717. row = 10,
  718. col = 10,
  719. width = 10,
  720. height = 10,
  721. })
  722. exec_lua(
  723. [[
  724. local otherwin, cmdwin = ...
  725. vim._with({win = otherwin}, function()
  726. vim.api.nvim_win_hide(cmdwin)
  727. end)
  728. ]],
  729. other_win,
  730. api.nvim_get_current_win()
  731. )
  732. eq('', fn.getcmdwintype())
  733. eq(true, api.nvim_win_is_valid(other_win))
  734. end)
  735. end)
  736. describe('text_height', function()
  737. it('validation', function()
  738. local X = api.nvim_get_vvar('maxcol')
  739. insert([[
  740. aaa
  741. bbb
  742. ccc
  743. ddd
  744. eee]])
  745. eq('Invalid window id: 23', pcall_err(api.nvim_win_text_height, 23, {}))
  746. eq('Line index out of bounds', pcall_err(api.nvim_win_text_height, 0, { start_row = 5 }))
  747. eq('Line index out of bounds', pcall_err(api.nvim_win_text_height, 0, { start_row = -6 }))
  748. eq('Line index out of bounds', pcall_err(api.nvim_win_text_height, 0, { end_row = 5 }))
  749. eq('Line index out of bounds', pcall_err(api.nvim_win_text_height, 0, { end_row = -6 }))
  750. eq(
  751. "'start_row' is higher than 'end_row'",
  752. pcall_err(api.nvim_win_text_height, 0, { start_row = 3, end_row = 1 })
  753. )
  754. eq(
  755. "'start_vcol' specified without 'start_row'",
  756. pcall_err(api.nvim_win_text_height, 0, { end_row = 2, start_vcol = 0 })
  757. )
  758. eq(
  759. "'end_vcol' specified without 'end_row'",
  760. pcall_err(api.nvim_win_text_height, 0, { start_row = 2, end_vcol = 0 })
  761. )
  762. eq(
  763. "Invalid 'start_vcol': out of range",
  764. pcall_err(api.nvim_win_text_height, 0, { start_row = 2, start_vcol = -1 })
  765. )
  766. eq(
  767. "Invalid 'start_vcol': out of range",
  768. pcall_err(api.nvim_win_text_height, 0, { start_row = 2, start_vcol = X + 1 })
  769. )
  770. eq(
  771. "Invalid 'end_vcol': out of range",
  772. pcall_err(api.nvim_win_text_height, 0, { end_row = 2, end_vcol = -1 })
  773. )
  774. eq(
  775. "Invalid 'end_vcol': out of range",
  776. pcall_err(api.nvim_win_text_height, 0, { end_row = 2, end_vcol = X + 1 })
  777. )
  778. eq(
  779. "'start_vcol' is higher than 'end_vcol'",
  780. pcall_err(
  781. api.nvim_win_text_height,
  782. 0,
  783. { start_row = 2, end_row = 2, start_vcol = 10, end_vcol = 5 }
  784. )
  785. )
  786. end)
  787. it('with two diff windows', function()
  788. local X = api.nvim_get_vvar('maxcol')
  789. local screen = Screen.new(45, 22)
  790. exec([[
  791. set diffopt+=context:2 number
  792. let expr = 'printf("%08d", v:val) .. repeat("!", v:val)'
  793. call setline(1, map(range(1, 20) + range(25, 45), expr))
  794. vnew
  795. call setline(1, map(range(3, 20) + range(28, 50), expr))
  796. windo diffthis
  797. ]])
  798. feed('24gg')
  799. screen:expect {
  800. grid = [[
  801. {7: }{8: }{23:----------------}│{7: }{8: 1 }{22:00000001! }|
  802. {7: }{8: }{23:----------------}│{7: }{8: 2 }{22:00000002!! }|
  803. {7: }{8: 1 }00000003!!! │{7: }{8: 3 }00000003!!! |
  804. {7: }{8: 2 }00000004!!!! │{7: }{8: 4 }00000004!!!! |
  805. {7:+ }{8: 3 }{13:+-- 14 lines: 00}│{7:+ }{8: 5 }{13:+-- 14 lines: 00}|
  806. {7: }{8: 17 }00000019!!!!!!!!│{7: }{8: 19 }00000019!!!!!!!!|
  807. {7: }{8: 18 }00000020!!!!!!!!│{7: }{8: 20 }00000020!!!!!!!!|
  808. {7: }{8: }{23:----------------}│{7: }{8: 21 }{22:00000025!!!!!!!!}|
  809. {7: }{8: }{23:----------------}│{7: }{8: 22 }{22:00000026!!!!!!!!}|
  810. {7: }{8: }{23:----------------}│{7: }{8: 23 }{22:00000027!!!!!!!!}|
  811. {7: }{8: 19 }00000028!!!!!!!!│{7: }{8: 24 }^00000028!!!!!!!!|
  812. {7: }{8: 20 }00000029!!!!!!!!│{7: }{8: 25 }00000029!!!!!!!!|
  813. {7:+ }{8: 21 }{13:+-- 14 lines: 00}│{7:+ }{8: 26 }{13:+-- 14 lines: 00}|
  814. {7: }{8: 35 }00000044!!!!!!!!│{7: }{8: 40 }00000044!!!!!!!!|
  815. {7: }{8: 36 }00000045!!!!!!!!│{7: }{8: 41 }00000045!!!!!!!!|
  816. {7: }{8: 37 }{22:00000046!!!!!!!!}│{7: }{8: }{23:----------------}|
  817. {7: }{8: 38 }{22:00000047!!!!!!!!}│{7: }{8: }{23:----------------}|
  818. {7: }{8: 39 }{22:00000048!!!!!!!!}│{7: }{8: }{23:----------------}|
  819. {7: }{8: 40 }{22:00000049!!!!!!!!}│{7: }{8: }{23:----------------}|
  820. {7: }{8: 41 }{22:00000050!!!!!!!!}│{7: }{8: }{23:----------------}|
  821. {2:[No Name] [+] }{3:[No Name] [+] }|
  822. |
  823. ]],
  824. }
  825. screen:try_resize(45, 3)
  826. screen:expect {
  827. grid = [[
  828. {7: }{8: 19 }00000028!!!!!!!!│{7: }{8: 24 }^00000028!!!!!!!!|
  829. {2:[No Name] [+] }{3:[No Name] [+] }|
  830. |
  831. ]],
  832. }
  833. eq({ all = 20, fill = 5 }, api.nvim_win_text_height(1000, {}))
  834. eq({ all = 20, fill = 5 }, api.nvim_win_text_height(1001, {}))
  835. eq({ all = 20, fill = 5 }, api.nvim_win_text_height(1000, { start_row = 0 }))
  836. eq({ all = 20, fill = 5 }, api.nvim_win_text_height(1001, { start_row = 0 }))
  837. eq({ all = 15, fill = 0 }, api.nvim_win_text_height(1000, { end_row = -1 }))
  838. eq({ all = 15, fill = 0 }, api.nvim_win_text_height(1000, { end_row = 40 }))
  839. eq({ all = 20, fill = 5 }, api.nvim_win_text_height(1001, { end_row = -1 }))
  840. eq({ all = 20, fill = 5 }, api.nvim_win_text_height(1001, { end_row = 40 }))
  841. eq({ all = 10, fill = 5 }, api.nvim_win_text_height(1000, { start_row = 23 }))
  842. eq({ all = 13, fill = 3 }, api.nvim_win_text_height(1001, { start_row = 18 }))
  843. eq({ all = 11, fill = 0 }, api.nvim_win_text_height(1000, { end_row = 23 }))
  844. eq({ all = 11, fill = 5 }, api.nvim_win_text_height(1001, { end_row = 18 }))
  845. eq({ all = 11, fill = 0 }, api.nvim_win_text_height(1000, { start_row = 3, end_row = 39 }))
  846. eq({ all = 11, fill = 3 }, api.nvim_win_text_height(1001, { start_row = 1, end_row = 34 }))
  847. eq({ all = 9, fill = 0 }, api.nvim_win_text_height(1000, { start_row = 4, end_row = 38 }))
  848. eq({ all = 9, fill = 3 }, api.nvim_win_text_height(1001, { start_row = 2, end_row = 33 }))
  849. eq({ all = 9, fill = 0 }, api.nvim_win_text_height(1000, { start_row = 5, end_row = 37 }))
  850. eq({ all = 9, fill = 3 }, api.nvim_win_text_height(1001, { start_row = 3, end_row = 32 }))
  851. eq({ all = 9, fill = 0 }, api.nvim_win_text_height(1000, { start_row = 17, end_row = 25 }))
  852. eq({ all = 9, fill = 3 }, api.nvim_win_text_height(1001, { start_row = 15, end_row = 20 }))
  853. eq({ all = 7, fill = 0 }, api.nvim_win_text_height(1000, { start_row = 18, end_row = 24 }))
  854. eq({ all = 7, fill = 3 }, api.nvim_win_text_height(1001, { start_row = 16, end_row = 19 }))
  855. eq({ all = 6, fill = 5 }, api.nvim_win_text_height(1000, { start_row = -1 }))
  856. eq({ all = 5, fill = 5 }, api.nvim_win_text_height(1000, { start_row = -1, start_vcol = X }))
  857. eq(
  858. { all = 0, fill = 0 },
  859. api.nvim_win_text_height(1000, { start_row = -1, start_vcol = X, end_row = -1 })
  860. )
  861. eq(
  862. { all = 0, fill = 0 },
  863. api.nvim_win_text_height(
  864. 1000,
  865. { start_row = -1, start_vcol = X, end_row = -1, end_vcol = X }
  866. )
  867. )
  868. eq(
  869. { all = 1, fill = 0 },
  870. api.nvim_win_text_height(
  871. 1000,
  872. { start_row = -1, start_vcol = 0, end_row = -1, end_vcol = X }
  873. )
  874. )
  875. eq({ all = 3, fill = 2 }, api.nvim_win_text_height(1001, { end_row = 0 }))
  876. eq({ all = 2, fill = 2 }, api.nvim_win_text_height(1001, { end_row = 0, end_vcol = 0 }))
  877. eq(
  878. { all = 2, fill = 2 },
  879. api.nvim_win_text_height(1001, { start_row = 0, end_row = 0, end_vcol = 0 })
  880. )
  881. eq(
  882. { all = 0, fill = 0 },
  883. api.nvim_win_text_height(1001, { start_row = 0, start_vcol = 0, end_row = 0, end_vcol = 0 })
  884. )
  885. eq(
  886. { all = 1, fill = 0 },
  887. api.nvim_win_text_height(1001, { start_row = 0, start_vcol = 0, end_row = 0, end_vcol = X })
  888. )
  889. eq({ all = 11, fill = 5 }, api.nvim_win_text_height(1001, { end_row = 18 }))
  890. eq(
  891. { all = 9, fill = 3 },
  892. api.nvim_win_text_height(1001, { start_row = 0, start_vcol = 0, end_row = 18 })
  893. )
  894. eq({ all = 10, fill = 5 }, api.nvim_win_text_height(1001, { end_row = 18, end_vcol = 0 }))
  895. eq(
  896. { all = 8, fill = 3 },
  897. api.nvim_win_text_height(
  898. 1001,
  899. { start_row = 0, start_vcol = 0, end_row = 18, end_vcol = 0 }
  900. )
  901. )
  902. end)
  903. it('with wrapped lines', function()
  904. local X = api.nvim_get_vvar('maxcol')
  905. local screen = Screen.new(45, 22)
  906. exec([[
  907. set number cpoptions+=n
  908. call setline(1, repeat([repeat('foobar-', 36)], 3))
  909. ]])
  910. local ns = api.nvim_create_namespace('')
  911. api.nvim_buf_set_extmark(
  912. 0,
  913. ns,
  914. 1,
  915. 100,
  916. { virt_text = { { ('?'):rep(15), 'Search' } }, virt_text_pos = 'inline' }
  917. )
  918. api.nvim_buf_set_extmark(
  919. 0,
  920. ns,
  921. 2,
  922. 200,
  923. { virt_text = { { ('!'):rep(75), 'Search' } }, virt_text_pos = 'inline' }
  924. )
  925. screen:expect {
  926. grid = [[
  927. {8: 1 }^foobar-foobar-foobar-foobar-foobar-foobar|
  928. -foobar-foobar-foobar-foobar-foobar-foobar-fo|
  929. obar-foobar-foobar-foobar-foobar-foobar-fooba|
  930. r-foobar-foobar-foobar-foobar-foobar-foobar-f|
  931. oobar-foobar-foobar-foobar-foobar-foobar-foob|
  932. ar-foobar-foobar-foobar-foobar- |
  933. {8: 2 }foobar-foobar-foobar-foobar-foobar-foobar|
  934. -foobar-foobar-foobar-foobar-foobar-foobar-fo|
  935. obar-foobar-fo{10:???????????????}obar-foobar-foob|
  936. ar-foobar-foobar-foobar-foobar-foobar-foobar-|
  937. foobar-foobar-foobar-foobar-foobar-foobar-foo|
  938. bar-foobar-foobar-foobar-foobar-foobar-foobar|
  939. - |
  940. {8: 3 }foobar-foobar-foobar-foobar-foobar-foobar|
  941. -foobar-foobar-foobar-foobar-foobar-foobar-fo|
  942. obar-foobar-foobar-foobar-foobar-foobar-fooba|
  943. r-foobar-foobar-foobar-foobar-foobar-foobar-f|
  944. oobar-foobar-foobar-foob{10:!!!!!!!!!!!!!!!!!!!!!}|
  945. {10:!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!}|
  946. {10:!!!!!!!!!}ar-foobar-foobar-foobar-foobar-fooba|
  947. r-foobar-foobar- |
  948. |
  949. ]],
  950. }
  951. screen:try_resize(45, 2)
  952. screen:expect {
  953. grid = [[
  954. {8: 1 }^foobar-foobar-foobar-foobar-foobar-foobar|
  955. |
  956. ]],
  957. }
  958. eq({ all = 21, fill = 0 }, api.nvim_win_text_height(0, {}))
  959. eq({ all = 6, fill = 0 }, api.nvim_win_text_height(0, { start_row = 0, end_row = 0 }))
  960. eq({ all = 7, fill = 0 }, api.nvim_win_text_height(0, { start_row = 1, end_row = 1 }))
  961. eq({ all = 8, fill = 0 }, api.nvim_win_text_height(0, { start_row = 2, end_row = 2 }))
  962. eq(
  963. { all = 0, fill = 0 },
  964. api.nvim_win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 0 })
  965. )
  966. eq(
  967. { all = 1, fill = 0 },
  968. api.nvim_win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 41 })
  969. )
  970. eq(
  971. { all = 2, fill = 0 },
  972. api.nvim_win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 42 })
  973. )
  974. eq(
  975. { all = 2, fill = 0 },
  976. api.nvim_win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 86 })
  977. )
  978. eq(
  979. { all = 3, fill = 0 },
  980. api.nvim_win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 87 })
  981. )
  982. eq(
  983. { all = 6, fill = 0 },
  984. api.nvim_win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 266 })
  985. )
  986. eq(
  987. { all = 7, fill = 0 },
  988. api.nvim_win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 267 })
  989. )
  990. eq(
  991. { all = 7, fill = 0 },
  992. api.nvim_win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 311 })
  993. )
  994. eq(
  995. { all = 7, fill = 0 },
  996. api.nvim_win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = 312 })
  997. )
  998. eq(
  999. { all = 7, fill = 0 },
  1000. api.nvim_win_text_height(0, { start_row = 1, start_vcol = 0, end_row = 1, end_vcol = X })
  1001. )
  1002. eq(
  1003. { all = 7, fill = 0 },
  1004. api.nvim_win_text_height(0, { start_row = 1, start_vcol = 40, end_row = 1, end_vcol = X })
  1005. )
  1006. eq(
  1007. { all = 6, fill = 0 },
  1008. api.nvim_win_text_height(0, { start_row = 1, start_vcol = 41, end_row = 1, end_vcol = X })
  1009. )
  1010. eq(
  1011. { all = 6, fill = 0 },
  1012. api.nvim_win_text_height(0, { start_row = 1, start_vcol = 85, end_row = 1, end_vcol = X })
  1013. )
  1014. eq(
  1015. { all = 5, fill = 0 },
  1016. api.nvim_win_text_height(0, { start_row = 1, start_vcol = 86, end_row = 1, end_vcol = X })
  1017. )
  1018. eq(
  1019. { all = 2, fill = 0 },
  1020. api.nvim_win_text_height(0, { start_row = 1, start_vcol = 265, end_row = 1, end_vcol = X })
  1021. )
  1022. eq(
  1023. { all = 1, fill = 0 },
  1024. api.nvim_win_text_height(0, { start_row = 1, start_vcol = 266, end_row = 1, end_vcol = X })
  1025. )
  1026. eq(
  1027. { all = 1, fill = 0 },
  1028. api.nvim_win_text_height(0, { start_row = 1, start_vcol = 310, end_row = 1, end_vcol = X })
  1029. )
  1030. eq(
  1031. { all = 0, fill = 0 },
  1032. api.nvim_win_text_height(0, { start_row = 1, start_vcol = 311, end_row = 1, end_vcol = X })
  1033. )
  1034. eq(
  1035. { all = 1, fill = 0 },
  1036. api.nvim_win_text_height(0, { start_row = 1, start_vcol = 86, end_row = 1, end_vcol = 131 })
  1037. )
  1038. eq(
  1039. { all = 1, fill = 0 },
  1040. api.nvim_win_text_height(
  1041. 0,
  1042. { start_row = 1, start_vcol = 221, end_row = 1, end_vcol = 266 }
  1043. )
  1044. )
  1045. eq({ all = 18, fill = 0 }, api.nvim_win_text_height(0, { start_row = 0, start_vcol = 131 }))
  1046. eq({ all = 19, fill = 0 }, api.nvim_win_text_height(0, { start_row = 0, start_vcol = 130 }))
  1047. eq({ all = 20, fill = 0 }, api.nvim_win_text_height(0, { end_row = 2, end_vcol = 311 }))
  1048. eq({ all = 21, fill = 0 }, api.nvim_win_text_height(0, { end_row = 2, end_vcol = 312 }))
  1049. eq(
  1050. { all = 17, fill = 0 },
  1051. api.nvim_win_text_height(
  1052. 0,
  1053. { start_row = 0, start_vcol = 131, end_row = 2, end_vcol = 311 }
  1054. )
  1055. )
  1056. eq(
  1057. { all = 19, fill = 0 },
  1058. api.nvim_win_text_height(
  1059. 0,
  1060. { start_row = 0, start_vcol = 130, end_row = 2, end_vcol = 312 }
  1061. )
  1062. )
  1063. eq({ all = 16, fill = 0 }, api.nvim_win_text_height(0, { start_row = 0, start_vcol = 221 }))
  1064. eq({ all = 17, fill = 0 }, api.nvim_win_text_height(0, { start_row = 0, start_vcol = 220 }))
  1065. eq({ all = 14, fill = 0 }, api.nvim_win_text_height(0, { end_row = 2, end_vcol = 41 }))
  1066. eq({ all = 15, fill = 0 }, api.nvim_win_text_height(0, { end_row = 2, end_vcol = 42 }))
  1067. eq(
  1068. { all = 9, fill = 0 },
  1069. api.nvim_win_text_height(0, { start_row = 0, start_vcol = 221, end_row = 2, end_vcol = 41 })
  1070. )
  1071. eq(
  1072. { all = 11, fill = 0 },
  1073. api.nvim_win_text_height(0, { start_row = 0, start_vcol = 220, end_row = 2, end_vcol = 42 })
  1074. )
  1075. end)
  1076. end)
  1077. describe('open_win', function()
  1078. it('disallowed in cmdwin if enter=true or buf=cmdwin_buf', function()
  1079. local new_buf = api.nvim_create_buf(true, true)
  1080. feed('q:')
  1081. eq(
  1082. 'E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
  1083. pcall_err(api.nvim_open_win, new_buf, true, {
  1084. relative = 'editor',
  1085. row = 5,
  1086. col = 5,
  1087. width = 5,
  1088. height = 5,
  1089. })
  1090. )
  1091. eq(
  1092. 'E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
  1093. pcall_err(api.nvim_open_win, 0, false, {
  1094. relative = 'editor',
  1095. row = 5,
  1096. col = 5,
  1097. width = 5,
  1098. height = 5,
  1099. })
  1100. )
  1101. matches(
  1102. 'E11: Invalid in command%-line window; <CR> executes, CTRL%-C quits$',
  1103. pcall_err(
  1104. exec_lua,
  1105. [[
  1106. local cmdwin_buf = vim.api.nvim_get_current_buf()
  1107. vim._with({buf = vim.api.nvim_create_buf(false, true)}, function()
  1108. vim.api.nvim_open_win(cmdwin_buf, false, {
  1109. relative='editor', row=5, col=5, width=5, height=5,
  1110. })
  1111. end)
  1112. ]]
  1113. )
  1114. )
  1115. eq(
  1116. new_buf,
  1117. api.nvim_win_get_buf(api.nvim_open_win(new_buf, false, {
  1118. relative = 'editor',
  1119. row = 5,
  1120. col = 5,
  1121. width = 5,
  1122. height = 5,
  1123. }))
  1124. )
  1125. end)
  1126. it('aborts if buffer is invalid', function()
  1127. local wins_before = api.nvim_list_wins()
  1128. eq(
  1129. 'Invalid buffer id: 1337',
  1130. pcall_err(api.nvim_open_win, 1337, false, {
  1131. relative = 'editor',
  1132. row = 5,
  1133. col = 5,
  1134. width = 5,
  1135. height = 5,
  1136. })
  1137. )
  1138. eq(wins_before, api.nvim_list_wins())
  1139. end)
  1140. describe('creates a split window above', function()
  1141. local function test_open_win_split_above(key, val)
  1142. local initial_win = api.nvim_get_current_win()
  1143. local win = api.nvim_open_win(0, true, {
  1144. [key] = val,
  1145. height = 10,
  1146. })
  1147. eq('', api.nvim_win_get_config(win).relative)
  1148. eq(10, api.nvim_win_get_height(win))
  1149. local layout = fn.winlayout()
  1150. eq({
  1151. 'col',
  1152. {
  1153. { 'leaf', win },
  1154. { 'leaf', initial_win },
  1155. },
  1156. }, layout)
  1157. end
  1158. it("with split = 'above'", function()
  1159. test_open_win_split_above('split', 'above')
  1160. end)
  1161. it("with vertical = false and 'nosplitbelow'", function()
  1162. api.nvim_set_option_value('splitbelow', false, {})
  1163. test_open_win_split_above('vertical', false)
  1164. end)
  1165. end)
  1166. describe('creates a split window below', function()
  1167. local function test_open_win_split_below(key, val)
  1168. local initial_win = api.nvim_get_current_win()
  1169. local win = api.nvim_open_win(0, true, {
  1170. [key] = val,
  1171. height = 15,
  1172. })
  1173. eq('', api.nvim_win_get_config(win).relative)
  1174. eq(15, api.nvim_win_get_height(win))
  1175. local layout = fn.winlayout()
  1176. eq({
  1177. 'col',
  1178. {
  1179. { 'leaf', initial_win },
  1180. { 'leaf', win },
  1181. },
  1182. }, layout)
  1183. end
  1184. it("with split = 'below'", function()
  1185. test_open_win_split_below('split', 'below')
  1186. end)
  1187. it("with vertical = false and 'splitbelow'", function()
  1188. api.nvim_set_option_value('splitbelow', true, {})
  1189. test_open_win_split_below('vertical', false)
  1190. end)
  1191. end)
  1192. describe('creates a split window to the left', function()
  1193. local function test_open_win_split_left(key, val)
  1194. local initial_win = api.nvim_get_current_win()
  1195. local win = api.nvim_open_win(0, true, {
  1196. [key] = val,
  1197. width = 25,
  1198. })
  1199. eq('', api.nvim_win_get_config(win).relative)
  1200. eq(25, api.nvim_win_get_width(win))
  1201. local layout = fn.winlayout()
  1202. eq({
  1203. 'row',
  1204. {
  1205. { 'leaf', win },
  1206. { 'leaf', initial_win },
  1207. },
  1208. }, layout)
  1209. end
  1210. it("with split = 'left'", function()
  1211. test_open_win_split_left('split', 'left')
  1212. end)
  1213. it("with vertical = true and 'nosplitright'", function()
  1214. api.nvim_set_option_value('splitright', false, {})
  1215. test_open_win_split_left('vertical', true)
  1216. end)
  1217. end)
  1218. describe('creates a split window to the right', function()
  1219. local function test_open_win_split_right(key, val)
  1220. local initial_win = api.nvim_get_current_win()
  1221. local win = api.nvim_open_win(0, true, {
  1222. [key] = val,
  1223. width = 30,
  1224. })
  1225. eq('', api.nvim_win_get_config(win).relative)
  1226. eq(30, api.nvim_win_get_width(win))
  1227. local layout = fn.winlayout()
  1228. eq({
  1229. 'row',
  1230. {
  1231. { 'leaf', initial_win },
  1232. { 'leaf', win },
  1233. },
  1234. }, layout)
  1235. end
  1236. it("with split = 'right'", function()
  1237. test_open_win_split_right('split', 'right')
  1238. end)
  1239. it("with vertical = true and 'splitright'", function()
  1240. api.nvim_set_option_value('splitright', true, {})
  1241. test_open_win_split_right('vertical', true)
  1242. end)
  1243. end)
  1244. it("doesn't change tp_curwin when splitting window in another tab with enter=false", function()
  1245. local tab1 = api.nvim_get_current_tabpage()
  1246. local tab1_win = api.nvim_get_current_win()
  1247. n.command('tabnew')
  1248. local tab2 = api.nvim_get_current_tabpage()
  1249. local tab2_win = api.nvim_get_current_win()
  1250. eq({ tab1_win, tab2_win }, api.nvim_list_wins())
  1251. eq({ tab1, tab2 }, api.nvim_list_tabpages())
  1252. api.nvim_set_current_tabpage(tab1)
  1253. eq(tab1_win, api.nvim_get_current_win())
  1254. local tab2_prevwin = fn.tabpagewinnr(tab2, '#')
  1255. -- split in tab2 whine in tab2, with enter = false
  1256. local tab2_win2 = api.nvim_open_win(api.nvim_create_buf(false, true), false, {
  1257. win = tab2_win,
  1258. split = 'right',
  1259. })
  1260. eq(tab1_win, api.nvim_get_current_win()) -- we should still be in the first tp
  1261. eq(tab1_win, api.nvim_tabpage_get_win(tab1))
  1262. eq(tab2_win, api.nvim_tabpage_get_win(tab2)) -- tab2's tp_curwin should not have changed
  1263. eq(tab2_prevwin, fn.tabpagewinnr(tab2, '#')) -- tab2's tp_prevwin should not have changed
  1264. eq({ tab1_win, tab2_win, tab2_win2 }, api.nvim_list_wins())
  1265. eq({ tab2_win, tab2_win2 }, api.nvim_tabpage_list_wins(tab2))
  1266. end)
  1267. it('creates splits in the correct location', function()
  1268. local first_win = api.nvim_get_current_win()
  1269. -- specifying window 0 should create a split next to the current window
  1270. local win = api.nvim_open_win(0, true, {
  1271. vertical = false,
  1272. })
  1273. local layout = fn.winlayout()
  1274. eq({
  1275. 'col',
  1276. {
  1277. { 'leaf', win },
  1278. { 'leaf', first_win },
  1279. },
  1280. }, layout)
  1281. -- not specifying a window should create a top-level split
  1282. local win2 = api.nvim_open_win(0, true, {
  1283. split = 'left',
  1284. win = -1,
  1285. })
  1286. layout = fn.winlayout()
  1287. eq({
  1288. 'row',
  1289. {
  1290. { 'leaf', win2 },
  1291. {
  1292. 'col',
  1293. {
  1294. { 'leaf', win },
  1295. { 'leaf', first_win },
  1296. },
  1297. },
  1298. },
  1299. }, layout)
  1300. -- specifying a window should create a split next to that window
  1301. local win3 = api.nvim_open_win(0, true, {
  1302. win = win,
  1303. vertical = false,
  1304. })
  1305. layout = fn.winlayout()
  1306. eq({
  1307. 'row',
  1308. {
  1309. { 'leaf', win2 },
  1310. {
  1311. 'col',
  1312. {
  1313. { 'leaf', win3 },
  1314. { 'leaf', win },
  1315. { 'leaf', first_win },
  1316. },
  1317. },
  1318. },
  1319. }, layout)
  1320. end)
  1321. it('opens floating windows in other tabpages', function()
  1322. local first_win = api.nvim_get_current_win()
  1323. local first_tab = api.nvim_get_current_tabpage()
  1324. command('tabnew')
  1325. local new_tab = api.nvim_get_current_tabpage()
  1326. local win = api.nvim_open_win(0, false, {
  1327. relative = 'win',
  1328. win = first_win,
  1329. width = 5,
  1330. height = 5,
  1331. row = 1,
  1332. col = 1,
  1333. })
  1334. eq(api.nvim_win_get_tabpage(win), first_tab)
  1335. eq(api.nvim_get_current_tabpage(), new_tab)
  1336. end)
  1337. it('switches to new windows in non-current tabpages when enter=true', function()
  1338. local first_win = api.nvim_get_current_win()
  1339. local first_tab = api.nvim_get_current_tabpage()
  1340. command('tabnew')
  1341. local win = api.nvim_open_win(0, true, {
  1342. relative = 'win',
  1343. win = first_win,
  1344. width = 5,
  1345. height = 5,
  1346. row = 1,
  1347. col = 1,
  1348. })
  1349. eq(api.nvim_win_get_tabpage(win), first_tab)
  1350. eq(api.nvim_get_current_tabpage(), first_tab)
  1351. end)
  1352. local function setup_tabbed_autocmd_test()
  1353. local info = {}
  1354. info.orig_buf = api.nvim_get_current_buf()
  1355. info.other_buf = api.nvim_create_buf(true, true)
  1356. info.tab1_curwin = api.nvim_get_current_win()
  1357. info.tab1 = api.nvim_get_current_tabpage()
  1358. command('tab split | split')
  1359. info.tab2_curwin = api.nvim_get_current_win()
  1360. info.tab2 = api.nvim_get_current_tabpage()
  1361. exec([=[
  1362. tabfirst
  1363. let result = []
  1364. autocmd TabEnter * let result += [["TabEnter", nvim_get_current_tabpage()]]
  1365. autocmd TabLeave * let result += [["TabLeave", nvim_get_current_tabpage()]]
  1366. autocmd WinEnter * let result += [["WinEnter", win_getid()]]
  1367. autocmd WinLeave * let result += [["WinLeave", win_getid()]]
  1368. autocmd WinNew * let result += [["WinNew", win_getid()]]
  1369. autocmd WinClosed * let result += [["WinClosed", str2nr(expand("<afile>"))]]
  1370. autocmd BufEnter * let result += [["BufEnter", win_getid(), bufnr()]]
  1371. autocmd BufLeave * let result += [["BufLeave", win_getid(), bufnr()]]
  1372. autocmd BufWinEnter * let result += [["BufWinEnter", win_getid(), bufnr()]]
  1373. autocmd BufWinLeave * let result += [["BufWinLeave", win_getid(), bufnr()]]
  1374. ]=])
  1375. return info
  1376. end
  1377. it('noautocmd option works', function()
  1378. local info = setup_tabbed_autocmd_test()
  1379. api.nvim_open_win(
  1380. info.other_buf,
  1381. true,
  1382. { split = 'left', win = info.tab2_curwin, noautocmd = true }
  1383. )
  1384. eq({}, eval('result'))
  1385. api.nvim_open_win(
  1386. info.orig_buf,
  1387. true,
  1388. { relative = 'editor', row = 0, col = 0, width = 10, height = 10, noautocmd = true }
  1389. )
  1390. eq({}, eval('result'))
  1391. end)
  1392. it('fires expected autocmds when creating splits without entering', function()
  1393. local info = setup_tabbed_autocmd_test()
  1394. -- For these, don't want BufWinEnter if visiting the same buffer, like :{s}buffer.
  1395. -- Same tabpage, same buffer.
  1396. local new_win = api.nvim_open_win(0, false, { split = 'left', win = info.tab1_curwin })
  1397. eq({
  1398. { 'WinNew', new_win },
  1399. }, eval('result'))
  1400. eq(info.tab1_curwin, api.nvim_get_current_win())
  1401. -- Other tabpage, same buffer.
  1402. command('let result = []')
  1403. new_win = api.nvim_open_win(0, false, { split = 'left', win = info.tab2_curwin })
  1404. eq({
  1405. { 'WinNew', new_win },
  1406. }, eval('result'))
  1407. eq(info.tab1_curwin, api.nvim_get_current_win())
  1408. -- Same tabpage, other buffer.
  1409. command('let result = []')
  1410. new_win = api.nvim_open_win(info.other_buf, false, { split = 'left', win = info.tab1_curwin })
  1411. eq({
  1412. { 'WinNew', new_win },
  1413. { 'BufWinEnter', new_win, info.other_buf },
  1414. }, eval('result'))
  1415. eq(info.tab1_curwin, api.nvim_get_current_win())
  1416. -- Other tabpage, other buffer.
  1417. command('let result = []')
  1418. new_win = api.nvim_open_win(info.other_buf, false, { split = 'left', win = info.tab2_curwin })
  1419. eq({
  1420. { 'WinNew', new_win },
  1421. { 'BufWinEnter', new_win, info.other_buf },
  1422. }, eval('result'))
  1423. eq(info.tab1_curwin, api.nvim_get_current_win())
  1424. end)
  1425. it('fires expected autocmds when creating and entering splits', function()
  1426. local info = setup_tabbed_autocmd_test()
  1427. -- Same tabpage, same buffer.
  1428. local new_win = api.nvim_open_win(0, true, { split = 'left', win = info.tab1_curwin })
  1429. eq({
  1430. { 'WinNew', new_win },
  1431. { 'WinLeave', info.tab1_curwin },
  1432. { 'WinEnter', new_win },
  1433. }, eval('result'))
  1434. -- Same tabpage, other buffer.
  1435. api.nvim_set_current_win(info.tab1_curwin)
  1436. command('let result = []')
  1437. new_win = api.nvim_open_win(info.other_buf, true, { split = 'left', win = info.tab1_curwin })
  1438. eq({
  1439. { 'WinNew', new_win },
  1440. { 'WinLeave', info.tab1_curwin },
  1441. { 'WinEnter', new_win },
  1442. { 'BufLeave', new_win, info.orig_buf },
  1443. { 'BufEnter', new_win, info.other_buf },
  1444. { 'BufWinEnter', new_win, info.other_buf },
  1445. }, eval('result'))
  1446. -- For these, the other tabpage's prevwin and curwin will change like we switched from its old
  1447. -- curwin to the new window, so the extra events near TabEnter reflect that.
  1448. -- Other tabpage, same buffer.
  1449. api.nvim_set_current_win(info.tab1_curwin)
  1450. command('let result = []')
  1451. new_win = api.nvim_open_win(0, true, { split = 'left', win = info.tab2_curwin })
  1452. eq({
  1453. { 'WinNew', new_win },
  1454. { 'WinLeave', info.tab1_curwin },
  1455. { 'TabLeave', info.tab1 },
  1456. { 'WinEnter', info.tab2_curwin },
  1457. { 'TabEnter', info.tab2 },
  1458. { 'WinLeave', info.tab2_curwin },
  1459. { 'WinEnter', new_win },
  1460. }, eval('result'))
  1461. -- Other tabpage, other buffer.
  1462. api.nvim_set_current_win(info.tab2_curwin)
  1463. api.nvim_set_current_win(info.tab1_curwin)
  1464. command('let result = []')
  1465. new_win = api.nvim_open_win(info.other_buf, true, { split = 'left', win = info.tab2_curwin })
  1466. eq({
  1467. { 'WinNew', new_win },
  1468. { 'WinLeave', info.tab1_curwin },
  1469. { 'TabLeave', info.tab1 },
  1470. { 'WinEnter', info.tab2_curwin },
  1471. { 'TabEnter', info.tab2 },
  1472. { 'WinLeave', info.tab2_curwin },
  1473. { 'WinEnter', new_win },
  1474. { 'BufLeave', new_win, info.orig_buf },
  1475. { 'BufEnter', new_win, info.other_buf },
  1476. { 'BufWinEnter', new_win, info.other_buf },
  1477. }, eval('result'))
  1478. -- Other tabpage, other buffer; but other tabpage's curwin has a new buffer active.
  1479. api.nvim_set_current_win(info.tab2_curwin)
  1480. local new_buf = api.nvim_create_buf(true, true)
  1481. api.nvim_set_current_buf(new_buf)
  1482. api.nvim_set_current_win(info.tab1_curwin)
  1483. command('let result = []')
  1484. new_win = api.nvim_open_win(info.other_buf, true, { split = 'left', win = info.tab2_curwin })
  1485. eq({
  1486. { 'WinNew', new_win },
  1487. { 'BufLeave', info.tab1_curwin, info.orig_buf },
  1488. { 'WinLeave', info.tab1_curwin },
  1489. { 'TabLeave', info.tab1 },
  1490. { 'WinEnter', info.tab2_curwin },
  1491. { 'TabEnter', info.tab2 },
  1492. { 'BufEnter', info.tab2_curwin, new_buf },
  1493. { 'WinLeave', info.tab2_curwin },
  1494. { 'WinEnter', new_win },
  1495. { 'BufLeave', new_win, new_buf },
  1496. { 'BufEnter', new_win, info.other_buf },
  1497. { 'BufWinEnter', new_win, info.other_buf },
  1498. }, eval('result'))
  1499. end)
  1500. it('OK when new window is moved to other tabpage by autocommands', function()
  1501. -- Use nvim_win_set_config in the autocommands, as other methods of moving a window to a
  1502. -- different tabpage (e.g: wincmd T) actually creates a new window.
  1503. local tab0 = api.nvim_get_current_tabpage()
  1504. local tab0_win = api.nvim_get_current_win()
  1505. command('tabnew')
  1506. local new_buf = api.nvim_create_buf(true, true)
  1507. local tab1 = api.nvim_get_current_tabpage()
  1508. local tab1_parent = api.nvim_get_current_win()
  1509. command(
  1510. 'tabfirst | autocmd WinNew * ++once call nvim_win_set_config(0, #{split: "left", win: '
  1511. .. tab1_parent
  1512. .. '})'
  1513. )
  1514. local new_win = api.nvim_open_win(new_buf, true, { split = 'left' })
  1515. eq(tab1, api.nvim_get_current_tabpage())
  1516. eq(new_win, api.nvim_get_current_win())
  1517. eq(new_buf, api.nvim_get_current_buf())
  1518. -- nvim_win_set_config called after entering. It doesn't follow a curwin that is moved to a
  1519. -- different tabpage, but instead moves to the win filling the space, which is tab0_win.
  1520. command(
  1521. 'tabfirst | autocmd WinEnter * ++once call nvim_win_set_config(0, #{split: "left", win: '
  1522. .. tab1_parent
  1523. .. '})'
  1524. )
  1525. new_win = api.nvim_open_win(new_buf, true, { split = 'left' })
  1526. eq(tab0, api.nvim_get_current_tabpage())
  1527. eq(tab0_win, api.nvim_get_current_win())
  1528. eq(tab1, api.nvim_win_get_tabpage(new_win))
  1529. eq(new_buf, api.nvim_win_get_buf(new_win))
  1530. command(
  1531. 'tabfirst | autocmd BufEnter * ++once call nvim_win_set_config(0, #{split: "left", win: '
  1532. .. tab1_parent
  1533. .. '})'
  1534. )
  1535. new_win = api.nvim_open_win(new_buf, true, { split = 'left' })
  1536. eq(tab0, api.nvim_get_current_tabpage())
  1537. eq(tab0_win, api.nvim_get_current_win())
  1538. eq(tab1, api.nvim_win_get_tabpage(new_win))
  1539. eq(new_buf, api.nvim_win_get_buf(new_win))
  1540. end)
  1541. it('does not fire BufWinEnter if win_set_buf fails', function()
  1542. exec([[
  1543. set nohidden modified
  1544. autocmd WinNew * ++once only!
  1545. let fired = v:false
  1546. autocmd BufWinEnter * ++once let fired = v:true
  1547. ]])
  1548. eq(
  1549. 'Failed to set buffer 2',
  1550. pcall_err(api.nvim_open_win, api.nvim_create_buf(true, true), false, { split = 'left' })
  1551. )
  1552. eq(false, eval('fired'))
  1553. end)
  1554. it('fires Buf* autocommands when `!enter` if window is entered via autocommands', function()
  1555. exec([[
  1556. autocmd WinNew * ++once only!
  1557. let fired = v:false
  1558. autocmd BufEnter * ++once let fired = v:true
  1559. ]])
  1560. api.nvim_open_win(api.nvim_create_buf(true, true), false, { split = 'left' })
  1561. eq(true, eval('fired'))
  1562. end)
  1563. it('no heap-use-after-free if target buffer deleted by autocommands', function()
  1564. local cur_buf = api.nvim_get_current_buf()
  1565. local new_buf = api.nvim_create_buf(true, true)
  1566. command('autocmd WinNew * ++once call nvim_buf_delete(' .. new_buf .. ', #{force: 1})')
  1567. api.nvim_open_win(new_buf, true, { split = 'left' })
  1568. eq(cur_buf, api.nvim_get_current_buf())
  1569. end)
  1570. it('checks if splitting disallowed', function()
  1571. command('split | autocmd WinEnter * ++once call nvim_open_win(0, 0, #{split: "right"})')
  1572. matches("E242: Can't split a window while closing another$", pcall_err(command, 'quit'))
  1573. command('only | autocmd BufHidden * ++once call nvim_open_win(0, 0, #{split: "left"})')
  1574. matches(
  1575. 'E1159: Cannot split a window when closing the buffer$',
  1576. pcall_err(command, 'new | quit')
  1577. )
  1578. local w = api.nvim_get_current_win()
  1579. command(
  1580. 'only | new | autocmd BufHidden * ++once call nvim_open_win(0, 0, #{split: "left", win: '
  1581. .. w
  1582. .. '})'
  1583. )
  1584. matches(
  1585. 'E1159: Cannot split a window when closing the buffer$',
  1586. pcall_err(api.nvim_win_close, w, true)
  1587. )
  1588. -- OK when using window to different buffer than `win`s.
  1589. w = api.nvim_get_current_win()
  1590. command(
  1591. 'only | autocmd BufHidden * ++once call nvim_open_win(0, 0, #{split: "left", win: '
  1592. .. w
  1593. .. '})'
  1594. )
  1595. command('new | quit')
  1596. end)
  1597. it('restores last known cursor position if BufWinEnter did not move it', function()
  1598. -- This test mostly exists to ensure BufWinEnter is executed before enter_buffer's epilogue.
  1599. local buf = api.nvim_get_current_buf()
  1600. insert([[
  1601. foo
  1602. bar baz .etc
  1603. i love autocommand bugs!
  1604. supercalifragilisticexpialidocious
  1605. marvim is actually a human
  1606. llanfairpwllgwyngyllgogerychwyrndrobwllllantysiliogogogoch
  1607. ]])
  1608. api.nvim_win_set_cursor(0, { 5, 2 })
  1609. command('set nostartofline | enew')
  1610. local new_win = api.nvim_open_win(buf, false, { split = 'left' })
  1611. eq({ 5, 2 }, api.nvim_win_get_cursor(new_win))
  1612. exec([[
  1613. only!
  1614. autocmd BufWinEnter * ++once normal! j6l
  1615. ]])
  1616. new_win = api.nvim_open_win(buf, false, { split = 'left' })
  1617. eq({ 2, 6 }, api.nvim_win_get_cursor(new_win))
  1618. end)
  1619. it('does not block all win_set_buf autocommands if !enter and !noautocmd', function()
  1620. local new_buf = fn.bufadd('foobarbaz')
  1621. exec([[
  1622. let triggered = ""
  1623. autocmd BufReadCmd * ++once let triggered = bufname()
  1624. ]])
  1625. api.nvim_open_win(new_buf, false, { split = 'left' })
  1626. eq('foobarbaz', eval('triggered'))
  1627. end)
  1628. it('sets error when no room', function()
  1629. matches('E36: Not enough room$', pcall_err(command, 'execute "split|"->repeat(&lines)'))
  1630. matches(
  1631. 'E36: Not enough room$',
  1632. pcall_err(api.nvim_open_win, 0, true, { split = 'above', win = 0 })
  1633. )
  1634. matches(
  1635. 'E36: Not enough room$',
  1636. pcall_err(api.nvim_open_win, 0, true, { split = 'below', win = 0 })
  1637. )
  1638. end)
  1639. describe("with 'autochdir'", function()
  1640. local topdir
  1641. local otherbuf
  1642. before_each(function()
  1643. command('set shellslash')
  1644. topdir = fn.getcwd()
  1645. t.mkdir(topdir .. '/Xacd')
  1646. t.mkdir(topdir .. '/Xacd/foo')
  1647. otherbuf = api.nvim_create_buf(false, true)
  1648. api.nvim_buf_set_name(otherbuf, topdir .. '/Xacd/baz.txt')
  1649. command('set autochdir')
  1650. command('edit Xacd/foo/bar.txt')
  1651. eq(topdir .. '/Xacd/foo', fn.getcwd())
  1652. end)
  1653. after_each(function()
  1654. n.rmdir(topdir .. '/Xacd')
  1655. end)
  1656. it('does not change cwd with enter=false #15280', function()
  1657. api.nvim_open_win(
  1658. otherbuf,
  1659. false,
  1660. { relative = 'editor', height = 5, width = 5, row = 5, col = 5 }
  1661. )
  1662. eq(topdir .. '/Xacd/foo', fn.getcwd())
  1663. end)
  1664. it('changes cwd with enter=true', function()
  1665. api.nvim_open_win(
  1666. otherbuf,
  1667. true,
  1668. { relative = 'editor', height = 5, width = 5, row = 5, col = 5 }
  1669. )
  1670. eq(topdir .. '/Xacd', fn.getcwd())
  1671. end)
  1672. end)
  1673. it('no memory leak with valid title and invalid footer', function()
  1674. eq(
  1675. 'title/footer must be string or array',
  1676. pcall_err(api.nvim_open_win, 0, false, {
  1677. relative = 'editor',
  1678. row = 10,
  1679. col = 10,
  1680. height = 10,
  1681. width = 10,
  1682. border = 'single',
  1683. title = { { 'TITLE' } },
  1684. footer = 0,
  1685. })
  1686. )
  1687. end)
  1688. it('no memory leak with invalid title and valid footer', function()
  1689. eq(
  1690. 'title/footer must be string or array',
  1691. pcall_err(api.nvim_open_win, 0, false, {
  1692. relative = 'editor',
  1693. row = 10,
  1694. col = 10,
  1695. height = 10,
  1696. width = 10,
  1697. border = 'single',
  1698. title = 0,
  1699. footer = { { 'FOOTER' } },
  1700. })
  1701. )
  1702. end)
  1703. end)
  1704. describe('set_config', function()
  1705. it('moves a split into a float', function()
  1706. local win = api.nvim_open_win(0, true, {
  1707. vertical = false,
  1708. })
  1709. eq('', api.nvim_win_get_config(win).relative)
  1710. api.nvim_win_set_config(win, {
  1711. relative = 'editor',
  1712. row = 5,
  1713. col = 5,
  1714. width = 5,
  1715. height = 5,
  1716. })
  1717. eq('editor', api.nvim_win_get_config(win).relative)
  1718. end)
  1719. it('throws error when attempting to move the last window', function()
  1720. local err = pcall_err(api.nvim_win_set_config, 0, {
  1721. vertical = false,
  1722. })
  1723. eq('Cannot move last window', err)
  1724. end)
  1725. it('passing retval of get_config results in no-op', function()
  1726. -- simple split layout
  1727. local win = api.nvim_open_win(0, true, {
  1728. split = 'left',
  1729. })
  1730. local layout = fn.winlayout()
  1731. local config = api.nvim_win_get_config(win)
  1732. api.nvim_win_set_config(win, config)
  1733. eq(layout, fn.winlayout())
  1734. -- nested split layout
  1735. local win2 = api.nvim_open_win(0, true, {
  1736. vertical = true,
  1737. })
  1738. local win3 = api.nvim_open_win(0, true, {
  1739. win = win2,
  1740. vertical = false,
  1741. })
  1742. layout = fn.winlayout()
  1743. config = api.nvim_win_get_config(win2)
  1744. api.nvim_win_set_config(win2, config)
  1745. eq(layout, fn.winlayout())
  1746. config = api.nvim_win_get_config(win3)
  1747. api.nvim_win_set_config(win3, config)
  1748. eq(layout, fn.winlayout())
  1749. end)
  1750. it('moves a float into a split', function()
  1751. local layout = fn.winlayout()
  1752. eq('leaf', layout[1])
  1753. local win = api.nvim_open_win(0, true, {
  1754. relative = 'editor',
  1755. row = 5,
  1756. col = 5,
  1757. width = 5,
  1758. height = 5,
  1759. })
  1760. api.nvim_win_set_config(win, {
  1761. split = 'below',
  1762. win = -1,
  1763. })
  1764. eq('', api.nvim_win_get_config(win).relative)
  1765. layout = fn.winlayout()
  1766. eq('col', layout[1])
  1767. eq(2, #layout[2])
  1768. eq(win, layout[2][2][2])
  1769. end)
  1770. it('respects the "split" option', function()
  1771. local layout = fn.winlayout()
  1772. eq('leaf', layout[1])
  1773. local first_win = layout[2]
  1774. local win = api.nvim_open_win(0, true, {
  1775. relative = 'editor',
  1776. row = 5,
  1777. col = 5,
  1778. width = 5,
  1779. height = 5,
  1780. })
  1781. api.nvim_win_set_config(win, {
  1782. split = 'right',
  1783. win = first_win,
  1784. })
  1785. layout = fn.winlayout()
  1786. eq('row', layout[1])
  1787. eq(2, #layout[2])
  1788. eq(win, layout[2][2][2])
  1789. local config = api.nvim_win_get_config(win)
  1790. eq('', config.relative)
  1791. eq('right', config.split)
  1792. api.nvim_win_set_config(win, {
  1793. split = 'below',
  1794. win = first_win,
  1795. })
  1796. layout = fn.winlayout()
  1797. eq('col', layout[1])
  1798. eq(2, #layout[2])
  1799. eq(win, layout[2][2][2])
  1800. config = api.nvim_win_get_config(win)
  1801. eq('', config.relative)
  1802. eq('below', config.split)
  1803. eq(
  1804. "non-float with 'win' requires at least 'split' or 'vertical'",
  1805. pcall_err(api.nvim_win_set_config, 0, { win = 0 })
  1806. )
  1807. eq(
  1808. "non-float with 'win' requires at least 'split' or 'vertical'",
  1809. pcall_err(api.nvim_win_set_config, 0, { win = 0, relative = '' })
  1810. )
  1811. end)
  1812. it('creates top-level splits', function()
  1813. local win = api.nvim_open_win(0, true, {
  1814. vertical = false,
  1815. })
  1816. local win2 = api.nvim_open_win(0, true, {
  1817. vertical = true,
  1818. win = -1,
  1819. })
  1820. local layout = fn.winlayout()
  1821. eq('row', layout[1])
  1822. eq(2, #layout[2])
  1823. eq(win2, layout[2][1][2])
  1824. api.nvim_win_set_config(win, {
  1825. split = 'below',
  1826. win = -1,
  1827. })
  1828. layout = fn.winlayout()
  1829. eq('col', layout[1])
  1830. eq(2, #layout[2])
  1831. eq('row', layout[2][1][1])
  1832. eq(win, layout[2][2][2])
  1833. end)
  1834. it('moves splits to other tabpages', function()
  1835. local curtab = api.nvim_get_current_tabpage()
  1836. local win = api.nvim_open_win(0, false, { split = 'left' })
  1837. command('tabnew')
  1838. local tabnr = api.nvim_get_current_tabpage()
  1839. command('tabprev') -- return to the initial tab
  1840. api.nvim_win_set_config(win, {
  1841. split = 'right',
  1842. win = api.nvim_tabpage_get_win(tabnr),
  1843. })
  1844. eq(tabnr, api.nvim_win_get_tabpage(win))
  1845. -- we are changing the config, the current tabpage should not change
  1846. eq(curtab, api.nvim_get_current_tabpage())
  1847. command('tabnext') -- switch to the new tabpage so we can get the layout
  1848. local layout = fn.winlayout()
  1849. eq({
  1850. 'row',
  1851. {
  1852. { 'leaf', api.nvim_tabpage_get_win(tabnr) },
  1853. { 'leaf', win },
  1854. },
  1855. }, layout)
  1856. end)
  1857. it('correctly moves curwin when moving curwin to a different tabpage', function()
  1858. local curtab = api.nvim_get_current_tabpage()
  1859. command('tabnew')
  1860. local tab2 = api.nvim_get_current_tabpage()
  1861. local tab2_win = api.nvim_get_current_win()
  1862. command('tabprev') -- return to the initial tab
  1863. local neighbor = api.nvim_get_current_win()
  1864. -- create and enter a new split
  1865. local win = api.nvim_open_win(0, true, {
  1866. vertical = false,
  1867. })
  1868. eq(curtab, api.nvim_win_get_tabpage(win))
  1869. eq({ win, neighbor }, api.nvim_tabpage_list_wins(curtab))
  1870. -- move the current win to a different tabpage
  1871. api.nvim_win_set_config(win, {
  1872. split = 'right',
  1873. win = api.nvim_tabpage_get_win(tab2),
  1874. })
  1875. eq(curtab, api.nvim_get_current_tabpage())
  1876. -- win should have moved to tab2
  1877. eq(tab2, api.nvim_win_get_tabpage(win))
  1878. -- tp_curwin of tab2 should not have changed
  1879. eq(tab2_win, api.nvim_tabpage_get_win(tab2))
  1880. -- win lists should be correct
  1881. eq({ tab2_win, win }, api.nvim_tabpage_list_wins(tab2))
  1882. eq({ neighbor }, api.nvim_tabpage_list_wins(curtab))
  1883. -- current win should have moved to neighboring win
  1884. eq(neighbor, api.nvim_tabpage_get_win(curtab))
  1885. end)
  1886. it('splits windows in non-current tabpage', function()
  1887. local curtab = api.nvim_get_current_tabpage()
  1888. command('tabnew')
  1889. local tabnr = api.nvim_get_current_tabpage()
  1890. command('tabprev') -- return to the initial tab
  1891. local win = api.nvim_open_win(0, false, {
  1892. vertical = false,
  1893. win = api.nvim_tabpage_get_win(tabnr),
  1894. })
  1895. eq(tabnr, api.nvim_win_get_tabpage(win))
  1896. -- since enter = false, the current tabpage should not change
  1897. eq(curtab, api.nvim_get_current_tabpage())
  1898. end)
  1899. it('moves the current split window', function()
  1900. local initial_win = api.nvim_get_current_win()
  1901. local win = api.nvim_open_win(0, true, {
  1902. vertical = true,
  1903. })
  1904. local win2 = api.nvim_open_win(0, true, {
  1905. vertical = true,
  1906. })
  1907. api.nvim_set_current_win(win)
  1908. eq({
  1909. 'row',
  1910. {
  1911. { 'leaf', win2 },
  1912. { 'leaf', win },
  1913. { 'leaf', initial_win },
  1914. },
  1915. }, fn.winlayout())
  1916. api.nvim_win_set_config(0, {
  1917. vertical = false,
  1918. win = 0,
  1919. })
  1920. eq(win, api.nvim_get_current_win())
  1921. eq({
  1922. 'col',
  1923. {
  1924. { 'leaf', win },
  1925. {
  1926. 'row',
  1927. {
  1928. { 'leaf', win2 },
  1929. { 'leaf', initial_win },
  1930. },
  1931. },
  1932. },
  1933. }, fn.winlayout())
  1934. api.nvim_set_current_win(win2)
  1935. local win3 = api.nvim_open_win(0, true, {
  1936. vertical = true,
  1937. })
  1938. eq(win3, api.nvim_get_current_win())
  1939. eq({
  1940. 'col',
  1941. {
  1942. { 'leaf', win },
  1943. {
  1944. 'row',
  1945. {
  1946. { 'leaf', win3 },
  1947. { 'leaf', win2 },
  1948. { 'leaf', initial_win },
  1949. },
  1950. },
  1951. },
  1952. }, fn.winlayout())
  1953. api.nvim_win_set_config(0, {
  1954. vertical = false,
  1955. win = 0,
  1956. })
  1957. eq(win3, api.nvim_get_current_win())
  1958. eq({
  1959. 'col',
  1960. {
  1961. { 'leaf', win },
  1962. {
  1963. 'row',
  1964. {
  1965. {
  1966. 'col',
  1967. {
  1968. { 'leaf', win3 },
  1969. { 'leaf', win2 },
  1970. },
  1971. },
  1972. { 'leaf', initial_win },
  1973. },
  1974. },
  1975. },
  1976. }, fn.winlayout())
  1977. end)
  1978. it('closing new curwin when moving window to other tabpage works', function()
  1979. command('split | tabnew')
  1980. local t2_win = api.nvim_get_current_win()
  1981. command('tabfirst | autocmd WinEnter * ++once quit')
  1982. local t1_move_win = api.nvim_get_current_win()
  1983. -- win_set_config fails to switch away from "t1_move_win" because the WinEnter autocmd that
  1984. -- closed the window we're switched to returns us to "t1_move_win", as it filled the space.
  1985. eq(
  1986. 'Failed to switch away from window ' .. t1_move_win,
  1987. pcall_err(api.nvim_win_set_config, t1_move_win, { win = t2_win, split = 'left' })
  1988. )
  1989. eq(t1_move_win, api.nvim_get_current_win())
  1990. command('split | split | autocmd WinEnter * ++once quit')
  1991. t1_move_win = api.nvim_get_current_win()
  1992. -- In this case, we closed the window that we got switched to, but doing so didn't switch us
  1993. -- back to "t1_move_win", which is fine.
  1994. api.nvim_win_set_config(t1_move_win, { win = t2_win, split = 'left' })
  1995. neq(t1_move_win, api.nvim_get_current_win())
  1996. end)
  1997. it('messing with "win" or "parent" when moving "win" to other tabpage', function()
  1998. command('split | tabnew')
  1999. local t2 = api.nvim_get_current_tabpage()
  2000. local t2_win1 = api.nvim_get_current_win()
  2001. command('split')
  2002. local t2_win2 = api.nvim_get_current_win()
  2003. command('split')
  2004. local t2_win3 = api.nvim_get_current_win()
  2005. command('tabfirst | autocmd WinEnter * ++once call nvim_win_close(' .. t2_win1 .. ', 1)')
  2006. local cur_win = api.nvim_get_current_win()
  2007. eq(
  2008. 'Windows to split were closed',
  2009. pcall_err(api.nvim_win_set_config, 0, { win = t2_win1, split = 'left' })
  2010. )
  2011. eq(cur_win, api.nvim_get_current_win())
  2012. command('split | autocmd WinLeave * ++once quit!')
  2013. cur_win = api.nvim_get_current_win()
  2014. eq(
  2015. 'Windows to split were closed',
  2016. pcall_err(api.nvim_win_set_config, 0, { win = t2_win2, split = 'left' })
  2017. )
  2018. neq(cur_win, api.nvim_get_current_win())
  2019. exec([[
  2020. split
  2021. autocmd WinLeave * ++once
  2022. \ call nvim_win_set_config(0, #{relative:'editor', row:0, col:0, width:5, height:5})
  2023. ]])
  2024. cur_win = api.nvim_get_current_win()
  2025. eq(
  2026. 'Floating state of windows to split changed',
  2027. pcall_err(api.nvim_win_set_config, 0, { win = t2_win3, split = 'left' })
  2028. )
  2029. eq('editor', api.nvim_win_get_config(0).relative)
  2030. eq(cur_win, api.nvim_get_current_win())
  2031. command('autocmd WinLeave * ++once wincmd J')
  2032. cur_win = api.nvim_get_current_win()
  2033. eq(
  2034. 'Floating state of windows to split changed',
  2035. pcall_err(api.nvim_win_set_config, 0, { win = t2_win3, split = 'left' })
  2036. )
  2037. eq('', api.nvim_win_get_config(0).relative)
  2038. eq(cur_win, api.nvim_get_current_win())
  2039. -- Try to make "parent" floating. This should give the same error as before, but because
  2040. -- changing a split from another tabpage into a float isn't supported yet, check for that
  2041. -- error instead for now.
  2042. -- Use ":silent!" to avoid the one second delay from printing the error message.
  2043. exec(([[
  2044. autocmd WinLeave * ++once silent!
  2045. \ call nvim_win_set_config(%d, #{relative:'editor', row:0, col:0, width:5, height:5})
  2046. ]]):format(t2_win3))
  2047. cur_win = api.nvim_get_current_win()
  2048. api.nvim_win_set_config(0, { win = t2_win3, split = 'left' })
  2049. matches(
  2050. 'Cannot change window from different tabpage into float$',
  2051. api.nvim_get_vvar('errmsg')
  2052. )
  2053. -- The error doesn't abort moving the window (or maybe it should, if that's wanted?)
  2054. neq(cur_win, api.nvim_get_current_win())
  2055. eq(t2, api.nvim_win_get_tabpage(cur_win))
  2056. end)
  2057. it('expected autocmds when moving window to other tabpage', function()
  2058. local new_curwin = api.nvim_get_current_win()
  2059. command('split')
  2060. local win = api.nvim_get_current_win()
  2061. command('tabnew')
  2062. local parent = api.nvim_get_current_win()
  2063. exec([[
  2064. tabfirst
  2065. let result = []
  2066. autocmd WinEnter * let result += ["Enter", win_getid()]
  2067. autocmd WinLeave * let result += ["Leave", win_getid()]
  2068. autocmd WinNew * let result += ["New", win_getid()]
  2069. ]])
  2070. api.nvim_win_set_config(0, { win = parent, split = 'left' })
  2071. -- Shouldn't see WinNew, as we're not creating any new windows, just moving existing ones.
  2072. eq({ 'Leave', win, 'Enter', new_curwin }, eval('result'))
  2073. end)
  2074. it('no autocmds when moving window within same tabpage', function()
  2075. local parent = api.nvim_get_current_win()
  2076. exec([[
  2077. split
  2078. let result = []
  2079. autocmd WinEnter * let result += ["Enter", win_getid()]
  2080. autocmd WinLeave * let result += ["Leave", win_getid()]
  2081. autocmd WinNew * let result += ["New", win_getid()]
  2082. ]])
  2083. api.nvim_win_set_config(0, { win = parent, split = 'left' })
  2084. -- Shouldn't see any of those events, as we remain in the same window.
  2085. eq({}, eval('result'))
  2086. end)
  2087. it('checks if splitting disallowed', function()
  2088. command('split | autocmd WinEnter * ++once call nvim_win_set_config(0, #{split: "right"})')
  2089. matches("E242: Can't split a window while closing another$", pcall_err(command, 'quit'))
  2090. command('autocmd BufHidden * ++once call nvim_win_set_config(0, #{split: "left"})')
  2091. matches(
  2092. 'E1159: Cannot split a window when closing the buffer$',
  2093. pcall_err(command, 'new | quit')
  2094. )
  2095. -- OK when using window to different buffer.
  2096. local w = api.nvim_get_current_win()
  2097. command('autocmd BufHidden * ++once call nvim_win_set_config(' .. w .. ', #{split: "left"})')
  2098. command('new | quit')
  2099. end)
  2100. --- Returns a function to get information about the window layout, sizes and positions of a
  2101. --- tabpage.
  2102. local function define_tp_info_function()
  2103. exec_lua([[
  2104. function tp_info(tp)
  2105. return {
  2106. layout = vim.fn.winlayout(vim.api.nvim_tabpage_get_number(tp)),
  2107. pos_sizes = vim.tbl_map(
  2108. function(w)
  2109. local pos = vim.fn.win_screenpos(w)
  2110. return {
  2111. row = pos[1],
  2112. col = pos[2],
  2113. width = vim.fn.winwidth(w),
  2114. height = vim.fn.winheight(w)
  2115. }
  2116. end,
  2117. vim.api.nvim_tabpage_list_wins(tp)
  2118. )
  2119. }
  2120. end
  2121. ]])
  2122. return function(tp)
  2123. return exec_lua('return tp_info(...)', tp)
  2124. end
  2125. end
  2126. it('attempt to move window with no room', function()
  2127. -- Fill the 2nd tabpage full of windows until we run out of room.
  2128. -- Use &laststatus=0 to ensure restoring missing statuslines doesn't affect things.
  2129. command('set laststatus=0 | tabnew')
  2130. matches('E36: Not enough room$', pcall_err(command, 'execute "split|"->repeat(&lines)'))
  2131. command('vsplit | wincmd | | wincmd p')
  2132. local t2 = api.nvim_get_current_tabpage()
  2133. local t2_cur_win = api.nvim_get_current_win()
  2134. local t2_top_split = fn.win_getid(1)
  2135. local t2_bot_split = fn.win_getid(fn.winnr('$'))
  2136. local t2_float = api.nvim_open_win(
  2137. 0,
  2138. false,
  2139. { relative = 'editor', row = 0, col = 0, width = 10, height = 10 }
  2140. )
  2141. local t2_float_config = api.nvim_win_get_config(t2_float)
  2142. local tp_info = define_tp_info_function()
  2143. local t2_info = tp_info(t2)
  2144. matches(
  2145. 'E36: Not enough room$',
  2146. pcall_err(api.nvim_win_set_config, 0, { win = t2_top_split, split = 'above' })
  2147. )
  2148. matches(
  2149. 'E36: Not enough room$',
  2150. pcall_err(api.nvim_win_set_config, 0, { win = t2_top_split, split = 'below' })
  2151. )
  2152. matches(
  2153. 'E36: Not enough room$',
  2154. pcall_err(api.nvim_win_set_config, 0, { win = t2_bot_split, split = 'above' })
  2155. )
  2156. matches(
  2157. 'E36: Not enough room$',
  2158. pcall_err(api.nvim_win_set_config, 0, { win = t2_bot_split, split = 'below' })
  2159. )
  2160. matches(
  2161. 'E36: Not enough room$',
  2162. pcall_err(api.nvim_win_set_config, t2_float, { win = t2_top_split, split = 'above' })
  2163. )
  2164. matches(
  2165. 'E36: Not enough room$',
  2166. pcall_err(api.nvim_win_set_config, t2_float, { win = t2_top_split, split = 'below' })
  2167. )
  2168. matches(
  2169. 'E36: Not enough room$',
  2170. pcall_err(api.nvim_win_set_config, t2_float, { win = t2_bot_split, split = 'above' })
  2171. )
  2172. matches(
  2173. 'E36: Not enough room$',
  2174. pcall_err(api.nvim_win_set_config, t2_float, { win = t2_bot_split, split = 'below' })
  2175. )
  2176. eq(t2_cur_win, api.nvim_get_current_win())
  2177. eq(t2_info, tp_info(t2))
  2178. eq(t2_float_config, api.nvim_win_get_config(t2_float))
  2179. -- Try to move windows from the 1st tabpage to the 2nd.
  2180. command('tabfirst | split | wincmd _')
  2181. local t1 = api.nvim_get_current_tabpage()
  2182. local t1_cur_win = api.nvim_get_current_win()
  2183. local t1_float = api.nvim_open_win(
  2184. 0,
  2185. false,
  2186. { relative = 'editor', row = 5, col = 3, width = 7, height = 6 }
  2187. )
  2188. local t1_float_config = api.nvim_win_get_config(t1_float)
  2189. local t1_info = tp_info(t1)
  2190. matches(
  2191. 'E36: Not enough room$',
  2192. pcall_err(api.nvim_win_set_config, 0, { win = t2_top_split, split = 'above' })
  2193. )
  2194. matches(
  2195. 'E36: Not enough room$',
  2196. pcall_err(api.nvim_win_set_config, 0, { win = t2_top_split, split = 'below' })
  2197. )
  2198. matches(
  2199. 'E36: Not enough room$',
  2200. pcall_err(api.nvim_win_set_config, 0, { win = t2_bot_split, split = 'above' })
  2201. )
  2202. matches(
  2203. 'E36: Not enough room$',
  2204. pcall_err(api.nvim_win_set_config, 0, { win = t2_bot_split, split = 'below' })
  2205. )
  2206. matches(
  2207. 'E36: Not enough room$',
  2208. pcall_err(api.nvim_win_set_config, t1_float, { win = t2_top_split, split = 'above' })
  2209. )
  2210. matches(
  2211. 'E36: Not enough room$',
  2212. pcall_err(api.nvim_win_set_config, t1_float, { win = t2_top_split, split = 'below' })
  2213. )
  2214. matches(
  2215. 'E36: Not enough room$',
  2216. pcall_err(api.nvim_win_set_config, t1_float, { win = t2_bot_split, split = 'above' })
  2217. )
  2218. matches(
  2219. 'E36: Not enough room$',
  2220. pcall_err(api.nvim_win_set_config, t1_float, { win = t2_bot_split, split = 'below' })
  2221. )
  2222. eq(t1_cur_win, api.nvim_get_current_win())
  2223. eq(t1_info, tp_info(t1))
  2224. eq(t1_float_config, api.nvim_win_get_config(t1_float))
  2225. end)
  2226. it('attempt to move window from other tabpage with no room', function()
  2227. -- Fill up the 1st tabpage with horizontal splits, then create a 2nd with only a few. Go back
  2228. -- to the 1st and try to move windows from the 2nd (while it's non-current) to it. Check that
  2229. -- window positions and sizes in the 2nd are unchanged.
  2230. command('set laststatus=0')
  2231. matches('E36: Not enough room$', pcall_err(command, 'execute "split|"->repeat(&lines)'))
  2232. command('tab split')
  2233. local t2 = api.nvim_get_current_tabpage()
  2234. local t2_top = api.nvim_get_current_win()
  2235. command('belowright split')
  2236. local t2_mid_left = api.nvim_get_current_win()
  2237. command('belowright vsplit')
  2238. local t2_mid_right = api.nvim_get_current_win()
  2239. command('split | wincmd J')
  2240. local t2_bot = api.nvim_get_current_win()
  2241. local tp_info = define_tp_info_function()
  2242. local t2_info = tp_info(t2)
  2243. eq({
  2244. 'col',
  2245. {
  2246. { 'leaf', t2_top },
  2247. {
  2248. 'row',
  2249. {
  2250. { 'leaf', t2_mid_left },
  2251. { 'leaf', t2_mid_right },
  2252. },
  2253. },
  2254. { 'leaf', t2_bot },
  2255. },
  2256. }, t2_info.layout)
  2257. local function try_move_t2_wins_to_t1()
  2258. for _, w in ipairs({ t2_bot, t2_mid_left, t2_mid_right, t2_top }) do
  2259. matches(
  2260. 'E36: Not enough room$',
  2261. pcall_err(api.nvim_win_set_config, w, { win = 0, split = 'below' })
  2262. )
  2263. eq(t2_info, tp_info(t2))
  2264. end
  2265. end
  2266. command('tabfirst')
  2267. try_move_t2_wins_to_t1()
  2268. -- Go to the 2nd tabpage to ensure nothing changes after win_comp_pos, last_status, .etc.
  2269. -- from enter_tabpage.
  2270. command('tabnext')
  2271. eq(t2_info, tp_info(t2))
  2272. -- Check things are fine with the global statusline too, for good measure.
  2273. -- Set it while the 2nd tabpage is current, so last_status runs for it.
  2274. command('set laststatus=3')
  2275. t2_info = tp_info(t2)
  2276. command('tabfirst')
  2277. try_move_t2_wins_to_t1()
  2278. end)
  2279. it('handles cmdwin and textlock restrictions', function()
  2280. command('tabnew')
  2281. local t2 = api.nvim_get_current_tabpage()
  2282. local t2_win = api.nvim_get_current_win()
  2283. command('tabfirst')
  2284. local t1_move_win = api.nvim_get_current_win()
  2285. command('split')
  2286. -- Can't move the cmdwin, or its old curwin to a different tabpage.
  2287. local old_curwin = api.nvim_get_current_win()
  2288. feed('q:')
  2289. eq(
  2290. 'E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
  2291. pcall_err(api.nvim_win_set_config, 0, { split = 'left', win = t2_win })
  2292. )
  2293. eq(
  2294. 'E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
  2295. pcall_err(api.nvim_win_set_config, old_curwin, { split = 'left', win = t2_win })
  2296. )
  2297. -- But we can move other windows.
  2298. api.nvim_win_set_config(t1_move_win, { split = 'left', win = t2_win })
  2299. eq(t2, api.nvim_win_get_tabpage(t1_move_win))
  2300. command('quit!')
  2301. -- Can't configure windows such that the cmdwin would become the only non-float.
  2302. command('only!')
  2303. feed('q:')
  2304. eq(
  2305. 'E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
  2306. pcall_err(
  2307. api.nvim_win_set_config,
  2308. old_curwin,
  2309. { relative = 'editor', row = 0, col = 0, width = 5, height = 5 }
  2310. )
  2311. )
  2312. -- old_curwin is now no longer the only other non-float, so we can make it floating now.
  2313. local t1_new_win = api.nvim_open_win(
  2314. api.nvim_create_buf(true, true),
  2315. false,
  2316. { split = 'left', win = old_curwin }
  2317. )
  2318. api.nvim_win_set_config(
  2319. old_curwin,
  2320. { relative = 'editor', row = 0, col = 0, width = 5, height = 5 }
  2321. )
  2322. eq('editor', api.nvim_win_get_config(old_curwin).relative)
  2323. -- ...which means we shouldn't be able to also make the new window floating too!
  2324. eq(
  2325. 'E11: Invalid in command-line window; <CR> executes, CTRL-C quits',
  2326. pcall_err(
  2327. api.nvim_win_set_config,
  2328. t1_new_win,
  2329. { relative = 'editor', row = 0, col = 0, width = 5, height = 5 }
  2330. )
  2331. )
  2332. -- Nothing ought to stop us from making the cmdwin itself floating, though...
  2333. api.nvim_win_set_config(0, { relative = 'editor', row = 0, col = 0, width = 5, height = 5 })
  2334. eq('editor', api.nvim_win_get_config(0).relative)
  2335. -- We can't make our new window from before floating too, as it's now the only non-float.
  2336. eq(
  2337. 'Cannot change last window into float',
  2338. pcall_err(
  2339. api.nvim_win_set_config,
  2340. t1_new_win,
  2341. { relative = 'editor', row = 0, col = 0, width = 5, height = 5 }
  2342. )
  2343. )
  2344. command('quit!')
  2345. -- Can't switch away from window before moving it to a different tabpage during textlock.
  2346. exec(([[
  2347. new
  2348. call setline(1, 'foo')
  2349. setlocal debug=throw indentexpr=nvim_win_set_config(0,#{split:'left',win:%d})
  2350. ]]):format(t2_win))
  2351. local cur_win = api.nvim_get_current_win()
  2352. matches(
  2353. 'E565: Not allowed to change text or change window$',
  2354. pcall_err(command, 'normal! ==')
  2355. )
  2356. eq(cur_win, api.nvim_get_current_win())
  2357. end)
  2358. it('updates statusline when moving bottom split', function()
  2359. local screen = Screen.new(10, 10)
  2360. exec([[
  2361. set laststatus=0
  2362. belowright split
  2363. call nvim_win_set_config(0, #{split: 'above', win: win_getid(winnr('#'))})
  2364. ]])
  2365. screen:expect([[
  2366. ^ |
  2367. {1:~ }|*3
  2368. {3:[No Name] }|
  2369. |
  2370. {1:~ }|*3
  2371. |
  2372. ]])
  2373. end)
  2374. it("updates tp_curwin of moved window's original tabpage", function()
  2375. local t1 = api.nvim_get_current_tabpage()
  2376. command('tab split | split')
  2377. local t2 = api.nvim_get_current_tabpage()
  2378. local t2_alt_win = api.nvim_get_current_win()
  2379. command('vsplit')
  2380. local t2_cur_win = api.nvim_get_current_win()
  2381. command('tabprevious')
  2382. eq(t2_cur_win, api.nvim_tabpage_get_win(t2))
  2383. -- tp_curwin is unchanged when moved within the same tabpage.
  2384. api.nvim_win_set_config(t2_cur_win, { split = 'left', win = t2_alt_win })
  2385. eq(t2_cur_win, api.nvim_tabpage_get_win(t2))
  2386. -- Also unchanged if the move failed.
  2387. command('let &winwidth = &columns | let &winminwidth = &columns')
  2388. matches(
  2389. 'E36: Not enough room$',
  2390. pcall_err(api.nvim_win_set_config, t2_cur_win, { split = 'left', win = 0 })
  2391. )
  2392. eq(t2_cur_win, api.nvim_tabpage_get_win(t2))
  2393. command('set winminwidth& winwidth&')
  2394. -- But is changed if successfully moved to a different tabpage.
  2395. api.nvim_win_set_config(t2_cur_win, { split = 'left', win = 0 })
  2396. eq(t2_alt_win, api.nvim_tabpage_get_win(t2))
  2397. eq(t1, api.nvim_win_get_tabpage(t2_cur_win))
  2398. -- Now do it for a float, which has different altwin logic.
  2399. command('tabnext')
  2400. t2_cur_win =
  2401. api.nvim_open_win(0, true, { relative = 'editor', row = 5, col = 5, width = 5, height = 5 })
  2402. eq(t2_alt_win, fn.win_getid(fn.winnr('#')))
  2403. command('tabprevious')
  2404. eq(t2_cur_win, api.nvim_tabpage_get_win(t2))
  2405. api.nvim_win_set_config(t2_cur_win, { split = 'left', win = 0 })
  2406. eq(t2_alt_win, api.nvim_tabpage_get_win(t2))
  2407. eq(t1, api.nvim_win_get_tabpage(t2_cur_win))
  2408. end)
  2409. end)
  2410. describe('get_config', function()
  2411. it('includes border', function()
  2412. local b = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' }
  2413. local win = api.nvim_open_win(0, true, {
  2414. relative = 'win',
  2415. row = 3,
  2416. col = 3,
  2417. width = 12,
  2418. height = 3,
  2419. border = b,
  2420. })
  2421. local cfg = api.nvim_win_get_config(win)
  2422. eq(b, cfg.border)
  2423. end)
  2424. it('includes border with highlight group', function()
  2425. local b = {
  2426. { 'a', 'Normal' },
  2427. { 'b', 'Special' },
  2428. { 'c', 'String' },
  2429. { 'd', 'Comment' },
  2430. { 'e', 'Visual' },
  2431. { 'f', 'Error' },
  2432. { 'g', 'Constant' },
  2433. { 'h', 'PreProc' },
  2434. }
  2435. local win = api.nvim_open_win(0, true, {
  2436. relative = 'win',
  2437. row = 3,
  2438. col = 3,
  2439. width = 12,
  2440. height = 3,
  2441. border = b,
  2442. })
  2443. local cfg = api.nvim_win_get_config(win)
  2444. eq(b, cfg.border)
  2445. end)
  2446. it('includes title and footer', function()
  2447. local title = { { 'A', { 'StatusLine', 'TabLine' } }, { 'B' }, { 'C', 'WinBar' } }
  2448. local footer = { { 'A', 'WinBar' }, { 'B' }, { 'C', { 'StatusLine', 'TabLine' } } }
  2449. local win = api.nvim_open_win(0, true, {
  2450. relative = 'win',
  2451. row = 3,
  2452. col = 3,
  2453. width = 12,
  2454. height = 3,
  2455. border = 'single',
  2456. title = title,
  2457. footer = footer,
  2458. })
  2459. local cfg = api.nvim_win_get_config(win)
  2460. eq(title, cfg.title)
  2461. eq(footer, cfg.footer)
  2462. end)
  2463. it('includes split for normal windows', function()
  2464. local win = api.nvim_open_win(0, true, {
  2465. vertical = true,
  2466. win = -1,
  2467. })
  2468. eq('left', api.nvim_win_get_config(win).split)
  2469. api.nvim_win_set_config(win, {
  2470. vertical = false,
  2471. win = -1,
  2472. })
  2473. eq('above', api.nvim_win_get_config(win).split)
  2474. api.nvim_win_set_config(win, {
  2475. split = 'below',
  2476. win = -1,
  2477. })
  2478. eq('below', api.nvim_win_get_config(win).split)
  2479. end)
  2480. it('includes split when splitting with ex commands', function()
  2481. local win = api.nvim_get_current_win()
  2482. eq('left', api.nvim_win_get_config(win).split)
  2483. command('vsplit')
  2484. local win2 = api.nvim_get_current_win()
  2485. -- initial window now be marked as right split
  2486. -- since it was split with a vertical split
  2487. -- and 'splitright' is false by default
  2488. eq('right', api.nvim_win_get_config(win).split)
  2489. eq('left', api.nvim_win_get_config(win2).split)
  2490. api.nvim_set_option_value('splitbelow', true, {
  2491. scope = 'global',
  2492. })
  2493. api.nvim_win_close(win, true)
  2494. command('split')
  2495. local win3 = api.nvim_get_current_win()
  2496. eq('below', api.nvim_win_get_config(win3).split)
  2497. end)
  2498. it("includes the correct 'split' option in complex layouts", function()
  2499. local initial_win = api.nvim_get_current_win()
  2500. local win = api.nvim_open_win(0, false, {
  2501. split = 'right',
  2502. win = -1,
  2503. })
  2504. local win2 = api.nvim_open_win(0, false, {
  2505. split = 'below',
  2506. win = win,
  2507. })
  2508. api.nvim_win_set_config(win2, {
  2509. width = 50,
  2510. })
  2511. api.nvim_win_set_config(win, {
  2512. split = 'left',
  2513. win = -1,
  2514. })
  2515. local win3 = api.nvim_open_win(0, false, {
  2516. split = 'above',
  2517. win = -1,
  2518. })
  2519. local float = api.nvim_open_win(0, false, {
  2520. relative = 'editor',
  2521. width = 40,
  2522. height = 20,
  2523. col = 20,
  2524. row = 10,
  2525. })
  2526. api.nvim_win_set_config(float, {
  2527. split = 'right',
  2528. win = -1,
  2529. })
  2530. local layout = fn.winlayout()
  2531. eq({
  2532. 'row',
  2533. {
  2534. {
  2535. 'col',
  2536. {
  2537. { 'leaf', win3 },
  2538. {
  2539. 'row',
  2540. {
  2541. { 'leaf', win },
  2542. { 'leaf', initial_win },
  2543. { 'leaf', win2 },
  2544. },
  2545. },
  2546. },
  2547. },
  2548. {
  2549. 'leaf',
  2550. float,
  2551. },
  2552. },
  2553. }, layout)
  2554. eq('above', api.nvim_win_get_config(win3).split)
  2555. eq('left', api.nvim_win_get_config(win).split)
  2556. eq('left', api.nvim_win_get_config(initial_win).split)
  2557. eq('right', api.nvim_win_get_config(win2).split)
  2558. eq('right', api.nvim_win_get_config(float).split)
  2559. end)
  2560. end)
  2561. describe('set_config', function()
  2562. it('no crash with invalid title', function()
  2563. local win = api.nvim_open_win(0, true, {
  2564. width = 10,
  2565. height = 10,
  2566. relative = 'editor',
  2567. row = 10,
  2568. col = 10,
  2569. title = { { 'test' } },
  2570. border = 'single',
  2571. })
  2572. eq(
  2573. 'title/footer must be string or array',
  2574. pcall_err(api.nvim_win_set_config, win, { title = 0 })
  2575. )
  2576. command('redraw!')
  2577. assert_alive()
  2578. eq(
  2579. 'title/footer cannot be an empty array',
  2580. pcall_err(api.nvim_win_set_config, win, { title = {} })
  2581. )
  2582. command('redraw!')
  2583. assert_alive()
  2584. end)
  2585. it('no crash with invalid footer', function()
  2586. local win = api.nvim_open_win(0, true, {
  2587. width = 10,
  2588. height = 10,
  2589. relative = 'editor',
  2590. row = 10,
  2591. col = 10,
  2592. footer = { { 'test' } },
  2593. border = 'single',
  2594. })
  2595. eq(
  2596. 'title/footer must be string or array',
  2597. pcall_err(api.nvim_win_set_config, win, { footer = 0 })
  2598. )
  2599. command('redraw!')
  2600. assert_alive()
  2601. eq(
  2602. 'title/footer cannot be an empty array',
  2603. pcall_err(api.nvim_win_set_config, win, { footer = {} })
  2604. )
  2605. command('redraw!')
  2606. assert_alive()
  2607. end)
  2608. describe('no crash or memory leak', function()
  2609. local win
  2610. before_each(function()
  2611. win = api.nvim_open_win(0, false, {
  2612. relative = 'editor',
  2613. row = 10,
  2614. col = 10,
  2615. height = 10,
  2616. width = 10,
  2617. border = 'single',
  2618. title = { { 'OLD_TITLE' } },
  2619. footer = { { 'OLD_FOOTER' } },
  2620. })
  2621. end)
  2622. it('with valid title and invalid footer', function()
  2623. eq(
  2624. 'title/footer must be string or array',
  2625. pcall_err(api.nvim_win_set_config, win, {
  2626. title = { { 'NEW_TITLE' } },
  2627. footer = 0,
  2628. })
  2629. )
  2630. command('redraw!')
  2631. assert_alive()
  2632. eq({ { 'OLD_TITLE' } }, api.nvim_win_get_config(win).title)
  2633. end)
  2634. it('with invalid title and valid footer', function()
  2635. eq(
  2636. 'title/footer must be string or array',
  2637. pcall_err(api.nvim_win_set_config, win, {
  2638. title = 0,
  2639. footer = { { 'NEW_FOOTER' } },
  2640. })
  2641. )
  2642. command('redraw!')
  2643. assert_alive()
  2644. eq({ { 'OLD_FOOTER' } }, api.nvim_win_get_config(win).footer)
  2645. end)
  2646. end)
  2647. end)
  2648. end)