blob: e5ef41ee0a7d1f543d8c48018c425d48721fa7b4 [file] [log] [blame]
Bram Moolenaar41e0f2f2016-03-08 14:44:42 +01001" 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
Bram Moolenaar53f0c962017-10-22 14:23:59 +020014
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
Bram Moolenaarfb222df2019-05-14 17:57:19 +020036
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 normal G
102 let last_line = line('$')
103
104 " Expected output
105 append
106asdfasdf. asdf
107asdfasdf. asdf
108asdfasdf. asdf
109asdfasdf. asdf
110asdfasdf. asdf
111asdfasdf. asdf
112asdfasdf. asdf
113asdfasdf asdf
114asdfasdf asdf
115asdfasdf asdf
116asdfasdf asdf
117asdfasdf asdf
118asdfasdf asdf
119asdfasdf asdf
120zx cvn. as dfg? hjkl iop! ert ernop
121zx 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
151asdfasdf. asdf
152asdfasdf. asdf
153asdfasdf. asdf
154asdfasdf. asdf
155asdfasdf. asdf
156asdfasdf. asdf
157asdfasdf. asdf
158asdfasdf asdf
159asdfasdf asdf
160asdfasdf asdf
161asdfasdf asdf
162asdfasdf asdf
163asdfasdf asdf
164asdfasdf asdf
165zx cvn. as dfg? hjkl iop! ert enop
166zx 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
188asdfasdf. asdf
189asdfasdf. asdf
190asdfasdf. asdf
191asdfasdf. asdf
192asdfasdf. asdf
193asdfasdf. asdf
194asdfasdf. asdf
195asdfasdf asdf
196asdfasdf asdf
197asdfasdf asdf
198asdfasdf asdf
199asdfasdf asdf
200asdfasdf asdf
201asdfasdf asdf
202zx 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!
211endfunc
212
213" Test for joining lines with comments
214func 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
241if (condition) // Remove the next comment leader!
242// OK, I will.
243action();
244
245if (condition) // Remove the next comment leader!
246// OK, I will.
247action();
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.
277if (condition) // Remove the next comment leader! OK, I will.
278action();
279if (condition) // Remove the next comment leader! OK, I will.
280action();
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!
291endfunc
292
293" Test for joining lines with different comment leaders
294func 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
338if (condition) // Remove the next comment leader!
339 // OK, I will.
340 action();
341
342if (condition) // Remove the next comment leader!
343 // OK, I will.
344 action();
345
346int i = 7 /* foo *// 3
347 // comment
348 ;
349
350int 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.
406if (condition) // Remove the next comment leader! OK, I will.
407 action();
408if (condition) // Remove the next comment leader! OK, I will.
409 action();
410int i = 7 /* foo *// 3 // comment
411 ;
412int 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
417Some 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!
423endfunc