Mercurial > vim
annotate src/testdir/test_cindent.vim @ 14525:e20810cb5b72
Added tag v8.1.0275 for changeset e36d6e01708c93058f2822d97d687709e14973e9
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 12 Aug 2018 16:00:06 +0200 |
parents | 4dba3e4f3b01 |
children | 81be817c9d9a |
rev | line source |
---|---|
11069
814126a34c9d
patch 8.0.0423: changing 'cinoptions' does not always work
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1 " Test for cinoptions and cindent |
814126a34c9d
patch 8.0.0423: changing 'cinoptions' does not always work
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2 " |
814126a34c9d
patch 8.0.0423: changing 'cinoptions' does not always work
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3 " TODO: rewrite test3.in into this new style test |
814126a34c9d
patch 8.0.0423: changing 'cinoptions' does not always work
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4 |
814126a34c9d
patch 8.0.0423: changing 'cinoptions' does not always work
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5 func Test_cino_hash() |
814126a34c9d
patch 8.0.0423: changing 'cinoptions' does not always work
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6 " Test that curbuf->b_ind_hash_comment is correctly reset |
814126a34c9d
patch 8.0.0423: changing 'cinoptions' does not always work
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
7 new |
814126a34c9d
patch 8.0.0423: changing 'cinoptions' does not always work
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
8 setlocal cindent cinoptions=#1 |
814126a34c9d
patch 8.0.0423: changing 'cinoptions' does not always work
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
9 setlocal cinoptions= |
814126a34c9d
patch 8.0.0423: changing 'cinoptions' does not always work
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
10 call setline(1, ["#include <iostream>"]) |
814126a34c9d
patch 8.0.0423: changing 'cinoptions' does not always work
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
11 call cursor(1, 1) |
814126a34c9d
patch 8.0.0423: changing 'cinoptions' does not always work
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
12 norm! o#include |
814126a34c9d
patch 8.0.0423: changing 'cinoptions' does not always work
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
13 "call feedkeys("o#include\<esc>", 't') |
814126a34c9d
patch 8.0.0423: changing 'cinoptions' does not always work
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
14 call assert_equal(["#include <iostream>", "#include"], getline(1,2)) |
814126a34c9d
patch 8.0.0423: changing 'cinoptions' does not always work
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
15 bwipe! |
814126a34c9d
patch 8.0.0423: changing 'cinoptions' does not always work
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
16 endfunc |
11087
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
17 |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
18 func Test_cino_extern_c() |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
19 " Test for cino-E |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
20 |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
21 let without_ind = [ |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
22 \ '#ifdef __cplusplus', |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
23 \ 'extern "C" {', |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
24 \ '#endif', |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
25 \ 'int func_a(void);', |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
26 \ '#ifdef __cplusplus', |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
27 \ '}', |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
28 \ '#endif' |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
29 \ ] |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
30 |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
31 let with_ind = [ |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
32 \ '#ifdef __cplusplus', |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
33 \ 'extern "C" {', |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
34 \ '#endif', |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
35 \ "\tint func_a(void);", |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
36 \ '#ifdef __cplusplus', |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
37 \ '}', |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
38 \ '#endif' |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
39 \ ] |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
40 new |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
41 setlocal cindent cinoptions=E0 |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
42 call setline(1, without_ind) |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
43 call feedkeys("gg=G", 'tx') |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
44 call assert_equal(with_ind, getline(1, '$')) |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
45 |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
46 setlocal cinoptions=E-s |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
47 call setline(1, with_ind) |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
48 call feedkeys("gg=G", 'tx') |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
49 call assert_equal(without_ind, getline(1, '$')) |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
50 |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
51 setlocal cinoptions=Es |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
52 let tests = [ |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
53 \ ['recognized', ['extern "C" {'], "\t\t;"], |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
54 \ ['recognized', ['extern "C++" {'], "\t\t;"], |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
55 \ ['recognized', ['extern /* com */ "C"{'], "\t\t;"], |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
56 \ ['recognized', ['extern"C"{'], "\t\t;"], |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
57 \ ['recognized', ['extern "C"', '{'], "\t\t;"], |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
58 \ ['not recognized', ['extern {'], "\t;"], |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
59 \ ['not recognized', ['extern /*"C"*/{'], "\t;"], |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
60 \ ['not recognized', ['extern "C" //{'], ";"], |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
61 \ ['not recognized', ['extern "C" /*{*/'], ";"], |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
62 \ ] |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
63 |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
64 for pair in tests |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
65 let lines = pair[1] |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
66 call setline(1, lines) |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
67 call feedkeys(len(lines) . "Go;", 'tx') |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
68 call assert_equal(pair[2], getline(len(lines) + 1), 'Failed for "' . string(lines) . '"') |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
69 endfor |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
70 |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
71 bwipe! |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
72 endfunc |
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
73 |
12323
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
74 func Test_cindent_rawstring() |
12238
0066a7e178bc
patch 8.0.0999: indenting raw C++ strings is wrong
Christian Brabandt <cb@256bit.org>
parents:
11087
diff
changeset
|
75 new |
0066a7e178bc
patch 8.0.0999: indenting raw C++ strings is wrong
Christian Brabandt <cb@256bit.org>
parents:
11087
diff
changeset
|
76 setl cindent |
0066a7e178bc
patch 8.0.0999: indenting raw C++ strings is wrong
Christian Brabandt <cb@256bit.org>
parents:
11087
diff
changeset
|
77 call feedkeys("i" . |
0066a7e178bc
patch 8.0.0999: indenting raw C++ strings is wrong
Christian Brabandt <cb@256bit.org>
parents:
11087
diff
changeset
|
78 \ "int main() {\<CR>" . |
0066a7e178bc
patch 8.0.0999: indenting raw C++ strings is wrong
Christian Brabandt <cb@256bit.org>
parents:
11087
diff
changeset
|
79 \ "R\"(\<CR>" . |
0066a7e178bc
patch 8.0.0999: indenting raw C++ strings is wrong
Christian Brabandt <cb@256bit.org>
parents:
11087
diff
changeset
|
80 \ ")\";\<CR>" . |
0066a7e178bc
patch 8.0.0999: indenting raw C++ strings is wrong
Christian Brabandt <cb@256bit.org>
parents:
11087
diff
changeset
|
81 \ "statement;\<Esc>", "x") |
0066a7e178bc
patch 8.0.0999: indenting raw C++ strings is wrong
Christian Brabandt <cb@256bit.org>
parents:
11087
diff
changeset
|
82 call assert_equal("\tstatement;", getline(line('.'))) |
0066a7e178bc
patch 8.0.0999: indenting raw C++ strings is wrong
Christian Brabandt <cb@256bit.org>
parents:
11087
diff
changeset
|
83 bw! |
12323
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
84 endfunc |
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
85 |
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
86 func Test_cindent_expr() |
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
87 new |
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
88 func! MyIndentFunction() |
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
89 return v:lnum == 1 ? shiftwidth() : 0 |
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
90 endfunc |
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
91 setl expandtab sw=8 indentkeys+=; indentexpr=MyIndentFunction() |
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
92 call setline(1, ['var_a = something()', 'b = something()']) |
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
93 call cursor(1, 1) |
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
94 call feedkeys("^\<c-v>j$A;\<esc>", 'tnix') |
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
95 call assert_equal([' var_a = something();', 'b = something();'], getline(1, '$')) |
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
96 |
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
97 %d |
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
98 call setline(1, [' var_a = something()', ' b = something()']) |
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
99 call cursor(1, 1) |
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
100 call feedkeys("^\<c-v>j$A;\<esc>", 'tnix') |
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
101 call assert_equal([' var_a = something();', ' b = something()'], getline(1, '$')) |
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
102 bw! |
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
103 endfunc |
4dba3e4f3b01
patch 8.0.1041: bogus characters when indenting during visual-block append
Christian Brabandt <cb@256bit.org>
parents:
12238
diff
changeset
|
104 |
11087
242e0617aa51
patch 8.0.0431: 'cinoptions' cannot set indent for extern block
Christian Brabandt <cb@256bit.org>
parents:
11069
diff
changeset
|
105 " vim: shiftwidth=2 sts=2 expandtab |