Patch 8.2.0686
Problem:    Formatoptions not sufficiently tested.
Solution:   Add a few more tests. (Yegappan Lakshmanan, closes #6031)
Files:      src/testdir/test_normal.vim, src/testdir/test_textformat.vim


*** ../vim-8.2.0685/src/testdir/test_normal.vim 2020-04-28 20:29:04.237851565 
+0200
--- src/testdir/test_normal.vim 2020-05-03 16:03:10.549955246 +0200
***************
*** 204,209 ****
--- 204,224 ----
    set formatexpr=
  endfunc
  
+ " When 'formatexpr' returns non-zero, internal formatting is used.
+ func Test_normal_formatexpr_returns_nonzero()
+   new
+   call setline(1, ['one', 'two'])
+   func! Format()
+     return 1
+   endfunc
+   setlocal formatexpr=Format()
+   normal VGgq
+   call assert_equal(['one two'], getline(1, '$'))
+   setlocal formatexpr=
+   delfunc Format
+   close!
+ endfunc
+ 
  " basic test for formatprg
  func Test_normal06_formatprg()
    " only test on non windows platform
*** ../vim-8.2.0685/src/testdir/test_textformat.vim     2020-04-28 
20:29:04.237851565 +0200
--- src/testdir/test_textformat.vim     2020-05-03 16:03:10.549955246 +0200
***************
*** 1091,1096 ****
--- 1091,1107 ----
    setlocal fo+=aw tw=10
    call feedkeys("iabc abc a abc\<Esc>k0weade", 'xt')
    call assert_equal(['abc abcde ', 'a abc'], getline(1, '$'))
+ 
+   " Test for 'a', 'w' and '1' options.
+   setlocal textwidth=0
+   setlocal fo=1aw
+   %d
+   call setline(1, '. foo')
+   normal 72ig
+   call feedkeys('a uu uu uu', 'xt')
+   call assert_equal('g uu uu ', getline(1)[-8:])
+   call assert_equal(['uu. foo'], getline(2, '$'))
+ 
    %bw!
  endfunc
  
***************
*** 1113,1116 ****
--- 1124,1308 ----
    %bw!
  endfunc
  
+ " Test for formatting lines using gq in visual mode
+ func Test_visual_gq_format()
+   new
+   call setline(1, ['one two three four', 'five six', 'one two'])
+   setl textwidth=10
+   call feedkeys('ggv$jj', 'xt')
+   redraw!
+   normal gq
+   %d
+   call setline(1, ['one two three four', 'five six', 'one two'])
+   normal G$
+   call feedkeys('v0kk', 'xt')
+   redraw!
+   normal gq
+   setl textwidth&
+   close!
+ endfunc
+ 
+ " Test for 'n' flag in 'formatoptions' to format numbered lists
+ func Test_fo_n()
+   new
+   setlocal autoindent
+   setlocal textwidth=12
+   setlocal fo=n
+   call setline(1, ['  1) one two three four', '  2) two'])
+   normal gggqG
+   call assert_equal(['  1) one two', '     three', '     four', '  2) two'],
+         \ getline(1, '$'))
+   close!
+ endfunc
+ 
+ " Test for 'formatlistpat' option
+ func Test_formatlistpat()
+   new
+   setlocal autoindent
+   setlocal textwidth=10
+   setlocal fo=n
+   setlocal formatlistpat=^\\s*-\\s*
+   call setline(1, ['  - one two three', '  - two'])
+   normal gggqG
+   call assert_equal(['  - one', '    two', '    three', '  - two'],
+         \ getline(1, '$'))
+   close!
+ endfunc
+ 
+ " Test for the 'b' and 'v' flags in 'formatoptions'
+ " Text should wrap only if a space character is inserted at or before
+ " 'textwidth'
+ func Test_fo_b()
+   new
+   setlocal textwidth=20
+ 
+   setlocal formatoptions=t
+   call setline(1, 'one two three four')
+   call feedkeys('Amore', 'xt')
+   call assert_equal(['one two three', 'fourmore'], getline(1, '$'))
+ 
+   setlocal formatoptions=bt
+   %d
+   call setline(1, 'one two three four')
+   call feedkeys('Amore five', 'xt')
+   call assert_equal(['one two three fourmore five'], getline(1, '$'))
+ 
+   setlocal formatoptions=bt
+   %d
+   call setline(1, 'one two three four')
+   call feedkeys('A five', 'xt')
+   call assert_equal(['one two three four', 'five'], getline(1, '$'))
+ 
+   setlocal formatoptions=vt
+   %d
+   call setline(1, 'one two three four')
+   call feedkeys('Amore five', 'xt')
+   call assert_equal(['one two three fourmore', 'five'], getline(1, '$'))
+ 
+   close!
+ endfunc
+ 
+ " Test for the '1' flag in 'formatoptions'. Don't wrap text after a one letter
+ " word.
+ func Test_fo_1()
+   new
+   setlocal textwidth=20
+ 
+   setlocal formatoptions=t
+   call setline(1, 'one two three four')
+   call feedkeys('A a bird', 'xt')
+   call assert_equal(['one two three four a', 'bird'], getline(1, '$'))
+ 
+   %d
+   setlocal formatoptions=t1
+   call setline(1, 'one two three four')
+   call feedkeys('A a bird', 'xt')
+   call assert_equal(['one two three four', 'a bird'], getline(1, '$'))
+ 
+   close!
+ endfunc
+ 
+ " Test for 'l' flag in 'formatoptions'. When starting insert mode, if a line
+ " is longer than 'textwidth', then it is not broken.
+ func Test_fo_l()
+   new
+   setlocal textwidth=20
+ 
+   setlocal formatoptions=t
+   call setline(1, 'one two three four five')
+   call feedkeys('A six', 'xt')
+   call assert_equal(['one two three four', 'five six'], getline(1, '$'))
+ 
+   %d
+   setlocal formatoptions=tl
+   call setline(1, 'one two three four five')
+   call feedkeys('A six', 'xt')
+   call assert_equal(['one two three four five six'], getline(1, '$'))
+ 
+   close!
+ endfunc
+ 
+ " Test for the '2' flag in 'formatoptions'
+ func Test_fo_2()
+   new
+   setlocal autoindent
+   setlocal formatoptions=t2
+   setlocal textwidth=30
+   call setline(1, ["\tfirst line of a paragraph.",
+         \ "second line of the same paragraph.",
+         \ "third line."])
+   normal gggqG
+   call assert_equal(["\tfirst line of a",
+         \ "paragraph.  second line of the",
+         \ "same paragraph.  third line."], getline(1, '$'))
+   close!
+ endfunc
+ 
+ " Test for formatting lines where only the first line has a comment.
+ func Test_fo_gq_with_firstline_comment()
+   new
+   setlocal formatoptions=tcq
+   call setline(1, ['- one two', 'three'])
+   normal gggqG
+   call assert_equal(['- one two three'], getline(1, '$'))
+ 
+   %d
+   call setline(1, ['- one', '- two'])
+   normal gggqG
+   call assert_equal(['- one', '- two'], getline(1, '$'))
+   close!
+ endfunc
+ 
+ " Test for trying to join a comment line with a non-comment line
+ func Test_join_comments()
+   new
+   call setline(1, ['one', '/* two */', 'three'])
+   normal gggqG
+   call assert_equal(['one', '/* two */', 'three'], getline(1, '$'))
+   close!
+ endfunc
+ 
+ " Test for using 'a' in 'formatoptions' with comments
+ func Test_autoformat_comments()
+   new
+   setlocal formatoptions+=a
+   call feedkeys("a- one\n- two\n", 'xt')
+   call assert_equal(['- one', '- two', ''], getline(1, '$'))
+ 
+   %d
+   call feedkeys("a\none\n", 'xt')
+   call assert_equal(['', 'one', ''], getline(1, '$'))
+ 
+   setlocal formatoptions+=aw
+   %d
+   call feedkeys("aone \ntwo\n", 'xt')
+   call assert_equal(['one two', ''], getline(1, '$'))
+ 
+   %d
+   call feedkeys("aone\ntwo\n", 'xt')
+   call assert_equal(['one', 'two', ''], getline(1, '$'))
+ 
+   close!
+ endfunc
+ 
  " vim: shiftwidth=2 sts=2 expandtab
*** ../vim-8.2.0685/src/version.c       2020-05-03 15:47:29.993697177 +0200
--- src/version.c       2020-05-03 16:04:06.457704556 +0200
***************
*** 748,749 ****
--- 748,751 ----
  {   /* Add new patch number below this line */
+ /**/
+     686,
  /**/

-- 
Never overestimate a man's ability to underestimate a woman.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202005031405.043E5C2w017993%40masaka.moolenaar.net.

Raspunde prin e-mail lui