Bram Moolenaar | 41e0f2f | 2016-03-08 14:44:42 +0100 | [diff] [blame] | 1 | " Test for joining lines. |
| 2 | |
| 3 | func 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! |
| 13 | endfunc |
Bram Moolenaar | 53f0c96 | 2017-10-22 14:23:59 +0200 | [diff] [blame] | 14 | |
| 15 | " Tests for setting the '[,'] marks when joining lines. |
| 16 | func 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! |
| 35 | endfunc |
Bram Moolenaar | fb222df | 2019-05-14 17:57:19 +0200 | [diff] [blame] | 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 |
| 41 | func Test_join_spaces_marks() |
| 42 | new |
| 43 | " Text used for the test |
| 44 | insert |
| 45 | asdfasdf. |
| 46 | asdf |
| 47 | asdfasdf. |
| 48 | asdf |
| 49 | asdfasdf. |
| 50 | asdf |
| 51 | asdfasdf. |
| 52 | asdf |
| 53 | asdfasdf. |
| 54 | asdf |
| 55 | asdfasdf. |
| 56 | asdf |
| 57 | asdfasdf. |
| 58 | asdf |
| 59 | asdfasdf |
| 60 | asdf |
| 61 | asdfasdf |
| 62 | asdf |
| 63 | asdfasdf |
| 64 | asdf |
| 65 | asdfasdf |
| 66 | asdf |
| 67 | asdfasdf |
| 68 | asdf |
| 69 | asdfasdf |
| 70 | asdf |
| 71 | asdfasdf |
| 72 | asdf |
| 73 | zx cvn. |
| 74 | as dfg? |
| 75 | hjkl iop! |
| 76 | ert |
| 77 | zx cvn. |
| 78 | as dfg? |
| 79 | hjkl iop! |
| 80 | ert |
| 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 | normal G |
| 102 | let last_line = line('$') |
| 103 | |
| 104 | " Expected output |
| 105 | append |
| 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 | asdfasdf asdf |
| 118 | asdfasdf asdf |
| 119 | asdfasdf asdf |
| 120 | zx cvn. as dfg? hjkl iop! ert ernop |
| 121 | zx cvn. as dfg? hjkl iop! ert ernop |
| 122 | . |
| 123 | |
| 124 | call assert_equal(getline(last_line + 1, '$'), getline(1, last_line)) |
| 125 | |
| 126 | enew! |
| 127 | call append(0, text) |
| 128 | normal gg |
| 129 | |
| 130 | set cpoptions-=j |
| 131 | set joinspaces |
| 132 | normal JjJjJjJjJjJjJjJjJjJjJjJjJjJ |
| 133 | normal j05lmx |
| 134 | normal 2j06lmy |
| 135 | normal 2k4Jy3l$p |
| 136 | normal `xyl$p |
| 137 | normal `yy2l$p |
| 138 | |
| 139 | set cpoptions+=j |
| 140 | normal j05lmx |
| 141 | normal 2j06lmy |
| 142 | normal 2k4Jy3l$p |
| 143 | normal `xyl$p |
| 144 | normal `yy2l$p |
| 145 | |
| 146 | normal G |
| 147 | let last_line = line('$') |
| 148 | |
| 149 | " Expected output |
| 150 | append |
| 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 | asdfasdf asdf |
| 160 | asdfasdf asdf |
| 161 | asdfasdf asdf |
| 162 | asdfasdf asdf |
| 163 | asdfasdf asdf |
| 164 | asdfasdf asdf |
| 165 | zx cvn. as dfg? hjkl iop! ert enop |
| 166 | zx cvn. as dfg? hjkl iop! ert ernop |
| 167 | |
| 168 | . |
| 169 | |
| 170 | call assert_equal(getline(last_line + 1, '$'), getline(1, last_line)) |
| 171 | |
| 172 | enew! |
| 173 | call append(0, text) |
| 174 | normal gg |
| 175 | |
| 176 | set cpoptions-=j |
| 177 | set nojoinspaces |
| 178 | set compatible |
| 179 | |
| 180 | normal JjJjJjJjJjJjJjJjJjJjJjJjJjJ |
| 181 | normal j4Jy3l$pjdG |
| 182 | |
| 183 | normal G |
| 184 | let last_line = line('$') |
| 185 | |
| 186 | " Expected output |
| 187 | append |
| 188 | asdfasdf. asdf |
| 189 | asdfasdf. asdf |
| 190 | asdfasdf. asdf |
| 191 | asdfasdf. asdf |
| 192 | asdfasdf. asdf |
| 193 | asdfasdf. asdf |
| 194 | asdfasdf. asdf |
| 195 | asdfasdf asdf |
| 196 | asdfasdf asdf |
| 197 | asdfasdf asdf |
| 198 | asdfasdf asdf |
| 199 | asdfasdf asdf |
| 200 | asdfasdf asdf |
| 201 | asdfasdf asdf |
| 202 | zx cvn. as dfg? hjkl iop! ert a |
| 203 | . |
| 204 | |
| 205 | call assert_equal(getline(last_line + 1, '$'), getline(1, last_line)) |
| 206 | |
| 207 | set nocompatible |
| 208 | set cpoptions&vim |
| 209 | set joinspaces&vim |
| 210 | close! |
| 211 | endfunc |
| 212 | |
| 213 | " Test for joining lines with comments |
| 214 | func Test_join_lines_with_comments() |
| 215 | new |
| 216 | |
| 217 | " Text used by the test |
| 218 | insert |
| 219 | { |
| 220 | |
| 221 | /* |
| 222 | * Make sure the previous comment leader is not removed. |
| 223 | */ |
| 224 | |
| 225 | /* |
| 226 | * Make sure the previous comment leader is not removed. |
| 227 | */ |
| 228 | |
| 229 | // Should the next comment leader be left alone? |
| 230 | // Yes. |
| 231 | |
| 232 | // Should the next comment leader be left alone? |
| 233 | // Yes. |
| 234 | |
| 235 | /* Here the comment leader should be left intact. */ |
| 236 | // And so should this one. |
| 237 | |
| 238 | /* Here the comment leader should be left intact. */ |
| 239 | // And so should this one. |
| 240 | |
| 241 | if (condition) // Remove the next comment leader! |
| 242 | // OK, I will. |
| 243 | action(); |
| 244 | |
| 245 | if (condition) // Remove the next comment leader! |
| 246 | // OK, I will. |
| 247 | action(); |
| 248 | } |
| 249 | . |
| 250 | |
| 251 | call cursor(2, 1) |
| 252 | set comments=s1:/*,mb:*,ex:*/,:// |
| 253 | set nojoinspaces fo=j |
| 254 | set backspace=eol,start |
| 255 | |
| 256 | .,+3join |
| 257 | exe "normal j4J\<CR>" |
| 258 | .,+2join |
| 259 | exe "normal j3J\<CR>" |
| 260 | .,+2join |
| 261 | exe "normal j3J\<CR>" |
| 262 | .,+2join |
| 263 | exe "normal jj3J\<CR>" |
| 264 | |
| 265 | normal G |
| 266 | let last_line = line('$') |
| 267 | |
| 268 | " Expected output |
| 269 | append |
| 270 | { |
| 271 | /* Make sure the previous comment leader is not removed. */ |
| 272 | /* Make sure the previous comment leader is not removed. */ |
| 273 | // Should the next comment leader be left alone? Yes. |
| 274 | // Should the next comment leader be left alone? Yes. |
| 275 | /* Here the comment leader should be left intact. */ // And so should this one. |
| 276 | /* Here the comment leader should be left intact. */ // And so should this one. |
| 277 | if (condition) // Remove the next comment leader! OK, I will. |
| 278 | action(); |
| 279 | if (condition) // Remove the next comment leader! OK, I will. |
| 280 | action(); |
| 281 | } |
| 282 | . |
| 283 | |
| 284 | call assert_equal(getline(last_line + 1, '$'), getline(1, last_line)) |
| 285 | |
| 286 | set comments&vim |
| 287 | set joinspaces&vim |
| 288 | set fo&vim |
| 289 | set backspace&vim |
| 290 | close! |
| 291 | endfunc |
| 292 | |
| 293 | " Test for joining lines with different comment leaders |
| 294 | func Test_join_comments_2() |
| 295 | new |
| 296 | |
| 297 | insert |
| 298 | { |
| 299 | |
| 300 | /* |
| 301 | * Make sure the previous comment leader is not removed. |
| 302 | */ |
| 303 | |
| 304 | /* |
| 305 | * Make sure the previous comment leader is not removed. |
| 306 | */ |
| 307 | |
| 308 | /* List: |
| 309 | * - item1 |
| 310 | * foo bar baz |
| 311 | * foo bar baz |
| 312 | * - item2 |
| 313 | * foo bar baz |
| 314 | * foo bar baz |
| 315 | */ |
| 316 | |
| 317 | /* List: |
| 318 | * - item1 |
| 319 | * foo bar baz |
| 320 | * foo bar baz |
| 321 | * - item2 |
| 322 | * foo bar baz |
| 323 | * foo bar baz |
| 324 | */ |
| 325 | |
| 326 | // Should the next comment leader be left alone? |
| 327 | // Yes. |
| 328 | |
| 329 | // Should the next comment leader be left alone? |
| 330 | // Yes. |
| 331 | |
| 332 | /* Here the comment leader should be left intact. */ |
| 333 | // And so should this one. |
| 334 | |
| 335 | /* Here the comment leader should be left intact. */ |
| 336 | // And so should this one. |
| 337 | |
| 338 | if (condition) // Remove the next comment leader! |
| 339 | // OK, I will. |
| 340 | action(); |
| 341 | |
| 342 | if (condition) // Remove the next comment leader! |
| 343 | // OK, I will. |
| 344 | action(); |
| 345 | |
| 346 | int i = 7 /* foo *// 3 |
| 347 | // comment |
| 348 | ; |
| 349 | |
| 350 | int i = 7 /* foo *// 3 |
| 351 | // comment |
| 352 | ; |
| 353 | |
| 354 | ># Note that the last character of the ending comment leader (left angle |
| 355 | # bracket) is a comment leader itself. Make sure that this comment leader is |
| 356 | # not removed from the next line #< |
| 357 | < On this line a new comment is opened which spans 2 lines. This comment should |
| 358 | < retain its comment leader. |
| 359 | |
| 360 | ># Note that the last character of the ending comment leader (left angle |
| 361 | # bracket) is a comment leader itself. Make sure that this comment leader is |
| 362 | # not removed from the next line #< |
| 363 | < On this line a new comment is opened which spans 2 lines. This comment should |
| 364 | < retain its comment leader. |
| 365 | |
| 366 | } |
| 367 | . |
| 368 | |
| 369 | call cursor(2, 1) |
| 370 | set comments=sO:*\ -,mO:*\ \ ,exO:*/ |
| 371 | set comments+=s1:/*,mb:*,ex:*/,:// |
| 372 | set comments+=s1:>#,mb:#,ex:#<,:< |
| 373 | set cpoptions-=j joinspaces fo=j |
| 374 | set backspace=eol,start |
| 375 | |
| 376 | .,+3join |
| 377 | exe "normal j4J\<CR>" |
| 378 | .,+8join |
| 379 | exe "normal j9J\<CR>" |
| 380 | .,+2join |
| 381 | exe "normal j3J\<CR>" |
| 382 | .,+2join |
| 383 | exe "normal j3J\<CR>" |
| 384 | .,+2join |
| 385 | exe "normal jj3J\<CR>j" |
| 386 | .,+2join |
| 387 | exe "normal jj3J\<CR>j" |
| 388 | .,+5join |
| 389 | exe "normal j6J\<CR>" |
| 390 | exe "normal oSome code!\<CR>// Make sure backspacing does not remove this comment leader.\<Esc>0i\<C-H>\<Esc>" |
| 391 | |
| 392 | normal G |
| 393 | let last_line = line('$') |
| 394 | |
| 395 | " Expected output |
| 396 | append |
| 397 | { |
| 398 | /* Make sure the previous comment leader is not removed. */ |
| 399 | /* Make sure the previous comment leader is not removed. */ |
| 400 | /* List: item1 foo bar baz foo bar baz item2 foo bar baz foo bar baz */ |
| 401 | /* List: item1 foo bar baz foo bar baz item2 foo bar baz foo bar baz */ |
| 402 | // Should the next comment leader be left alone? Yes. |
| 403 | // Should the next comment leader be left alone? Yes. |
| 404 | /* Here the comment leader should be left intact. */ // And so should this one. |
| 405 | /* Here the comment leader should be left intact. */ // And so should this one. |
| 406 | if (condition) // Remove the next comment leader! OK, I will. |
| 407 | action(); |
| 408 | if (condition) // Remove the next comment leader! OK, I will. |
| 409 | action(); |
| 410 | int i = 7 /* foo *// 3 // comment |
| 411 | ; |
| 412 | int i = 7 /* foo *// 3 // comment |
| 413 | ; |
| 414 | ># 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. |
| 415 | ># 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. |
| 416 | |
| 417 | Some code!// Make sure backspacing does not remove this comment leader. |
| 418 | } |
| 419 | . |
| 420 | |
| 421 | call assert_equal(getline(last_line + 1, '$'), getline(1, last_line)) |
| 422 | close! |
| 423 | endfunc |