Mercurial > vim
annotate src/testdir/test_indent.vim @ 19603:6d3c683466f4 v8.2.0358
patch 8.2.0358: insufficient testing for indent.c
Commit: https://github.com/vim/vim/commit/bd7206e02c957f0619e68e1628e2a3e91dd41e06
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Mar 6 20:36:04 2020 +0100
patch 8.2.0358: insufficient testing for indent.c
Problem: Insufficient testing for indent.c.
Solution: Add indent tests. (Yegappan Lakshmanan, closes https://github.com/vim/vim/issues/5736)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 06 Mar 2020 20:45:04 +0100 |
parents | |
children | 9c15be376631 |
rev | line source |
---|---|
19603
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
1 " Test for various indent options |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
2 |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
3 func Test_preserveindent() |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
4 new |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
5 " Test for autoindent copying indent from the previous line |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
6 setlocal autoindent |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
7 call setline(1, [repeat(' ', 16) .. 'line1']) |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
8 call feedkeys("A\nline2", 'xt') |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
9 call assert_equal("\t\tline2", getline(2)) |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
10 setlocal autoindent& |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
11 |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
12 " Test for using CTRL-T with and without 'preserveindent' |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
13 set shiftwidth=4 |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
14 call cursor(1, 1) |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
15 call setline(1, " \t ") |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
16 call feedkeys("Al\<C-T>", 'xt') |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
17 call assert_equal("\t\tl", getline(1)) |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
18 set preserveindent |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
19 call setline(1, " \t ") |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
20 call feedkeys("Al\<C-T>", 'xt') |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
21 call assert_equal(" \t \tl", getline(1)) |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
22 set pi& sw& |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
23 |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
24 " Test for using CTRL-T with 'expandtab' and 'preserveindent' |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
25 call cursor(1, 1) |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
26 call setline(1, "\t \t") |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
27 set shiftwidth=4 expandtab preserveindent |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
28 call feedkeys("Al\<C-T>", 'xt') |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
29 call assert_equal("\t \t l", getline(1)) |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
30 set sw& et& pi& |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
31 |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
32 close! |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
33 endfunc |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
34 |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
35 " Test for indent() |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
36 func Test_indent_func() |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
37 call assert_equal(-1, indent(-1)) |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
38 new |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
39 call setline(1, "\tabc") |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
40 call assert_equal(8, indent(1)) |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
41 call setline(1, " abc") |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
42 call assert_equal(4, indent(1)) |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
43 call setline(1, " \t abc") |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
44 call assert_equal(12, indent(1)) |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
45 close! |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
46 endfunc |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
47 |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
48 " Test for reindenting a line using the '=' operator |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
49 func Test_reindent() |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
50 new |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
51 call setline(1, 'abc') |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
52 set nomodifiable |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
53 call assert_fails('normal ==', 'E21:') |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
54 set modifiable |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
55 |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
56 call setline(1, ['foo', 'bar']) |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
57 call feedkeys('ggVG=', 'xt') |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
58 call assert_equal(['foo', 'bar'], getline(1, 2)) |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
59 close! |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
60 endfunc |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
61 |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
62 " Test for shifting a line with a preprocessor directive ('#') |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
63 func Test_preproc_indent() |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
64 new |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
65 set sw=4 |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
66 call setline(1, '#define FOO 1') |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
67 normal >> |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
68 call assert_equal(' #define FOO 1', getline(1)) |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
69 |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
70 " with 'smartindent' |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
71 call setline(1, '#define FOO 1') |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
72 set smartindent |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
73 normal >> |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
74 call assert_equal('#define FOO 1', getline(1)) |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
75 set smartindent& |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
76 |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
77 " with 'cindent' |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
78 set cindent |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
79 normal >> |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
80 call assert_equal('#define FOO 1', getline(1)) |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
81 set cindent& |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
82 |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
83 close! |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
84 endfunc |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
85 |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
86 " Test for 'copyindent' |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
87 func Test_copyindent() |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
88 new |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
89 set shiftwidth=4 autoindent expandtab copyindent |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
90 call setline(1, " \t abc") |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
91 call feedkeys("ol", 'xt') |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
92 call assert_equal(" \t l", getline(2)) |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
93 set noexpandtab |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
94 call setline(1, " \t abc") |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
95 call feedkeys("ol", 'xt') |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
96 call assert_equal(" \t l", getline(2)) |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
97 set sw& ai& et& ci& |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
98 close! |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
99 endfunc |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
100 |
6d3c683466f4
patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents:
diff
changeset
|
101 " vim: shiftwidth=2 sts=2 expandtab |