annotate src/testdir/test_smartindent.vim @ 33399:95db67c7b754 v9.0.1958

patch 9.0.1958: cannot complete option values Commit: https://github.com/vim/vim/commit/900894b09a95398dfc75599e9f0aa2ea25723384 Author: Yee Cheng Chin <ychin.git@gmail.com> Date: Fri Sep 29 20:42:32 2023 +0200 patch 9.0.1958: cannot complete option values Problem: cannot complete option values Solution: Add completion functions for several options Add cmdline tab-completion for setting string options Add tab-completion for setting string options on the cmdline using `:set=` (along with `:set+=` and `:set-=`). The existing tab completion for setting options currently only works when nothing is typed yet, and it only fills in with the existing value, e.g. when the user does `:set diffopt=<Tab>` it will be completed to `set diffopt=internal,filler,closeoff` and nothing else. This isn't too useful as a user usually wants auto-complete to suggest all the possible values, such as 'iblank', or 'algorithm:patience'. For set= and set+=, this adds a new optional callback function for each option that can be invoked when doing completion. This allows for each option to have control over how completion works. For example, in 'diffopt', it will suggest the default enumeration, but if `algorithm:` is selected, it will further suggest different algorithm types like 'meyers' and 'patience'. When using set=, the existing option value will be filled in as the first choice to preserve the existing behavior. When using set+= this won't happen as it doesn't make sense. For flag list options (e.g. 'mouse' and 'guioptions'), completion will take into account existing typed values (and in the case of set+=, the existing option value) to make sure it doesn't suggest duplicates. For set-=, there is a new `ExpandSettingSubtract` function which will handle flag list and comma-separated options smartly, by only suggesting values that currently exist in the option. Note that Vim has some existing code that adds special handling for 'filetype', 'syntax', and misc dir options like 'backupdir'. This change preserves them as they already work, instead of converting to the new callback API for each option. closes: #13182 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Yee Cheng Chin <ychin.git@gmail.com>
author Christian Brabandt <cb@256bit.org>
date Fri, 29 Sep 2023 20:45:04 +0200
parents 3942ea75b4c0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11943
268b1036cd17 patch 8.0.0851: 'smartindent' is used even when 'indentexpr' is set
Christian Brabandt <cb@256bit.org>
parents: 10145
diff changeset
1 " Tests for smartindent
10145
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 " Tests for not doing smart indenting when it isn't set.
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 11943
diff changeset
4 func Test_nosmartindent()
10145
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 new
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 call append(0, [" some test text",
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 11943
diff changeset
7 \ " test text",
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 11943
diff changeset
8 \ "test text",
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 11943
diff changeset
9 \ " test text"])
10145
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 set nocindent nosmartindent autoindent
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 exe "normal! gg/some\<CR>"
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 exe "normal! 2cc#test\<Esc>"
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 call assert_equal(" #test", getline(1))
eb9a7296ae9f commit https://github.com/vim/vim/commit/53f1673cd909eb1c809c6a9086e3d104a0df9bed
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 enew! | close
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 11943
diff changeset
15 endfunc
11943
268b1036cd17 patch 8.0.0851: 'smartindent' is used even when 'indentexpr' is set
Christian Brabandt <cb@256bit.org>
parents: 10145
diff changeset
16
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 11943
diff changeset
17 func MyIndent()
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 11943
diff changeset
18 endfunc
11943
268b1036cd17 patch 8.0.0851: 'smartindent' is used even when 'indentexpr' is set
Christian Brabandt <cb@256bit.org>
parents: 10145
diff changeset
19
268b1036cd17 patch 8.0.0851: 'smartindent' is used even when 'indentexpr' is set
Christian Brabandt <cb@256bit.org>
parents: 10145
diff changeset
20 " When 'indentexpr' is set, setting 'si' has no effect.
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 11943
diff changeset
21 func Test_smartindent_has_no_effect()
11943
268b1036cd17 patch 8.0.0851: 'smartindent' is used even when 'indentexpr' is set
Christian Brabandt <cb@256bit.org>
parents: 10145
diff changeset
22 new
268b1036cd17 patch 8.0.0851: 'smartindent' is used even when 'indentexpr' is set
Christian Brabandt <cb@256bit.org>
parents: 10145
diff changeset
23 exe "normal! i\<Tab>one\<Esc>"
19852
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
24 setlocal noautoindent smartindent indentexpr=
11943
268b1036cd17 patch 8.0.0851: 'smartindent' is used even when 'indentexpr' is set
Christian Brabandt <cb@256bit.org>
parents: 10145
diff changeset
25 exe "normal! Gotwo\<Esc>"
268b1036cd17 patch 8.0.0851: 'smartindent' is used even when 'indentexpr' is set
Christian Brabandt <cb@256bit.org>
parents: 10145
diff changeset
26 call assert_equal("\ttwo", getline("$"))
268b1036cd17 patch 8.0.0851: 'smartindent' is used even when 'indentexpr' is set
Christian Brabandt <cb@256bit.org>
parents: 10145
diff changeset
27
268b1036cd17 patch 8.0.0851: 'smartindent' is used even when 'indentexpr' is set
Christian Brabandt <cb@256bit.org>
parents: 10145
diff changeset
28 set indentexpr=MyIndent
268b1036cd17 patch 8.0.0851: 'smartindent' is used even when 'indentexpr' is set
Christian Brabandt <cb@256bit.org>
parents: 10145
diff changeset
29 exe "normal! Gothree\<Esc>"
268b1036cd17 patch 8.0.0851: 'smartindent' is used even when 'indentexpr' is set
Christian Brabandt <cb@256bit.org>
parents: 10145
diff changeset
30 call assert_equal("three", getline("$"))
268b1036cd17 patch 8.0.0851: 'smartindent' is used even when 'indentexpr' is set
Christian Brabandt <cb@256bit.org>
parents: 10145
diff changeset
31
268b1036cd17 patch 8.0.0851: 'smartindent' is used even when 'indentexpr' is set
Christian Brabandt <cb@256bit.org>
parents: 10145
diff changeset
32 delfunction! MyIndent
268b1036cd17 patch 8.0.0851: 'smartindent' is used even when 'indentexpr' is set
Christian Brabandt <cb@256bit.org>
parents: 10145
diff changeset
33 bwipe!
15406
63b02fcf1361 patch 8.1.0711: test files still use function!
Bram Moolenaar <Bram@vim.org>
parents: 11943
diff changeset
34 endfunc
11943
268b1036cd17 patch 8.0.0851: 'smartindent' is used even when 'indentexpr' is set
Christian Brabandt <cb@256bit.org>
parents: 10145
diff changeset
35
19603
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
36 " Test for inserting '{' and '} with smartindent
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
37 func Test_smartindent_braces()
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
38 new
19852
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
39 setlocal smartindent shiftwidth=4
19603
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
40 call setline(1, [' if (a)', "\tif (b)", "\t return 1"])
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
41 normal 2ggO{
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
42 normal 3ggA {
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
43 normal 4ggo}
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
44 normal o}
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
45 normal 4ggO#define FOO 1
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
46 call assert_equal([
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
47 \ ' if (a)',
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
48 \ ' {',
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
49 \ "\tif (b) {",
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
50 \ '#define FOO 1',
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
51 \ "\t return 1",
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
52 \ "\t}",
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
53 \ ' }'
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
54 \ ], getline(1, '$'))
19852
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
55 close!
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
56 endfunc
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
57
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
58 " Test for adding a new line before and after comments with smartindent
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
59 func Test_si_add_line_around_comment()
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
60 new
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
61 setlocal smartindent shiftwidth=4
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
62 call setline(1, [' A', '# comment1', '# comment2'])
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
63 exe "normal GoC\<Esc>2GOB"
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
64 call assert_equal([' A', ' B', '# comment1', '# comment2', ' C'],
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
65 \ getline(1, '$'))
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
66 close!
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
67 endfunc
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
68
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
69 " After a C style comment, indent for a following line should line up with the
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
70 " line containing the start of the comment.
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
71 func Test_si_indent_after_c_comment()
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
72 new
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
73 setlocal smartindent shiftwidth=4 fo+=ro
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
74 exe "normal i\<C-t>/*\ncomment\n/\n#define FOOBAR\n75\<Esc>ggOabc"
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
75 normal 3jOcont
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
76 call assert_equal([' abc', ' /*', ' * comment', ' * cont',
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
77 \ ' */', '#define FOOBAR', ' 75'], getline(1, '$'))
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
78 close!
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
79 endfunc
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
80
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
81 " Test for indenting a statement after a if condition split across lines
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
82 func Test_si_if_cond_split_across_lines()
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
83 new
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
84 setlocal smartindent shiftwidth=4
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
85 exe "normal i\<C-t>if (cond1 &&\n\<C-t>cond2) {\ni = 10;\n}"
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
86 call assert_equal([' if (cond1 &&', "\t cond2) {", "\ti = 10;",
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
87 \ ' }'], getline(1, '$'))
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
88 close!
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
89 endfunc
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
90
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
91 " Test for inserting lines before and after a one line comment
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
92 func Test_si_one_line_comment()
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
93 new
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
94 setlocal smartindent shiftwidth=4
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
95 exe "normal i\<C-t>abc;\n\<C-t>/* comment */"
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
96 normal oi = 10;
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
97 normal kOj = 1;
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
98 call assert_equal([' abc;', "\tj = 1;", "\t/* comment */", "\ti = 10;"],
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
99 \ getline(1, '$'))
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
100 close!
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
101 endfunc
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
102
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
103 " Test for smartindent with a comment continued across multiple lines
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
104 func Test_si_comment_line_continuation()
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
105 new
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
106 setlocal smartindent shiftwidth=4
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
107 call setline(1, ['# com1', '# com2 \', ' contd', '# com3', ' xyz'])
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
108 normal ggOabc
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
109 call assert_equal([' abc', '# com1', '# com2 \', ' contd', '# com3',
12518b40c161 patch 8.2.0482: channel and sandbox code not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19603
diff changeset
110 \ ' xyz'], getline(1, '$'))
19603
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
111 close!
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
112 endfunc
6d3c683466f4 patch 8.2.0358: insufficient testing for indent.c
Bram Moolenaar <Bram@vim.org>
parents: 15406
diff changeset
113
24946
dc3d45d9a4a8 patch 8.2.3010: not enough testing for viminfo code
Bram Moolenaar <Bram@vim.org>
parents: 19852
diff changeset
114 " When 'paste' is set, 'smartindent' should not take effect.
dc3d45d9a4a8 patch 8.2.3010: not enough testing for viminfo code
Bram Moolenaar <Bram@vim.org>
parents: 19852
diff changeset
115 func Test_si_with_paste()
dc3d45d9a4a8 patch 8.2.3010: not enough testing for viminfo code
Bram Moolenaar <Bram@vim.org>
parents: 19852
diff changeset
116 new
dc3d45d9a4a8 patch 8.2.3010: not enough testing for viminfo code
Bram Moolenaar <Bram@vim.org>
parents: 19852
diff changeset
117 setlocal smartindent autoindent
dc3d45d9a4a8 patch 8.2.3010: not enough testing for viminfo code
Bram Moolenaar <Bram@vim.org>
parents: 19852
diff changeset
118 set paste
dc3d45d9a4a8 patch 8.2.3010: not enough testing for viminfo code
Bram Moolenaar <Bram@vim.org>
parents: 19852
diff changeset
119 " insert text that will trigger smartindent
dc3d45d9a4a8 patch 8.2.3010: not enough testing for viminfo code
Bram Moolenaar <Bram@vim.org>
parents: 19852
diff changeset
120 exe "norm! i {\nif (x)\ni = 1;\n#define FOO 1\nj = 2;\n}"
dc3d45d9a4a8 patch 8.2.3010: not enough testing for viminfo code
Bram Moolenaar <Bram@vim.org>
parents: 19852
diff changeset
121 exe "norm! Ok = 3;"
dc3d45d9a4a8 patch 8.2.3010: not enough testing for viminfo code
Bram Moolenaar <Bram@vim.org>
parents: 19852
diff changeset
122 exe "norm! 4G>>"
dc3d45d9a4a8 patch 8.2.3010: not enough testing for viminfo code
Bram Moolenaar <Bram@vim.org>
parents: 19852
diff changeset
123 call assert_equal([' {', 'if (x)', 'i = 1;', '#define FOO 1',
dc3d45d9a4a8 patch 8.2.3010: not enough testing for viminfo code
Bram Moolenaar <Bram@vim.org>
parents: 19852
diff changeset
124 \ 'j = 2;', 'k = 3;', '}'], getline(1, '$'))
dc3d45d9a4a8 patch 8.2.3010: not enough testing for viminfo code
Bram Moolenaar <Bram@vim.org>
parents: 19852
diff changeset
125 call assert_true(&smartindent)
dc3d45d9a4a8 patch 8.2.3010: not enough testing for viminfo code
Bram Moolenaar <Bram@vim.org>
parents: 19852
diff changeset
126 set nopaste
dc3d45d9a4a8 patch 8.2.3010: not enough testing for viminfo code
Bram Moolenaar <Bram@vim.org>
parents: 19852
diff changeset
127 %d _
dc3d45d9a4a8 patch 8.2.3010: not enough testing for viminfo code
Bram Moolenaar <Bram@vim.org>
parents: 19852
diff changeset
128 exe "norm! i {\nif (x)\ni = 1;\n#define FOO 1\nj = 2;\n}"
dc3d45d9a4a8 patch 8.2.3010: not enough testing for viminfo code
Bram Moolenaar <Bram@vim.org>
parents: 19852
diff changeset
129 exe "norm! Ok = 3;"
dc3d45d9a4a8 patch 8.2.3010: not enough testing for viminfo code
Bram Moolenaar <Bram@vim.org>
parents: 19852
diff changeset
130 exe "norm! 4G>>"
dc3d45d9a4a8 patch 8.2.3010: not enough testing for viminfo code
Bram Moolenaar <Bram@vim.org>
parents: 19852
diff changeset
131 call assert_equal([' {', "\t if (x)", "\t\t i = 1;",
dc3d45d9a4a8 patch 8.2.3010: not enough testing for viminfo code
Bram Moolenaar <Bram@vim.org>
parents: 19852
diff changeset
132 \ '#define FOO 1', "\t\t j = 2;", "\t k = 3;", ' }'],
dc3d45d9a4a8 patch 8.2.3010: not enough testing for viminfo code
Bram Moolenaar <Bram@vim.org>
parents: 19852
diff changeset
133 \ getline(1, '$'))
dc3d45d9a4a8 patch 8.2.3010: not enough testing for viminfo code
Bram Moolenaar <Bram@vim.org>
parents: 19852
diff changeset
134 bw!
dc3d45d9a4a8 patch 8.2.3010: not enough testing for viminfo code
Bram Moolenaar <Bram@vim.org>
parents: 19852
diff changeset
135 endfunc
dc3d45d9a4a8 patch 8.2.3010: not enough testing for viminfo code
Bram Moolenaar <Bram@vim.org>
parents: 19852
diff changeset
136
28856
948877671c54 patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents: 24946
diff changeset
137 func Test_si_after_completion()
948877671c54 patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents: 24946
diff changeset
138 new
948877671c54 patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents: 24946
diff changeset
139 setlocal ai smartindent indentexpr=
948877671c54 patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents: 24946
diff changeset
140 call setline(1, 'foo foot')
948877671c54 patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents: 24946
diff changeset
141 call feedkeys("o f\<C-X>\<C-N>#", 'tx')
948877671c54 patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents: 24946
diff changeset
142 call assert_equal(' foo#', getline(2))
28860
3942ea75b4c0 patch 8.2.4953: with 'si' inserting '}' after completion goes wrong
Bram Moolenaar <Bram@vim.org>
parents: 28856
diff changeset
143
3942ea75b4c0 patch 8.2.4953: with 'si' inserting '}' after completion goes wrong
Bram Moolenaar <Bram@vim.org>
parents: 28856
diff changeset
144 call setline(2, '')
3942ea75b4c0 patch 8.2.4953: with 'si' inserting '}' after completion goes wrong
Bram Moolenaar <Bram@vim.org>
parents: 28856
diff changeset
145 call feedkeys("1Go f\<C-X>\<C-N>}", 'tx')
3942ea75b4c0 patch 8.2.4953: with 'si' inserting '}' after completion goes wrong
Bram Moolenaar <Bram@vim.org>
parents: 28856
diff changeset
146 call assert_equal(' foo}', getline(2))
3942ea75b4c0 patch 8.2.4953: with 'si' inserting '}' after completion goes wrong
Bram Moolenaar <Bram@vim.org>
parents: 28856
diff changeset
147
28856
948877671c54 patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents: 24946
diff changeset
148 bwipe!
948877671c54 patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents: 24946
diff changeset
149 endfunc
948877671c54 patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents: 24946
diff changeset
150
948877671c54 patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents: 24946
diff changeset
151 func Test_no_si_after_completion()
948877671c54 patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents: 24946
diff changeset
152 new
948877671c54 patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents: 24946
diff changeset
153 call setline(1, 'foo foot')
948877671c54 patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents: 24946
diff changeset
154 call feedkeys("o f\<C-X>\<C-N>#", 'tx')
948877671c54 patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents: 24946
diff changeset
155 call assert_equal(' foo#', getline(2))
948877671c54 patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents: 24946
diff changeset
156 bwipe!
948877671c54 patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents: 24946
diff changeset
157 endfunc
948877671c54 patch 8.2.4951: smart indenting done when not enabled
Bram Moolenaar <Bram@vim.org>
parents: 24946
diff changeset
158
11943
268b1036cd17 patch 8.0.0851: 'smartindent' is used even when 'indentexpr' is set
Christian Brabandt <cb@256bit.org>
parents: 10145
diff changeset
159 " vim: shiftwidth=2 sts=2 expandtab