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