diff src/testdir/test_smartindent.vim @ 19852:12518b40c161 v8.2.0482

patch 8.2.0482: channel and sandbox code not sufficiently tested Commit: https://github.com/vim/vim/commit/ca68ae13114619df3e4c195b41ad0575516f5ff6 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Mar 30 19:32:53 2020 +0200 patch 8.2.0482: channel and sandbox code not sufficiently tested Problem: Channel and sandbox code not sufficiently tested. Solution: Add more tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/5855)
author Bram Moolenaar <Bram@vim.org>
date Mon, 30 Mar 2020 19:45:05 +0200
parents 6d3c683466f4
children dc3d45d9a4a8
line wrap: on
line diff
--- a/src/testdir/test_smartindent.vim
+++ b/src/testdir/test_smartindent.vim
@@ -21,9 +21,7 @@ endfunc
 func Test_smartindent_has_no_effect()
   new
   exe "normal! i\<Tab>one\<Esc>"
-  set noautoindent
-  set smartindent
-  set indentexpr=
+  setlocal noautoindent smartindent indentexpr=
   exe "normal! Gotwo\<Esc>"
   call assert_equal("\ttwo", getline("$"))
 
@@ -32,16 +30,13 @@ func Test_smartindent_has_no_effect()
   call assert_equal("three", getline("$"))
 
   delfunction! MyIndent
-  set autoindent&
-  set smartindent&
-  set indentexpr&
   bwipe!
 endfunc
 
 " Test for inserting '{' and '} with smartindent
 func Test_smartindent_braces()
   new
-  set smartindent shiftwidth=4
+  setlocal smartindent shiftwidth=4
   call setline(1, ['    if (a)', "\tif (b)", "\t    return 1"])
   normal 2ggO{
   normal 3ggA {
@@ -57,7 +52,62 @@ func Test_smartindent_braces()
         \ "\t}",
         \ '    }'
         \ ], getline(1, '$'))
-  set si& sw& ai&
+  close!
+endfunc
+
+" Test for adding a new line before and after comments with smartindent
+func Test_si_add_line_around_comment()
+  new
+  setlocal smartindent shiftwidth=4
+  call setline(1, ['    A', '# comment1', '# comment2'])
+  exe "normal GoC\<Esc>2GOB"
+  call assert_equal(['    A', '    B', '# comment1', '# comment2', '    C'],
+        \ getline(1, '$'))
+  close!
+endfunc
+
+" After a C style comment, indent for a following line should line up with the
+" line containing the start of the comment.
+func Test_si_indent_after_c_comment()
+  new
+  setlocal smartindent shiftwidth=4 fo+=ro
+  exe "normal i\<C-t>/*\ncomment\n/\n#define FOOBAR\n75\<Esc>ggOabc"
+  normal 3jOcont
+  call assert_equal(['    abc', '    /*', '     * comment', '     * cont',
+        \ '     */', '#define FOOBAR', '    75'], getline(1, '$'))
+  close!
+endfunc
+
+" Test for indenting a statement after a if condition split across lines
+func Test_si_if_cond_split_across_lines()
+  new
+  setlocal smartindent shiftwidth=4
+  exe "normal i\<C-t>if (cond1 &&\n\<C-t>cond2) {\ni = 10;\n}"
+  call assert_equal(['    if (cond1 &&', "\t    cond2) {", "\ti = 10;",
+        \ '    }'], getline(1, '$'))
+  close!
+endfunc
+
+" Test for inserting lines before and after a one line comment
+func Test_si_one_line_comment()
+  new
+  setlocal smartindent shiftwidth=4
+  exe "normal i\<C-t>abc;\n\<C-t>/* comment */"
+  normal oi = 10;
+  normal kOj = 1;
+  call assert_equal(['    abc;', "\tj = 1;", "\t/* comment */", "\ti = 10;"],
+        \ getline(1, '$'))
+  close!
+endfunc
+
+" Test for smartindent with a comment continued across multiple lines
+func Test_si_comment_line_continuation()
+  new
+  setlocal smartindent shiftwidth=4
+  call setline(1, ['# com1', '# com2 \', '    contd', '# com3', '  xyz'])
+  normal ggOabc
+  call assert_equal(['  abc', '# com1', '# com2 \', '    contd', '# com3',
+        \ '  xyz'], getline(1, '$'))
   close!
 endfunc