robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
af23d17388
master
1" Test for joining lines. 2 3func Test_join_with_count () 4new 5call setline ( 1 , [ 'one' , 'two' , 'three' , 'four' ]) 6normal J 7call assert_equal ( 'one two' , getline ( 1 )) 8 %del 9call setline ( 1 , [ 'one' , 'two' , 'three' , 'four' ]) 10normal 10J 11call assert_equal ( 'one two three four' , getline ( 1 )) 12 13call setline ( 1 , [ 'one' , '' , 'two' ]) 14normal J 15call assert_equal ( 'one' , getline ( 1 )) 16 17call setline ( 1 , [ 'one' , ' ' , 'two' ]) 18normal J 19call assert_equal ( 'one' , getline ( 1 )) 20 21call setline ( 1 , [ 'one' , '' , '' , 'two' ]) 22normal JJ 23call assert_equal ( 'one' , getline ( 1 )) 24 25call setline ( 1 , [ 'one' , ' ' , ' ' , 'two' ]) 26normal JJ 27call assert_equal ( 'one' , getline ( 1 )) 28 29call setline ( 1 , [ 'one' , '' , '' , 'two' ]) 30normal 2J 31call assert_equal ( 'one' , getline ( 1 )) 32 33quit ! 34endfunc 35 36" Tests for setting the '[,'] marks when joining lines. 37func Test_join_marks () 38enew 39call append ( 0 , [ 40 \"\t\tO sodales, ludite, vos qui" , 41 \"attamen consulite per voster honur. Tua pulchra " . 42 \"facies me fay planszer milies" , 43 \"" , 44 \"This line." , 45 \"Should be joined with the next line" , 46 \"and with this line" ]) 47 48normal gg0gqj 49call assert_equal ([ 0 , 1 , 1 , 0 ], getpos ( "'[" )) 50call assert_equal ([ 0 , 2 , 1 , 0 ], getpos ( "']" )) 51 52/ ^This line / ;'}-join 53call assert_equal ([ 0 , 4 , 11 , 0 ], getpos ( "'[" )) 54call assert_equal ([ 0 , 4 , 67 , 0 ], getpos ( "']" )) 55enew ! 56endfunc 57 58" Test for joining lines and marks in them 59" in compatible and nocompatible modes 60" and with 'joinspaces' set or not 61" and with 'cpoptions' flag 'j' set or not 62func Test_join_spaces_marks () 63new 64" Text used for the test 65insert 66asdfasdf . 67asdf 68asdfasdf . 69asdf 70asdfasdf . 71asdf 72asdfasdf . 73asdf 74asdfasdf . 75asdf 76asdfasdf . 77asdf 78asdfasdf . 79asdf 80asdfasdf 81asdf 82asdfasdf 83asdf 84asdfasdf 85asdf 86asdfasdf 87asdf 88asdfasdf 89asdf 90asdfasdf 91asdf 92asdfasdf 93asdf 94zx cvn. 95as dfg? 96hjkl iop! 97ert 98zx cvn. 99as dfg? 100hjkl iop! 101ert 102. 103let text = getline ( 1 , '$' ) 104normal gg 105 106set nojoinspaces 107set cpoptions -= j 108normal JjJjJjJjJjJjJjJjJjJjJjJjJjJ 109normal j05lmx 110normal 2j06lmy 111normal 2k4Jy3l$p 112normal `xyl$p 113normal `yy2l$p 114 115" set cpoptions+=j 116normal j05lmx 117normal 2j06lmy 118normal 2k4Jy3l$p 119normal `xyl$p 120normal `yy2l$p 121 122" Expected output 123let expected =<< trim [DATA] 124asdfasdf. asdf 125asdfasdf. asdf 126asdfasdf. asdf 127asdfasdf. asdf 128asdfasdf. asdf 129asdfasdf. asdf 130asdfasdf. asdf 131asdfasdf asdf 132asdfasdf asdf 133asdfasdf asdf 134asdfasdf asdf 135asdfasdf asdf 136asdfasdf asdf 137asdfasdf asdf 138zx cvn. as dfg? hjkl iop! ert ernop 139zx cvn. as dfg? hjkl iop! ert ernop 140[DATA] 141 142call assert_equal ( expected , getline ( 1 , '$' )) 143throw 'skipped: Nvim does not support "set compatible" or "set cpoptions+=j"' 144 145enew ! 146call append ( 0 , text ) 147normal gg 148 149set cpoptions -= j 150set joinspaces 151normal JjJjJjJjJjJjJjJjJjJjJjJjJjJ 152normal j05lmx 153normal 2j06lmy 154normal 2k4Jy3l$p 155normal `xyl$p 156normal `yy2l$p 157 158set cpoptions += j 159normal j05lmx 160normal 2j06lmy 161normal 2k4Jy3l$p 162normal `xyl$p 163normal `yy2l$p 164 165" Expected output 166let expected =<< trim [DATA] 167asdfasdf. asdf 168asdfasdf. asdf 169asdfasdf. asdf 170asdfasdf. asdf 171asdfasdf. asdf 172asdfasdf. asdf 173asdfasdf. asdf 174asdfasdf asdf 175asdfasdf asdf 176asdfasdf asdf 177asdfasdf asdf 178asdfasdf asdf 179asdfasdf asdf 180asdfasdf asdf 181zx cvn. as dfg? hjkl iop! ert enop 182zx cvn. as dfg? hjkl iop! ert ernop 183 184[DATA] 185 186call assert_equal ( expected , getline ( 1 , '$' )) 187 188enew ! 189call append ( 0 , text ) 190normal gg 191 192set cpoptions -= j 193set nojoinspaces 194set compatible 195 196normal JjJjJjJjJjJjJjJjJjJjJjJjJjJ 197normal j4Jy3l$pjdG 198 199" Expected output 200let expected =<< trim [DATA] 201asdfasdf. asdf 202asdfasdf. asdf 203asdfasdf. asdf 204asdfasdf. asdf 205asdfasdf. asdf 206asdfasdf. asdf 207asdfasdf. asdf 208asdfasdf asdf 209asdfasdf asdf 210asdfasdf asdf 211asdfasdf asdf 212asdfasdf asdf 213asdfasdf asdf 214asdfasdf asdf 215zx cvn. as dfg? hjkl iop! ert a 216[DATA] 217 218call assert_equal ( expected , getline ( 1 , '$' )) 219 220set nocompatible 221set cpoptions & vim 222set joinspaces & vim 223close ! 224endfunc 225 226" Test for joining lines with comments 227func Test_join_lines_with_comments () 228new 229 230" Text used by the test 231insert 232{ 233 234/ * 235* Make sure the previous comment leader is not removed. 236* / 237 238/ * 239* Make sure the previous comment leader is not removed. 240* / 241 242/ / Should the next comment leader be left alone? 243/ / Yes. 244 245/ / Should the next comment leader be left alone? 246/ / Yes. 247 248/ * Here the comment leader should be left intact. */ 249/ / And so should this one. 250 251/ * Here the comment leader should be left intact. */ 252/ / And so should this one. 253 254if ( condition ) // Remove the next comment leader! 255/ / OK , I will. 256action (); 257 258if ( condition ) // Remove the next comment leader! 259/ / OK , I will. 260action (); 261} 262. 263 264call cursor ( 2 , 1 ) 265set comments = s1:/*,mb:*,ex:*/,:// 266set nojoinspaces fo = j 267set backspace = eol,start 268 269 ., +3 join 270exe "normal j4J\<CR>" 271 ., +2 join 272exe "normal j3J\<CR>" 273 ., +2 join 274exe "normal j3J\<CR>" 275 ., +2 join 276exe "normal jj3J\<CR>" 277 278" Expected output 279let expected =<< trim [CODE] 280{ 281/* Make sure the previous comment leader is not removed. */ 282/* Make sure the previous comment leader is not removed. */ 283// Should the next comment leader be left alone? Yes. 284// Should the next comment leader be left alone? Yes. 285/* Here the comment leader should be left intact. */ // And so should this one. 286/* Here the comment leader should be left intact. */ // And so should this one. 287if (condition) // Remove the next comment leader! OK, I will. 288action(); 289if (condition) // Remove the next comment leader! OK, I will. 290action(); 291} 292[CODE] 293 294call assert_equal ( expected , getline ( 1 , '$' )) 295 296set comments & vim 297set joinspaces & vim 298set fo & vim 299set backspace & vim 300close ! 301endfunc 302 303" Test for joining lines with different comment leaders 304func Test_join_comments_2 () 305new 306 307insert 308{ 309 310/ * 311* Make sure the previous comment leader is not removed. 312* / 313 314/ * 315* Make sure the previous comment leader is not removed. 316* / 317 318/ * List: 319* - item1 320* foo bar baz 321* foo bar baz 322* - item2 323* foo bar baz 324* foo bar baz 325* / 326 327/ * List: 328* - item1 329* foo bar baz 330* foo bar baz 331* - item2 332* foo bar baz 333* foo bar baz 334* / 335 336/ / Should the next comment leader be left alone? 337/ / Yes. 338 339/ / Should the next comment leader be left alone? 340/ / Yes. 341 342/ * Here the comment leader should be left intact. */ 343/ / And so should this one. 344 345/ * Here the comment leader should be left intact. */ 346/ / And so should this one. 347 348if ( condition ) // Remove the next comment leader! 349/ / OK , I will. 350action (); 351 352if ( condition ) // Remove the next comment leader! 353/ / OK , I will. 354action (); 355 356int i = 7 /* foo *// 3 357/ / comment 358 ; 359 360int i = 7 /* foo *// 3 361/ / comment 362 ; 363 364> #Note that the last character of the ending comment leader (left angle 365 # bracket) is a comment leader itself.Make sure that this comment leader is 366 # not removed from the next line #< 367<On this line a new comment is opened which spans2 lines.This comment should 368< retain its comment leader. 369 370> #Note that the last character of the ending comment leader (left angle 371 # bracket) is a comment leader itself.Make sure that this comment leader is 372 # not removed from the next line #< 373<On this line a new comment is opened which spans2 lines.This comment should 374< retain its comment leader. 375 376} 377. 378 379call cursor ( 2 , 1 ) 380set comments = sO:*\ -,mO:*\ \ ,exO:*/ 381set comments += s1:/*,mb:*,ex:*/,:// 382set comments += s1:>#,mb:#,ex:#<,:< 383set cpoptions -= jjoinspaces fo = j 384set backspace = eol,start 385 386 ., +3 join 387exe "normal j4J\<CR>" 388 ., +8 join 389exe "normal j9J\<CR>" 390 ., +2 join 391exe "normal j3J\<CR>" 392 ., +2 join 393exe "normal j3J\<CR>" 394 ., +2 join 395exe "normal jj3J\<CR>j" 396 ., +2 join 397exe "normal jj3J\<CR>j" 398 ., +5 join 399exe "normal j6J\<CR>" 400exe "normal oSome code!\<CR>// Make sure backspacing does not remove this comment leader.\<Esc>0i\<C-H>\<Esc>" 401 402" Expected output 403let expected =<< trim [CODE] 404{ 405/* Make sure the previous comment leader is not removed. */ 406/* Make sure the previous comment leader is not removed. */ 407/* List: item1 foo bar baz foo bar baz item2 foo bar baz foo bar baz */ 408/* List: item1 foo bar baz foo bar baz item2 foo bar baz foo bar baz */ 409// Should the next comment leader be left alone? Yes. 410// Should the next comment leader be left alone? Yes. 411/* Here the comment leader should be left intact. */ // And so should this one. 412/* Here the comment leader should be left intact. */ // And so should this one. 413if (condition) // Remove the next comment leader! OK, I will. 414action(); 415if (condition) // Remove the next comment leader! OK, I will. 416action(); 417int i = 7 /* foo *// 3 // comment 418; 419int i = 7 /* foo *// 3 // comment 420; 421># 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. 422># 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. 423424 Some code!// Make sure backspacing does not remove this comment leader. 425} 426[CODE] 427 428call assert_equal ( expected , getline ( 1 , '$' )) 429close ! 430endfunc 431 432func Test_join_lines () 433new 434call setline ( 1 , [ 'a' , 'b' , '' , 'c' , 'd' ]) 435 %join 436call assert_equal ( 'a b c d' , getline ( 1 )) 437call setline ( 1 , [ 'a' , 'b' , '' , 'c' , 'd' ]) 438normal 5J 439call assert_equal ( 'a b c d' , getline ( 1 )) 440call setline ( 1 , [ 'a' , 'b' , 'c' ]) 4412 , 2 join 442call assert_equal ([ 'a' , 'b' , 'c' ], getline ( 1 , '$' )) 443call assert_equal ( 2 , line ( '.' )) 4442 join 445call assert_equal ([ 'a' , 'b c' ], getline ( 1 , '$' )) 446bwipe ! 447endfunc