diff src/testdir/test_join.vim @ 16658:f776ce5d4ed8 v8.1.1331

patch 8.1.1331: test 29 is old style commit https://github.com/vim/vim/commit/fb222df28d5158516104a21cba7141a6240f4817 Author: Bram Moolenaar <Bram@vim.org> Date: Tue May 14 17:57:19 2019 +0200 patch 8.1.1331: test 29 is old style Problem: Test 29 is old style. Solution: Turn it into a new style test. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/4370)
author Bram Moolenaar <Bram@vim.org>
date Tue, 14 May 2019 18:00:07 +0200
parents 15f0f9f16cd9
children 9c90cf08cfa8
line wrap: on
line diff
--- a/src/testdir/test_join.vim
+++ b/src/testdir/test_join.vim
@@ -33,3 +33,391 @@ func Test_join_marks()
   call assert_equal([0, 4, 67, 0], getpos("']"))
   enew!
 endfunc
+
+" Test for joining lines and marks in them
+"   in compatible and nocompatible modes
+"   and with 'joinspaces' set or not
+"   and with 'cpoptions' flag 'j' set or not
+func Test_join_spaces_marks()
+  new
+  " Text used for the test
+  insert
+asdfasdf.
+asdf
+asdfasdf. 
+asdf
+asdfasdf.  
+asdf
+asdfasdf.	
+asdf
+asdfasdf. 	
+asdf
+asdfasdf.	 
+asdf
+asdfasdf.		
+asdf
+asdfasdf
+asdf
+asdfasdf 
+asdf
+asdfasdf  
+asdf
+asdfasdf	
+asdf
+asdfasdf	 
+asdf
+asdfasdf 	
+asdf
+asdfasdf		
+asdf
+zx cvn.
+as dfg?
+hjkl iop!
+ert
+zx cvn.
+as dfg?
+hjkl iop!
+ert
+.
+  let text = getline(1, '$')
+  normal gg
+
+  set nojoinspaces
+  set cpoptions-=j
+  normal JjJjJjJjJjJjJjJjJjJjJjJjJjJ
+  normal j05lmx
+  normal 2j06lmy
+  normal 2k4Jy3l$p
+  normal `xyl$p
+  normal `yy2l$p
+
+  set cpoptions+=j
+  normal j05lmx
+  normal 2j06lmy
+  normal 2k4Jy3l$p
+  normal `xyl$p
+  normal `yy2l$p
+
+  normal G
+  let last_line = line('$')
+
+  " Expected output
+  append
+asdfasdf. asdf
+asdfasdf. asdf
+asdfasdf.  asdf
+asdfasdf.	asdf
+asdfasdf. 	asdf
+asdfasdf.	 asdf
+asdfasdf.		asdf
+asdfasdf asdf
+asdfasdf asdf
+asdfasdf  asdf
+asdfasdf	asdf
+asdfasdf	 asdf
+asdfasdf 	asdf
+asdfasdf		asdf
+zx cvn. as dfg? hjkl iop! ert ernop
+zx cvn. as dfg? hjkl iop! ert ernop
+.
+
+  call assert_equal(getline(last_line + 1, '$'), getline(1, last_line))
+
+  enew!
+  call append(0, text)
+  normal gg
+
+  set cpoptions-=j
+  set joinspaces
+  normal JjJjJjJjJjJjJjJjJjJjJjJjJjJ
+  normal j05lmx
+  normal 2j06lmy
+  normal 2k4Jy3l$p
+  normal `xyl$p
+  normal `yy2l$p
+
+  set cpoptions+=j
+  normal j05lmx
+  normal 2j06lmy
+  normal 2k4Jy3l$p
+  normal `xyl$p
+  normal `yy2l$p
+
+  normal G
+  let last_line = line('$')
+
+  " Expected output
+  append
+asdfasdf.  asdf
+asdfasdf.  asdf
+asdfasdf.  asdf
+asdfasdf.	asdf
+asdfasdf. 	asdf
+asdfasdf.	 asdf
+asdfasdf.		asdf
+asdfasdf asdf
+asdfasdf asdf
+asdfasdf  asdf
+asdfasdf	asdf
+asdfasdf	 asdf
+asdfasdf 	asdf
+asdfasdf		asdf
+zx cvn.  as dfg?  hjkl iop!  ert  enop
+zx cvn.  as dfg? hjkl iop! ert ernop
+
+.
+
+  call assert_equal(getline(last_line + 1, '$'), getline(1, last_line))
+
+  enew!
+  call append(0, text)
+  normal gg
+
+  set cpoptions-=j
+  set nojoinspaces
+  set compatible
+
+  normal JjJjJjJjJjJjJjJjJjJjJjJjJjJ
+  normal j4Jy3l$pjdG
+
+  normal G
+  let last_line = line('$')
+
+  " Expected output
+  append
+asdfasdf.  asdf
+asdfasdf.  asdf
+asdfasdf.  asdf
+asdfasdf.	asdf
+asdfasdf. 	asdf
+asdfasdf.	 asdf
+asdfasdf.		asdf
+asdfasdf asdf
+asdfasdf asdf
+asdfasdf  asdf
+asdfasdf	asdf
+asdfasdf	 asdf
+asdfasdf 	asdf
+asdfasdf		asdf
+zx cvn.  as dfg? hjkl iop! ert  a
+.
+
+  call assert_equal(getline(last_line + 1, '$'), getline(1, last_line))
+
+  set nocompatible
+  set cpoptions&vim
+  set joinspaces&vim
+  close!
+endfunc
+
+" Test for joining lines with comments
+func Test_join_lines_with_comments()
+  new
+
+  " Text used by the test
+  insert
+{
+
+/*
+* Make sure the previous comment leader is not removed.
+*/
+
+/*
+* Make sure the previous comment leader is not removed.
+*/
+
+// Should the next comment leader be left alone?
+// Yes.
+
+// Should the next comment leader be left alone?
+// Yes.
+
+/* Here the comment leader should be left intact. */
+// And so should this one.
+
+/* Here the comment leader should be left intact. */
+// And so should this one.
+
+if (condition) // Remove the next comment leader!
+// OK, I will.
+action();
+
+if (condition) // Remove the next comment leader!
+// OK, I will.
+action();
+}
+.
+
+  call cursor(2, 1)
+  set comments=s1:/*,mb:*,ex:*/,://
+  set nojoinspaces fo=j
+  set backspace=eol,start
+
+  .,+3join
+  exe "normal j4J\<CR>"
+  .,+2join
+  exe "normal j3J\<CR>"
+  .,+2join
+  exe "normal j3J\<CR>"
+  .,+2join
+  exe "normal jj3J\<CR>"
+
+  normal G
+  let last_line = line('$')
+
+  " Expected output
+  append
+{
+/* Make sure the previous comment leader is not removed. */
+/* Make sure the previous comment leader is not removed. */
+// Should the next comment leader be left alone? Yes.
+// Should the next comment leader be left alone? Yes.
+/* Here the comment leader should be left intact. */ // And so should this one.
+/* Here the comment leader should be left intact. */ // And so should this one.
+if (condition) // Remove the next comment leader! OK, I will.
+action();
+if (condition) // Remove the next comment leader! OK, I will.
+action();
+}
+.
+
+  call assert_equal(getline(last_line + 1, '$'), getline(1, last_line))
+
+  set comments&vim
+  set joinspaces&vim
+  set fo&vim
+  set backspace&vim
+  close!
+endfunc
+
+" Test for joining lines with different comment leaders
+func Test_join_comments_2()
+  new
+
+  insert
+{
+
+/*
+ * Make sure the previous comment leader is not removed.
+ */
+
+/*
+ * Make sure the previous comment leader is not removed.
+ */
+
+/* List:
+ * - item1
+ *   foo bar baz
+ *   foo bar baz
+ * - item2
+ *   foo bar baz
+ *   foo bar baz
+ */
+
+/* List:
+ * - item1
+ *   foo bar baz
+ *   foo bar baz
+ * - item2
+ *   foo bar baz
+ *   foo bar baz
+ */
+
+// Should the next comment leader be left alone?
+// Yes.
+
+// Should the next comment leader be left alone?
+// Yes.
+
+/* Here the comment leader should be left intact. */
+// And so should this one.
+
+/* Here the comment leader should be left intact. */
+// And so should this one.
+
+if (condition) // Remove the next comment leader!
+               // OK, I will.
+    action();
+
+if (condition) // Remove the next comment leader!
+               // OK, I will.
+    action();
+
+int i = 7 /* foo *// 3
+ // comment
+ ;
+
+int i = 7 /* foo *// 3
+ // comment
+ ;
+
+># 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.
+
+># 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.
+
+}
+.
+
+  call cursor(2, 1)
+  set comments=sO:*\ -,mO:*\ \ ,exO:*/
+  set comments+=s1:/*,mb:*,ex:*/,://
+  set comments+=s1:>#,mb:#,ex:#<,:<
+  set cpoptions-=j joinspaces fo=j
+  set backspace=eol,start
+
+  .,+3join
+  exe "normal j4J\<CR>"
+  .,+8join
+  exe "normal j9J\<CR>"
+  .,+2join
+  exe "normal j3J\<CR>"
+  .,+2join
+  exe "normal j3J\<CR>"
+  .,+2join
+  exe "normal jj3J\<CR>j"
+  .,+2join
+  exe "normal jj3J\<CR>j"
+  .,+5join
+  exe "normal j6J\<CR>"
+  exe "normal oSome code!\<CR>// Make sure backspacing does not remove this comment leader.\<Esc>0i\<C-H>\<Esc>"
+
+  normal G
+  let last_line = line('$')
+
+  " Expected output
+  append
+{
+/* Make sure the previous comment leader is not removed.  */
+/* Make sure the previous comment leader is not removed.  */
+/* List: item1 foo bar baz foo bar baz item2 foo bar baz foo bar baz */
+/* List: item1 foo bar baz foo bar baz item2 foo bar baz foo bar baz */
+// Should the next comment leader be left alone?  Yes.
+// Should the next comment leader be left alone?  Yes.
+/* Here the comment leader should be left intact. */ // And so should this one.
+/* Here the comment leader should be left intact. */ // And so should this one.
+if (condition) // Remove the next comment leader!  OK, I will.
+    action();
+if (condition) // Remove the next comment leader!  OK, I will.
+    action();
+int i = 7 /* foo *// 3 // comment
+ ;
+int i = 7 /* foo *// 3 // comment
+ ;
+># 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.
+># 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.
+
+Some code!// Make sure backspacing does not remove this comment leader.
+}
+.
+
+  call assert_equal(getline(last_line + 1, '$'), getline(1, last_line))
+  close!
+endfunc