Bram Moolenaar | 6b64394 | 2017-03-05 19:44:06 +0100 | [diff] [blame] | 1 | " Test for cinoptions and cindent |
| 2 | " |
| 3 | " TODO: rewrite test3.in into this new style test |
| 4 | |
| 5 | func Test_cino_hash() |
| 6 | " Test that curbuf->b_ind_hash_comment is correctly reset |
| 7 | new |
| 8 | setlocal cindent cinoptions=#1 |
| 9 | setlocal cinoptions= |
| 10 | call setline(1, ["#include <iostream>"]) |
| 11 | call cursor(1, 1) |
| 12 | norm! o#include |
| 13 | "call feedkeys("o#include\<esc>", 't') |
| 14 | call assert_equal(["#include <iostream>", "#include"], getline(1,2)) |
| 15 | bwipe! |
| 16 | endfunc |
Bram Moolenaar | 7720ba8 | 2017-03-08 22:19:26 +0100 | [diff] [blame] | 17 | |
| 18 | func Test_cino_extern_c() |
| 19 | " Test for cino-E |
| 20 | |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 21 | let without_ind =<< trim [CODE] |
| 22 | #ifdef __cplusplus |
| 23 | extern "C" { |
| 24 | #endif |
| 25 | int func_a(void); |
| 26 | #ifdef __cplusplus |
| 27 | } |
| 28 | #endif |
| 29 | [CODE] |
Bram Moolenaar | 7720ba8 | 2017-03-08 22:19:26 +0100 | [diff] [blame] | 30 | |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 31 | let with_ind =<< trim [CODE] |
| 32 | #ifdef __cplusplus |
| 33 | extern "C" { |
| 34 | #endif |
| 35 | int func_a(void); |
| 36 | #ifdef __cplusplus |
| 37 | } |
| 38 | #endif |
| 39 | [CODE] |
Bram Moolenaar | 7720ba8 | 2017-03-08 22:19:26 +0100 | [diff] [blame] | 40 | new |
| 41 | setlocal cindent cinoptions=E0 |
| 42 | call setline(1, without_ind) |
| 43 | call feedkeys("gg=G", 'tx') |
| 44 | call assert_equal(with_ind, getline(1, '$')) |
| 45 | |
| 46 | setlocal cinoptions=E-s |
| 47 | call setline(1, with_ind) |
| 48 | call feedkeys("gg=G", 'tx') |
| 49 | call assert_equal(without_ind, getline(1, '$')) |
| 50 | |
| 51 | setlocal cinoptions=Es |
| 52 | let tests = [ |
| 53 | \ ['recognized', ['extern "C" {'], "\t\t;"], |
| 54 | \ ['recognized', ['extern "C++" {'], "\t\t;"], |
| 55 | \ ['recognized', ['extern /* com */ "C"{'], "\t\t;"], |
| 56 | \ ['recognized', ['extern"C"{'], "\t\t;"], |
| 57 | \ ['recognized', ['extern "C"', '{'], "\t\t;"], |
| 58 | \ ['not recognized', ['extern {'], "\t;"], |
| 59 | \ ['not recognized', ['extern /*"C"*/{'], "\t;"], |
| 60 | \ ['not recognized', ['extern "C" //{'], ";"], |
| 61 | \ ['not recognized', ['extern "C" /*{*/'], ";"], |
| 62 | \ ] |
| 63 | |
| 64 | for pair in tests |
| 65 | let lines = pair[1] |
| 66 | call setline(1, lines) |
| 67 | call feedkeys(len(lines) . "Go;", 'tx') |
| 68 | call assert_equal(pair[2], getline(len(lines) + 1), 'Failed for "' . string(lines) . '"') |
| 69 | endfor |
| 70 | |
Bram Moolenaar | 7720ba8 | 2017-03-08 22:19:26 +0100 | [diff] [blame] | 71 | bwipe! |
| 72 | endfunc |
| 73 | |
Bram Moolenaar | e2e69e4 | 2017-09-02 20:30:35 +0200 | [diff] [blame] | 74 | func Test_cindent_rawstring() |
Bram Moolenaar | dde8131 | 2017-08-26 17:49:01 +0200 | [diff] [blame] | 75 | new |
| 76 | setl cindent |
| 77 | call feedkeys("i" . |
| 78 | \ "int main() {\<CR>" . |
| 79 | \ "R\"(\<CR>" . |
| 80 | \ ")\";\<CR>" . |
| 81 | \ "statement;\<Esc>", "x") |
| 82 | call assert_equal("\tstatement;", getline(line('.'))) |
| 83 | bw! |
Bram Moolenaar | e2e69e4 | 2017-09-02 20:30:35 +0200 | [diff] [blame] | 84 | endfunc |
| 85 | |
| 86 | func Test_cindent_expr() |
| 87 | new |
| 88 | func! MyIndentFunction() |
| 89 | return v:lnum == 1 ? shiftwidth() : 0 |
| 90 | endfunc |
| 91 | setl expandtab sw=8 indentkeys+=; indentexpr=MyIndentFunction() |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 92 | let testinput =<< trim [CODE] |
| 93 | var_a = something() |
| 94 | b = something() |
| 95 | [CODE] |
| 96 | call setline(1, testinput) |
Bram Moolenaar | e2e69e4 | 2017-09-02 20:30:35 +0200 | [diff] [blame] | 97 | call cursor(1, 1) |
| 98 | call feedkeys("^\<c-v>j$A;\<esc>", 'tnix') |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 99 | let expected =<< trim [CODE] |
| 100 | var_a = something(); |
| 101 | b = something(); |
| 102 | [CODE] |
| 103 | call assert_equal(expected, getline(1, '$')) |
Bram Moolenaar | e2e69e4 | 2017-09-02 20:30:35 +0200 | [diff] [blame] | 104 | |
| 105 | %d |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 106 | let testinput =<< trim [CODE] |
| 107 | var_a = something() |
| 108 | b = something() |
| 109 | [CODE] |
| 110 | call setline(1, testinput) |
Bram Moolenaar | e2e69e4 | 2017-09-02 20:30:35 +0200 | [diff] [blame] | 111 | call cursor(1, 1) |
| 112 | call feedkeys("^\<c-v>j$A;\<esc>", 'tnix') |
Bram Moolenaar | c79745a | 2019-05-20 22:12:34 +0200 | [diff] [blame] | 113 | let expected =<< trim [CODE] |
| 114 | var_a = something(); |
| 115 | b = something() |
| 116 | [CODE] |
| 117 | call assert_equal(expected, getline(1, '$')) |
Bram Moolenaar | e2e69e4 | 2017-09-02 20:30:35 +0200 | [diff] [blame] | 118 | bw! |
| 119 | endfunc |
| 120 | |
Bram Moolenaar | 17aca70 | 2019-05-16 22:24:55 +0200 | [diff] [blame] | 121 | func Test_cindent_func() |
| 122 | new |
| 123 | setlocal cindent |
| 124 | call setline(1, ['int main(void)', '{', 'return 0;', '}']) |
| 125 | call assert_equal(cindent(0), -1) |
| 126 | call assert_equal(cindent(3), &sw) |
| 127 | call assert_equal(cindent(line('$')+1), -1) |
| 128 | bwipe! |
| 129 | endfunc |
| 130 | |
Bram Moolenaar | 7720ba8 | 2017-03-08 22:19:26 +0100 | [diff] [blame] | 131 | " vim: shiftwidth=2 sts=2 expandtab |