Bram Moolenaar | 69a76fe | 2017-08-03 17:54:03 +0200 | [diff] [blame] | 1 | " Tests for smartindent |
Bram Moolenaar | 53f1673 | 2016-09-07 20:46:39 +0200 | [diff] [blame] | 2 | |
| 3 | " Tests for not doing smart indenting when it isn't set. |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 4 | func Test_nosmartindent() |
Bram Moolenaar | 53f1673 | 2016-09-07 20:46:39 +0200 | [diff] [blame] | 5 | new |
| 6 | call append(0, [" some test text", |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 7 | \ " test text", |
| 8 | \ "test text", |
| 9 | \ " test text"]) |
Bram Moolenaar | 53f1673 | 2016-09-07 20:46:39 +0200 | [diff] [blame] | 10 | set nocindent nosmartindent autoindent |
| 11 | exe "normal! gg/some\<CR>" |
| 12 | exe "normal! 2cc#test\<Esc>" |
| 13 | call assert_equal(" #test", getline(1)) |
| 14 | enew! | close |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 15 | endfunc |
Bram Moolenaar | 69a76fe | 2017-08-03 17:54:03 +0200 | [diff] [blame] | 16 | |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 17 | func MyIndent() |
| 18 | endfunc |
Bram Moolenaar | 69a76fe | 2017-08-03 17:54:03 +0200 | [diff] [blame] | 19 | |
| 20 | " When 'indentexpr' is set, setting 'si' has no effect. |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 21 | func Test_smartindent_has_no_effect() |
Bram Moolenaar | 69a76fe | 2017-08-03 17:54:03 +0200 | [diff] [blame] | 22 | new |
| 23 | exe "normal! i\<Tab>one\<Esc>" |
| 24 | set noautoindent |
| 25 | set smartindent |
| 26 | set indentexpr= |
| 27 | exe "normal! Gotwo\<Esc>" |
| 28 | call assert_equal("\ttwo", getline("$")) |
| 29 | |
| 30 | set indentexpr=MyIndent |
| 31 | exe "normal! Gothree\<Esc>" |
| 32 | call assert_equal("three", getline("$")) |
| 33 | |
| 34 | delfunction! MyIndent |
| 35 | set autoindent& |
| 36 | set smartindent& |
| 37 | set indentexpr& |
| 38 | bwipe! |
Bram Moolenaar | 1e11536 | 2019-01-09 23:01:02 +0100 | [diff] [blame] | 39 | endfunc |
Bram Moolenaar | 69a76fe | 2017-08-03 17:54:03 +0200 | [diff] [blame] | 40 | |
Bram Moolenaar | bd7206e | 2020-03-06 20:36:04 +0100 | [diff] [blame^] | 41 | " Test for inserting '{' and '} with smartindent |
| 42 | func Test_smartindent_braces() |
| 43 | new |
| 44 | set smartindent shiftwidth=4 |
| 45 | call setline(1, [' if (a)', "\tif (b)", "\t return 1"]) |
| 46 | normal 2ggO{ |
| 47 | normal 3ggA { |
| 48 | normal 4ggo} |
| 49 | normal o} |
| 50 | normal 4ggO#define FOO 1 |
| 51 | call assert_equal([ |
| 52 | \ ' if (a)', |
| 53 | \ ' {', |
| 54 | \ "\tif (b) {", |
| 55 | \ '#define FOO 1', |
| 56 | \ "\t return 1", |
| 57 | \ "\t}", |
| 58 | \ ' }' |
| 59 | \ ], getline(1, '$')) |
| 60 | set si& sw& ai& |
| 61 | close! |
| 62 | endfunc |
| 63 | |
Bram Moolenaar | 69a76fe | 2017-08-03 17:54:03 +0200 | [diff] [blame] | 64 | " vim: shiftwidth=2 sts=2 expandtab |