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 | |
Bram Moolenaar | fb222df | 2019-05-14 17:57:19 +0200 | [diff] [blame] | 101 | " Expected output |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 102 | let expected =<< trim [DATA] |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 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 |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 119 | [DATA] |
Bram Moolenaar | fb222df | 2019-05-14 17:57:19 +0200 | [diff] [blame] | 120 | |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 121 | call assert_equal(expected, getline(1, '$')) |
Bram Moolenaar | fb222df | 2019-05-14 17:57:19 +0200 | [diff] [blame] | 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 | |
Bram Moolenaar | fb222df | 2019-05-14 17:57:19 +0200 | [diff] [blame] | 143 | " Expected output |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 144 | let expected =<< trim [DATA] |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 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 |
Bram Moolenaar | fb222df | 2019-05-14 17:57:19 +0200 | [diff] [blame] | 161 | |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 162 | [DATA] |
Bram Moolenaar | fb222df | 2019-05-14 17:57:19 +0200 | [diff] [blame] | 163 | |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 164 | call assert_equal(expected, getline(1, '$')) |
Bram Moolenaar | fb222df | 2019-05-14 17:57:19 +0200 | [diff] [blame] | 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 | |
Bram Moolenaar | fb222df | 2019-05-14 17:57:19 +0200 | [diff] [blame] | 177 | " Expected output |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 178 | let expected =<< trim [DATA] |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 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 |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 194 | [DATA] |
Bram Moolenaar | fb222df | 2019-05-14 17:57:19 +0200 | [diff] [blame] | 195 | |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 196 | call assert_equal(expected, getline(1, '$')) |
Bram Moolenaar | fb222df | 2019-05-14 17:57:19 +0200 | [diff] [blame] | 197 | |
| 198 | set nocompatible |
| 199 | set cpoptions&vim |
| 200 | set joinspaces&vim |
| 201 | close! |
| 202 | endfunc |
| 203 | |
| 204 | " Test for joining lines with comments |
| 205 | func 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 | |
| 232 | if (condition) // Remove the next comment leader! |
| 233 | // OK, I will. |
| 234 | action(); |
| 235 | |
| 236 | if (condition) // Remove the next comment leader! |
| 237 | // OK, I will. |
| 238 | action(); |
| 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 | |
Bram Moolenaar | fb222df | 2019-05-14 17:57:19 +0200 | [diff] [blame] | 256 | " Expected output |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 257 | let expected =<< trim [CODE] |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 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. |
| 265 | if (condition) // Remove the next comment leader! OK, I will. |
| 266 | action(); |
| 267 | if (condition) // Remove the next comment leader! OK, I will. |
| 268 | action(); |
| 269 | } |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 270 | [CODE] |
Bram Moolenaar | fb222df | 2019-05-14 17:57:19 +0200 | [diff] [blame] | 271 | |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 272 | call assert_equal(expected, getline(1, '$')) |
Bram Moolenaar | fb222df | 2019-05-14 17:57:19 +0200 | [diff] [blame] | 273 | |
| 274 | set comments&vim |
| 275 | set joinspaces&vim |
| 276 | set fo&vim |
| 277 | set backspace&vim |
| 278 | close! |
| 279 | endfunc |
| 280 | |
| 281 | " Test for joining lines with different comment leaders |
| 282 | func 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 | |
| 326 | if (condition) // Remove the next comment leader! |
| 327 | // OK, I will. |
| 328 | action(); |
| 329 | |
| 330 | if (condition) // Remove the next comment leader! |
| 331 | // OK, I will. |
| 332 | action(); |
| 333 | |
| 334 | int i = 7 /* foo *// 3 |
| 335 | // comment |
| 336 | ; |
| 337 | |
| 338 | int 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 | |
Bram Moolenaar | fb222df | 2019-05-14 17:57:19 +0200 | [diff] [blame] | 380 | " Expected output |
Bram Moolenaar | e7eb927 | 2019-06-24 00:58:07 +0200 | [diff] [blame] | 381 | let expected =<< trim [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. |
| 391 | if (condition) // Remove the next comment leader! OK, I will. |
| 392 | action(); |
| 393 | if (condition) // Remove the next comment leader! OK, I will. |
| 394 | action(); |
| 395 | int i = 7 /* foo *// 3 // comment |
| 396 | ; |
| 397 | int 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 | |
| 402 | Some code!// Make sure backspacing does not remove this comment leader. |
| 403 | } |
| 404 | [CODE] |
Bram Moolenaar | fb222df | 2019-05-14 17:57:19 +0200 | [diff] [blame] | 405 | |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 406 | call assert_equal(expected, getline(1, '$')) |
Bram Moolenaar | fb222df | 2019-05-14 17:57:19 +0200 | [diff] [blame] | 407 | close! |
| 408 | endfunc |