robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
f907614088
master
1-- Test for joining lines 2 3local t =require ( 'test.testutil' ) 4local n =require ( 'test.functional.testnvim' )() 5 6local describe , it , before_each =t . describe , t . it , t . before_each 7local clear , eq =n . clear , t . eq 8local eval , command =n . eval , n . command 9local feed =n . feed 10local insert =n . insert 11local expect =n . expect 12local feed_command =n . feed_command 13 14describe ( 'joining lines' , function () 15before_each ( clear ) 16 17it ( 'is working' , function () 18command ( 'new' ) 19command ( [[call setline(1, ['one', 'two', 'three', 'four'])]] ) 20command ( 'normal J' ) 21eq ( 'one two' , eval ( 'getline(1)' )) 22command ( '%del' ) 23command ( [[call setline(1, ['one', 'two', 'three', 'four'])]] ) 24command ( 'normal 10J' ) 25eq ( 'one two three four' , eval ( 'getline(1)' )) 26end ) 27 28-- luacheck: ignore 613 (Trailing whitespaces in a string) 29-- luacheck: ignore 611 (Line contains only whitespaces) 30it ( "keeps marks with different 'joinspaces' settings" , function () 31insert ( [[ 32firstline 33asdfasdf. 34asdf 35asdfasdf. 36asdf 37asdfasdf. 38asdf 39asdfasdf. 40asdf 41asdfasdf. 42asdf 43asdfasdf. 44asdf 45asdfasdf. 46asdf 47asdfasdf 48asdf 49asdfasdf 50asdf 51asdfasdf 52asdf 53asdfasdf 54asdf 55asdfasdf 56asdf 57asdfasdf 58asdf 59asdfasdf 60asdf 61zx cvn. 62as dfg? 63hjkl iop! 64ert 65]] ) 66 67-- Switch off 'joinspaces', then join some lines in the buffer using "J". 68-- Also set a few marks and record their movement when joining lines. 69feed_command ( 'set nojoinspaces' ) 70feed_command ( '/firstline/' ) 71feed ( 'j"td/^$/<cr>' ) 72feed ( 'PJjJjJjJjJjJjJjJjJjJjJjJjJjJ' ) 73feed ( 'j05lmx2j06lmy2k4Jy3l$p`xyl$p`yy2l$p' ) 74 75-- Do the same with 'joinspaces' on. 76feed_command ( 'set joinspaces' ) 77feed ( 'j"tp' ) 78feed ( 'JjJjJjJjJjJjJjJjJjJjJjJjJjJ' ) 79feed ( 'j05lmx2j06lmy2k4Jy3l$p`xyl$p`yy2l$po<esc>' ) 80 81feed_command ( '1d' ) 82 83expect ( [[ 84asdfasdf. asdf 85asdfasdf. asdf 86asdfasdf. asdf 87asdfasdf. asdf 88asdfasdf. asdf 89asdfasdf. asdf 90asdfasdf. asdf 91asdfasdf asdf 92asdfasdf asdf 93asdfasdf asdf 94asdfasdf asdf 95asdfasdf asdf 96asdfasdf asdf 97asdfasdf asdf 98zx cvn. as dfg? hjkl iop! ert ernop 99100 asdfasdf. asdf 101asdfasdf. asdf 102asdfasdf. asdf 103asdfasdf. asdf 104asdfasdf. asdf 105asdfasdf. asdf 106asdfasdf. asdf 107asdfasdf asdf 108asdfasdf asdf 109asdfasdf asdf 110asdfasdf asdf 111asdfasdf asdf 112asdfasdf asdf 113asdfasdf asdf 114zx cvn. as dfg? hjkl iop! ert enop 115]] ) 116end ) 117 118it ( "removes comment leaders with 'joinspaces' off" , function () 119insert ( [[ 120{ 121122 /* 123* Make sure the previous comment leader is not removed. 124*/ 125126 /* 127* Make sure the previous comment leader is not removed. 128*/ 129130 // Should the next comment leader be left alone? 131// Yes. 132133 // Should the next comment leader be left alone? 134// Yes. 135136 /* Here the comment leader should be left intact. */ 137// And so should this one. 138139 /* Here the comment leader should be left intact. */ 140// And so should this one. 141142 if (condition) // Remove the next comment leader! 143// OK, I will. 144action(); 145146 if (condition) // Remove the next comment leader! 147// OK, I will. 148action(); 149} 150]] ) 151 152feed_command ( '/^{/+1' ) 153feed_command ( 'set comments=s1:/*,mb:*,ex:*/,://' ) 154feed_command ( 'set nojoinspaces' ) 155feed_command ( 'set backspace=eol,start' ) 156 157-- With 'joinspaces' switched off, join lines using both "J" and :join and 158-- verify that comment leaders are stripped or kept as appropriate. 159feed_command ( '.,+3join' ) 160feed ( 'j4J<cr>' ) 161feed_command ( '.,+2join' ) 162feed ( 'j3J<cr>' ) 163feed_command ( '.,+2join' ) 164feed ( 'j3J<cr>' ) 165feed_command ( '.,+2join' ) 166feed ( 'jj3J<cr>' ) 167 168expect ( [[ 169{ 170/* Make sure the previous comment leader is not removed. */ 171/* Make sure the previous comment leader is not removed. */ 172// Should the next comment leader be left alone? Yes. 173// Should the next comment leader be left alone? Yes. 174/* Here the comment leader should be left intact. */ // And so should this one. 175/* Here the comment leader should be left intact. */ // And so should this one. 176if (condition) // Remove the next comment leader! OK, I will. 177action(); 178if (condition) // Remove the next comment leader! OK, I will. 179action(); 180} 181]] ) 182end ) 183 184-- This test case has nothing to do with joining lines. 185it ( "Ctrl-u and 'backspace' compatibility" , function () 186-- Notice that the buffer text, which is intended to helpfully hint at 187-- what's being done in the test, is off by one line. (For example, "this 188-- should be deleted" should not be deleted, but the line below it should, 189-- and is.) This is likely a mistake, but was kept here for consistency. 190insert ( [[ 1911 this shouldn't be deleted 1922 this shouldn't be deleted 1933 this shouldn't be deleted 1944 this should be deleted 1955 this shouldn't be deleted 1966 this shouldn't be deleted 1977 this shouldn't be deleted 1988 this shouldn't be deleted (not touched yet) 199]] ) 200 201-- As mentioned above, we mimic the wrong initial cursor position in the old 202-- test by advancing one line further. 203feed_command ( [[/^\d\+ this]] , '+1' ) 204 205-- Test with the default 'backspace' setting. 206feed ( 'Avim1<c-u><esc><cr>' ) 207feed ( 'Avim2<c-g>u<c-u><esc><cr>' ) 208feed_command ( 'set cpo-=<' ) 209feed_command ( 'inoremap <c-u> <left><c-u>' ) 210feed ( 'Avim3<c-u><esc><cr>' ) 211feed_command ( 'iunmap <c-u>' ) 212feed ( 'Avim4<c-u><c-u><esc><cr>' ) 213 214-- Test with 'backspace' set to the compatible setting. 215feed_command ( 'set backspace=' ) 216feed ( 'A vim5<esc>A<c-u><c-u><esc><cr>' ) 217feed ( 'A vim6<esc>Azwei<c-g>u<c-u><esc><cr>' ) 218feed_command ( 'inoremap <c-u> <left><c-u>' ) 219feed ( 'A vim7<c-u><c-u><esc><cr>' ) 220 221expect ( [[ 2221 this shouldn't be deleted 2232 this shouldn't be deleted 2243 this shouldn't be deleted 2254 this should be deleted3 226227 6 this shouldn't be deleted vim5 2287 this shouldn't be deleted vim6 2298 this shouldn't be deleted (not touched yet) vim7 230]] ) 231end ) 232 233it ( "removes comment leaders with 'joinspaces' on" , function () 234insert ( [[ 235{ 236237 /* 238* Make sure the previous comment leader is not removed. 239*/ 240241 /* 242* Make sure the previous comment leader is not removed. 243*/ 244245 /* List: 246* - item1 247* foo bar baz 248* foo bar baz 249* - item2 250* foo bar baz 251* foo bar baz 252*/ 253254 /* List: 255* - item1 256* foo bar baz 257* foo bar baz 258* - item2 259* foo bar baz 260* foo bar baz 261*/ 262263 // Should the next comment leader be left alone? 264// Yes. 265266 // Should the next comment leader be left alone? 267// Yes. 268269 /* Here the comment leader should be left intact. */ 270// And so should this one. 271272 /* Here the comment leader should be left intact. */ 273// And so should this one. 274275 if (condition) // Remove the next comment leader! 276// OK, I will. 277action(); 278279 if (condition) // Remove the next comment leader! 280// OK, I will. 281action(); 282283 int i = 7 /* foo *// 3 284// comment 285; 286287 int i = 7 /* foo *// 3 288// comment 289; 290291 ># Note that the last character of the ending comment leader (left angle 292# bracket) is a comment leader itself. Make sure that this comment leader is 293# not removed from the next line #< 294< On this line a new comment is opened which spans 2 lines. This comment should 295< retain its comment leader. 296297 ># Note that the last character of the ending comment leader (left angle 298# bracket) is a comment leader itself. Make sure that this comment leader is 299# not removed from the next line #< 300< On this line a new comment is opened which spans 2 lines. This comment should 301< retain its comment leader. 302303 } 304]] ) 305 306feed_command ( '/^{/+1' ) 307feed_command ( [[set comments=sO:*\ -,mO:*\ \ ,exO:*/]] ) 308feed_command ( 'set comments+=s1:/*,mb:*,ex:*/,://' ) 309feed_command ( 'set comments+=s1:>#,mb:#,ex:#<,:<' ) 310feed_command ( 'set backspace=eol,start' ) 311 312-- With 'joinspaces' on (the default setting), again join lines and verify 313-- that comment leaders are stripped or kept as appropriate. 314feed_command ( '.,+3join' ) 315feed ( 'j4J<cr>' ) 316feed_command ( '.,+8join' ) 317feed ( 'j9J<cr>' ) 318feed_command ( '.,+2join' ) 319feed ( 'j3J<cr>' ) 320feed_command ( '.,+2join' ) 321feed ( 'j3J<cr>' ) 322feed_command ( '.,+2join' ) 323feed ( 'jj3J<cr>' ) 324feed ( 'j' ) 325feed_command ( '.,+2join' ) 326feed ( 'jj3J<cr>' ) 327feed ( 'j' ) 328feed_command ( '.,+5join' ) 329feed ( 'j6J<cr>' ) 330feed ( 331'oSome code!<cr>// Make sure backspacing does not remove this comment leader.<esc>0i<bs><esc>' 332) 333 334expect ( [[ 335{ 336/* Make sure the previous comment leader is not removed. */ 337/* Make sure the previous comment leader is not removed. */ 338/* List: item1 foo bar baz foo bar baz item2 foo bar baz foo bar baz */ 339/* List: item1 foo bar baz foo bar baz item2 foo bar baz foo bar baz */ 340// Should the next comment leader be left alone? Yes. 341// Should the next comment leader be left alone? Yes. 342/* Here the comment leader should be left intact. */ // And so should this one. 343/* Here the comment leader should be left intact. */ // And so should this one. 344if (condition) // Remove the next comment leader! OK, I will. 345action(); 346if (condition) // Remove the next comment leader! OK, I will. 347action(); 348int i = 7 /* foo *// 3 // comment 349; 350int i = 7 /* foo *// 3 // comment 351; 352># Note that the last character of the ending comment leader (left angle bracket) is a comment leader itself. Make sure that this comment leader is not removed from the next line #< < On this line a new comment is opened which spans 2 lines. This comment should retain its comment leader. 353># Note that the last character of the ending comment leader (left angle bracket) is a comment leader itself. Make sure that this comment leader is not removed from the next line #< < On this line a new comment is opened which spans 2 lines. This comment should retain its comment leader. 354355 Some code!// Make sure backspacing does not remove this comment leader. 356} 357]] ) 358end ) 359end )