Mercurial > vim
comparison 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 |
comparison
equal
deleted
inserted
replaced
19851:e259e7903c55 | 19852:12518b40c161 |
---|---|
19 | 19 |
20 " When 'indentexpr' is set, setting 'si' has no effect. | 20 " When 'indentexpr' is set, setting 'si' has no effect. |
21 func Test_smartindent_has_no_effect() | 21 func Test_smartindent_has_no_effect() |
22 new | 22 new |
23 exe "normal! i\<Tab>one\<Esc>" | 23 exe "normal! i\<Tab>one\<Esc>" |
24 set noautoindent | 24 setlocal noautoindent smartindent indentexpr= |
25 set smartindent | |
26 set indentexpr= | |
27 exe "normal! Gotwo\<Esc>" | 25 exe "normal! Gotwo\<Esc>" |
28 call assert_equal("\ttwo", getline("$")) | 26 call assert_equal("\ttwo", getline("$")) |
29 | 27 |
30 set indentexpr=MyIndent | 28 set indentexpr=MyIndent |
31 exe "normal! Gothree\<Esc>" | 29 exe "normal! Gothree\<Esc>" |
32 call assert_equal("three", getline("$")) | 30 call assert_equal("three", getline("$")) |
33 | 31 |
34 delfunction! MyIndent | 32 delfunction! MyIndent |
35 set autoindent& | |
36 set smartindent& | |
37 set indentexpr& | |
38 bwipe! | 33 bwipe! |
39 endfunc | 34 endfunc |
40 | 35 |
41 " Test for inserting '{' and '} with smartindent | 36 " Test for inserting '{' and '} with smartindent |
42 func Test_smartindent_braces() | 37 func Test_smartindent_braces() |
43 new | 38 new |
44 set smartindent shiftwidth=4 | 39 setlocal smartindent shiftwidth=4 |
45 call setline(1, [' if (a)', "\tif (b)", "\t return 1"]) | 40 call setline(1, [' if (a)', "\tif (b)", "\t return 1"]) |
46 normal 2ggO{ | 41 normal 2ggO{ |
47 normal 3ggA { | 42 normal 3ggA { |
48 normal 4ggo} | 43 normal 4ggo} |
49 normal o} | 44 normal o} |
55 \ '#define FOO 1', | 50 \ '#define FOO 1', |
56 \ "\t return 1", | 51 \ "\t return 1", |
57 \ "\t}", | 52 \ "\t}", |
58 \ ' }' | 53 \ ' }' |
59 \ ], getline(1, '$')) | 54 \ ], getline(1, '$')) |
60 set si& sw& ai& | 55 close! |
56 endfunc | |
57 | |
58 " Test for adding a new line before and after comments with smartindent | |
59 func Test_si_add_line_around_comment() | |
60 new | |
61 setlocal smartindent shiftwidth=4 | |
62 call setline(1, [' A', '# comment1', '# comment2']) | |
63 exe "normal GoC\<Esc>2GOB" | |
64 call assert_equal([' A', ' B', '# comment1', '# comment2', ' C'], | |
65 \ getline(1, '$')) | |
66 close! | |
67 endfunc | |
68 | |
69 " After a C style comment, indent for a following line should line up with the | |
70 " line containing the start of the comment. | |
71 func Test_si_indent_after_c_comment() | |
72 new | |
73 setlocal smartindent shiftwidth=4 fo+=ro | |
74 exe "normal i\<C-t>/*\ncomment\n/\n#define FOOBAR\n75\<Esc>ggOabc" | |
75 normal 3jOcont | |
76 call assert_equal([' abc', ' /*', ' * comment', ' * cont', | |
77 \ ' */', '#define FOOBAR', ' 75'], getline(1, '$')) | |
78 close! | |
79 endfunc | |
80 | |
81 " Test for indenting a statement after a if condition split across lines | |
82 func Test_si_if_cond_split_across_lines() | |
83 new | |
84 setlocal smartindent shiftwidth=4 | |
85 exe "normal i\<C-t>if (cond1 &&\n\<C-t>cond2) {\ni = 10;\n}" | |
86 call assert_equal([' if (cond1 &&', "\t cond2) {", "\ti = 10;", | |
87 \ ' }'], getline(1, '$')) | |
88 close! | |
89 endfunc | |
90 | |
91 " Test for inserting lines before and after a one line comment | |
92 func Test_si_one_line_comment() | |
93 new | |
94 setlocal smartindent shiftwidth=4 | |
95 exe "normal i\<C-t>abc;\n\<C-t>/* comment */" | |
96 normal oi = 10; | |
97 normal kOj = 1; | |
98 call assert_equal([' abc;', "\tj = 1;", "\t/* comment */", "\ti = 10;"], | |
99 \ getline(1, '$')) | |
100 close! | |
101 endfunc | |
102 | |
103 " Test for smartindent with a comment continued across multiple lines | |
104 func Test_si_comment_line_continuation() | |
105 new | |
106 setlocal smartindent shiftwidth=4 | |
107 call setline(1, ['# com1', '# com2 \', ' contd', '# com3', ' xyz']) | |
108 normal ggOabc | |
109 call assert_equal([' abc', '# com1', '# com2 \', ' contd', '# com3', | |
110 \ ' xyz'], getline(1, '$')) | |
61 close! | 111 close! |
62 endfunc | 112 endfunc |
63 | 113 |
64 " vim: shiftwidth=2 sts=2 expandtab | 114 " vim: shiftwidth=2 sts=2 expandtab |