aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/testdir/test_indent.vim
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-04-20 07:56:19 +0800
committerzeertzjq <zeertzjq@outlook.com>2022-04-21 07:24:47 +0800
commitc72857d396f03fb570a3df4fa1abd074974f0c76 (patch)
tree32d5e90025a97ce0b9bbab83ef1bb470aee8d115 /src/nvim/testdir/test_indent.vim
parentc6dcc6acd84adbaed8e6bcba0cb5e42bffdf1732 (diff)
downloadrneovim-c72857d396f03fb570a3df4fa1abd074974f0c76.tar.gz
rneovim-c72857d396f03fb570a3df4fa1abd074974f0c76.tar.bz2
rneovim-c72857d396f03fb570a3df4fa1abd074974f0c76.zip
vim-patch:8.2.0358: insufficient testing for indent.c
Problem: Insufficient testing for indent.c. Solution: Add indent tests. (Yegappan Lakshmanan, closes vim/vim#5736) https://github.com/vim/vim/commit/bd7206e02c957f0619e68e1628e2a3e91dd41e06 Cherry-pick Test_ex_mode() changes from Vim patches 8.2.{0342,0347}. Reorder test_expand_func.vim to match upstream.
Diffstat (limited to 'src/nvim/testdir/test_indent.vim')
-rw-r--r--src/nvim/testdir/test_indent.vim101
1 files changed, 101 insertions, 0 deletions
diff --git a/src/nvim/testdir/test_indent.vim b/src/nvim/testdir/test_indent.vim
new file mode 100644
index 0000000000..91e801a64a
--- /dev/null
+++ b/src/nvim/testdir/test_indent.vim
@@ -0,0 +1,101 @@
+" Test for various indent options
+
+func Test_preserveindent()
+ new
+ " Test for autoindent copying indent from the previous line
+ setlocal autoindent
+ call setline(1, [repeat(' ', 16) .. 'line1'])
+ call feedkeys("A\nline2", 'xt')
+ call assert_equal("\t\tline2", getline(2))
+ setlocal autoindent&
+
+ " Test for using CTRL-T with and without 'preserveindent'
+ set shiftwidth=4
+ call cursor(1, 1)
+ call setline(1, " \t ")
+ call feedkeys("Al\<C-T>", 'xt')
+ call assert_equal("\t\tl", getline(1))
+ set preserveindent
+ call setline(1, " \t ")
+ call feedkeys("Al\<C-T>", 'xt')
+ call assert_equal(" \t \tl", getline(1))
+ set pi& sw&
+
+ " Test for using CTRL-T with 'expandtab' and 'preserveindent'
+ call cursor(1, 1)
+ call setline(1, "\t \t")
+ set shiftwidth=4 expandtab preserveindent
+ call feedkeys("Al\<C-T>", 'xt')
+ call assert_equal("\t \t l", getline(1))
+ set sw& et& pi&
+
+ close!
+endfunc
+
+" Test for indent()
+func Test_indent_func()
+ call assert_equal(-1, indent(-1))
+ new
+ call setline(1, "\tabc")
+ call assert_equal(8, indent(1))
+ call setline(1, " abc")
+ call assert_equal(4, indent(1))
+ call setline(1, " \t abc")
+ call assert_equal(12, indent(1))
+ close!
+endfunc
+
+" Test for reindenting a line using the '=' operator
+func Test_reindent()
+ new
+ call setline(1, 'abc')
+ set nomodifiable
+ call assert_fails('normal ==', 'E21:')
+ set modifiable
+
+ call setline(1, ['foo', 'bar'])
+ call feedkeys('ggVG=', 'xt')
+ call assert_equal(['foo', 'bar'], getline(1, 2))
+ close!
+endfunc
+
+" Test for shifting a line with a preprocessor directive ('#')
+func Test_preproc_indent()
+ new
+ set sw=4
+ call setline(1, '#define FOO 1')
+ normal >>
+ call assert_equal(' #define FOO 1', getline(1))
+
+ " with 'smartindent'
+ call setline(1, '#define FOO 1')
+ set smartindent
+ normal >>
+ call assert_equal('#define FOO 1', getline(1))
+ set smartindent&
+
+ " with 'cindent'
+ set cindent
+ normal >>
+ call assert_equal('#define FOO 1', getline(1))
+ set cindent&
+
+ close!
+endfunc
+
+" Test for 'copyindent'
+func Test_copyindent()
+ new
+ set shiftwidth=4 autoindent expandtab copyindent
+ call setline(1, " \t abc")
+ call feedkeys("ol", 'xt')
+ call assert_equal(" \t l", getline(2))
+ set noexpandtab
+ call setline(1, " \t abc")
+ call feedkeys("ol", 'xt')
+ call assert_equal(" \t l", getline(2))
+ set sw& ai& et& ci&
+ close!
+endfunc
+
+" vim: shiftwidth=2 sts=2 expandtab