robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1-- Tests for folding. 2 3local n =require ( 'test.functional.testnvim' )() 4local t =require ( 'test.testutil' ) 5local Screen =require ( 'test.functional.ui.screen' ) 6 7local describe , it , before_each =t . describe , t . it , t . before_each 8local feed , insert , feed_command , expect_any =n . feed , n . insert , n . feed_command , n . expect_any 9local command =n . command 10local exec =n . exec 11 12describe ( 'folding' , function () 13local screen 14 15before_each ( function () 16n . clear () 17 18screen =Screen . new ( 45 , 8 ) 19end ) 20 21it ( 'creation, opening, moving (to the end) and closing' , function () 22insert ( [[ 231 aa 242 bb 253 cc 26last 27]] ) 28 29-- Basic test if a fold can be created, opened, moving to the end and 30-- closed. 31feed_command ( '1' ) 32feed ( 'zf2j' ) 33feed_command ( 'call append("$", "manual " . getline(foldclosed(".")))' ) 34feed ( 'zo' ) 35feed_command ( 'call append("$", foldclosed("."))' ) 36feed ( ']z' ) 37feed_command ( 'call append("$", getline("."))' ) 38feed ( 'zc' ) 39feed_command ( 'call append("$", getline(foldclosed(".")))' ) 40 41expect_any ( [[ 42manual 1 aa 43-1 443 cc 451 aa]] ) 46end ) 47 48it ( 'foldmethod=marker' , function () 49screen : try_resize ( 20 , 10 ) 50insert ( [[ 51dd {{{ 52ee {{{ }}} 53ff }}} 54]] ) 55feed_command ( 'set fdm=marker fdl=1' ) 56feed_command ( '2' ) 57feed_command ( 'call append("$", "line 2 foldlevel=" . foldlevel("."))' ) 58feed ( '[z' ) 59feed_command ( 'call append("$", foldlevel("."))' ) 60feed ( 'jo{{ <esc>r{jj' ) -- writes '{{{' and moves 2 lines bot 61feed_command ( 'call append("$", foldlevel("."))' ) 62feed ( 'kYpj' ) 63feed_command ( 'call append("$", foldlevel("."))' ) 64 65n . poke_eventloop () 66screen : expect ( [[ 67dd {{{ | 68ee {{{ }}} | 69{{{ | 70ff }}} |*2 71^ | 72line 2 foldlevel=2 | 731 |*2 74| 75]] ) 76end ) 77 78it ( 'foldmethod=indent' , function () 79screen : try_resize ( 20 , 8 ) 80feed_command ( 'set fdm=indent sw=2' ) 81insert ( [[ 82aa 83bb 84cc 85last 86]] ) 87feed_command ( 'call append("$", "foldlevel line3=" . foldlevel(3))' ) 88feed_command ( 'call append("$", foldlevel(2))' ) 89feed ( 'zR' ) 90 91n . poke_eventloop () 92screen : expect ( [[ 93aa | 94bb | 95cc | 96last | 97^ | 98foldlevel line3=2 | 991 | 100| 101]] ) 102end ) 103 104it ( 'foldmethod=syntax' , function () 105screen : try_resize ( 35 , 15 ) 106insert ( [[ 1071 aa 1082 bb 1093 cc 1104 dd {{{ 1115 ee {{{ }}} 1126 ff }}} 1137 gg 1148 hh 1159 ii 116a jj 117b kk 118last]] ) 119feed_command ( 'set fdm=syntax fdl=0' ) 120feed_command ( 'syn region Hup start="dd" end="ii" fold contains=Fd1,Fd2,Fd3' ) 121feed_command ( 'syn region Fd1 start="ee" end="ff" fold contained' ) 122feed_command ( 'syn region Fd2 start="gg" end="hh" fold contained' ) 123feed_command ( 'syn region Fd3 start="commentstart" end="commentend" fold contained' ) 124feed ( 'Gzk' ) 125feed_command ( 'call append("$", "folding " . getline("."))' ) 126feed ( 'k' ) 127feed_command ( 'call append("$", getline("."))' ) 128feed ( 'jAcommentstart <esc>Acommentend<esc>' ) 129feed_command ( 'set fdl=1' ) 130feed ( '3j' ) 131feed_command ( 'call append("$", getline("."))' ) 132feed_command ( 'set fdl=0' ) 133feed ( 'zO<C-L>j' ) -- <C-L> redraws screen 134feed_command ( 'call append("$", getline("."))' ) 135feed_command ( 'set fdl=0' ) 136expect_any ( [[ 137folding 9 ii 1383 cc 1399 ii 140a jj]] ) 141end ) 142 143it ( 'foldmethod=expression' , function () 144insert ( [[ 1451 aa 1462 bb 1473 cc 1484 dd {{{ 1495 ee {{{ }}} 1506 ff }}} 1517 gg 1528 hh 1539 ii 154a jj 155b kk 156last ]] ) 157 158feed_command ( [[ 159fun Flvl() 160let l = getline(v:lnum) 161if l =~ "bb$" 162return 2 163elseif l =~ "gg$" 164return "s1" 165elseif l =~ "ii$" 166return ">2" 167elseif l =~ "kk$" 168return "0" 169endif 170return "=" 171endfun 172]] ) 173feed_command ( 'set fdm=expr fde=Flvl()' ) 174feed_command ( '/bb$' ) 175feed_command ( 'call append("$", "expr " . foldlevel("."))' ) 176feed_command ( '/hh$' ) 177feed_command ( 'call append("$", foldlevel("."))' ) 178feed_command ( '/ii$' ) 179feed_command ( 'call append("$", foldlevel("."))' ) 180feed_command ( '/kk$' ) 181feed_command ( 'call append("$", foldlevel("."))' ) 182 183expect_any ( [[ 184expr 2 1851 1862 1870]] ) 188end ) 189 190it ( 'can be opened after :move' , function () 191-- luacheck: ignore 192screen : try_resize ( 35 , 8 ) 193insert ( [[ 194Test fdm=indent and :move bug END 195line2 196Test fdm=indent START 197line3 198line4]] ) 199feed_command ( 'set noai nosta ' ) 200feed_command ( 'set fdm=indent' ) 201feed_command ( '1m1' ) 202feed ( '2jzc' ) 203feed_command ( 'm0' ) 204feed ( 'zR' ) 205 206expect_any ( [[ 207Test fdm=indent START 208line3 209line4 210Test fdm=indent and :move bug END 211line2]] ) 212end ) 213 214-- oldtest: Test_folds_with_rnu() 215it ( 'with relative line numbers' , function () 216command ( 'set fdm=marker rnu foldcolumn=2' ) 217command ( 'call setline(1, ["{{{1", "nline 1", "{{{1", "line 2"])' ) 218 219screen : expect ( [[ 220{7:+ }{8: 0 }{13:^+-- 2 lines: ·························}| 221{7:+ }{8: 1 }{13:+-- 2 lines: ·························}| 222{1:~ }|*5 223| 224]] ) 225feed ( 'j' ) 226screen : expect ( [[ 227{7:+ }{8: 1 }{13:+-- 2 lines: ·························}| 228{7:+ }{8: 0 }{13:^+-- 2 lines: ·························}| 229{1:~ }|*5 230| 231]] ) 232end ) 233 234-- oldtest: Test_foldclose_opt() 235it ( 'foldclose=all' , function () 236exec ( [[ 237set foldmethod=manual foldclose=all foldopen=all 238call setline(1, ['one', 'two', 'three', 'four']) 2392,3fold 240]] ) 241 242screen : expect ( [[ 243^one | 244{13:+-- 2 lines: two····························}| 245four | 246{1:~ }|*4 247| 248]] ) 249feed ( '2G' ) 250screen : expect ( [[ 251one | 252^two | 253three | 254four | 255{1:~ }|*3 256| 257]] ) 258feed ( '4G' ) 259screen : expect ( [[ 260one | 261{13:+-- 2 lines: two····························}| 262^four | 263{1:~ }|*4 264| 265]] ) 266feed ( '3G' ) 267screen : expect ( [[ 268one | 269two | 270^three | 271four | 272{1:~ }|*3 273| 274]] ) 275feed ( '1G' ) 276screen : expect ( [[ 277^one | 278{13:+-- 2 lines: two····························}| 279four | 280{1:~ }|*4 281| 282]] ) 283feed ( '2G' ) 284screen : expect ( [[ 285one | 286^two | 287three | 288four | 289{1:~ }|*3 290| 291]] ) 292feed ( 'k' ) 293screen : expect ( [[ 294^one | 295{13:+-- 2 lines: two····························}| 296four | 297{1:~ }|*4 298| 299]] ) 300end ) 301 302-- oldtest: Test_foldtext_and_fillchars_rightleft() 303it ( "fold text is displayed properly with 'rightleft'" , function () 304screen : try_resize ( 70 , 5 ) 305exec ( [[ 306let longtext = 'Lorem ipsum dolor sit amet, consectetur adipiscing' 307let g:multibyte = 'Lorem ipsum dolor sit amet' 308 309call setline(1, [longtext, longtext, longtext]) 3101,2fold 311 312setlocal rightleft 313set noshowmode noshowcmd 314]] ) 315screen : expect ( [[ 316{13:······gnicsipida rutetcesnoc ,tema tis rolod muspi meroL :senil 2 --^+}| 317gnicsipida rutetcesnoc ,tema tis rolod muspi meroL| 318{1: ~}|*2 319| 320]] ) 321command ( 'call setline(1, [g:multibyte, g:multibyte, g:multibyte])' ) 322screen : expect ( [[ 323{13:········tema tis rolod muspi meroL :senil 2 -^-+}| 324tema tis rolod muspi meroL| 325{1: ~}|*2 326| 327]] ) 328end ) 329end )