robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
af23d17388
master
1" Tests for smartindent 2 3" Tests for not doing smart indenting when it isn't set. 4func Test_nosmartindent () 5new 6call append ( 0 , [ " some test text" , 7 \" test text" , 8 \"test text" , 9 \" test text" ]) 10set nocindent nosmartindent autoindent 11exe "normal! gg/some\<CR>" 12exe "normal! 2cc#test\<Esc>" 13call assert_equal ( " #test" , getline ( 1 )) 14enew ! |close 15endfunc 16 17func MyIndent () 18endfunc 19 20" When 'indentexpr' is set, setting 'si' has no effect. 21func Test_smartindent_has_no_effect () 22new 23exe "normal! i\<Tab>one\<Esc>" 24setlocal noautoindent smartindent indentexpr = 25exe "normal! Gotwo\<Esc>" 26call assert_equal ( "\ttwo" , getline ( "$" )) 27 28set indentexpr = MyIndent 29exe "normal! Gothree\<Esc>" 30call assert_equal ( "three" , getline ( "$" )) 31 32delfunction ! MyIndent 33bwipe ! 34endfunc 35 36" Test for inserting '{' and '} with smartindent 37func Test_smartindent_braces () 38new 39setlocal smartindent shiftwidth = 4 40call setline ( 1 , [ ' if (a)' , "\tif (b)" , "\t return 1" ]) 41normal 2ggO{ 42normal 3ggA { 43normal 4ggo} 44normal o} 45normal 4ggO#define FOO 1 46call assert_equal ([ 47 \' if (a)' , 48 \' {' , 49 \"\tif (b) {" , 50 \'#define FOO 1' , 51 \"\t return 1" , 52 \"\t}" , 53 \' }' 54 \], getline ( 1 , '$' )) 55close ! 56endfunc 57 58" Test for adding a new line before and after comments with smartindent 59func Test_si_add_line_around_comment () 60new 61setlocal smartindent shiftwidth = 4 62call setline ( 1 , [ ' A' , '# comment1' , '# comment2' ]) 63exe "normal GoC\<Esc>2GOB" 64call assert_equal ([ ' A' , ' B' , '# comment1' , '# comment2' , ' C' ], 65 \getline ( 1 , '$' )) 66close ! 67endfunc 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. 71func Test_si_indent_after_c_comment () 72new 73setlocal smartindent shiftwidth = 4 fo += ro 74exe "normal i\<C-t>/*\ncomment\n/\n#define FOOBAR\n75\<Esc>ggOabc" 75normal 3jOcont 76call assert_equal ([ ' abc' , ' /*' , ' * comment' , ' * cont' , 77 \' */' , '#define FOOBAR' , ' 75' ], getline ( 1 , '$' )) 78close ! 79endfunc 80 81" Test for indenting a statement after a if condition split across lines 82func Test_si_if_cond_split_across_lines () 83new 84setlocal smartindent shiftwidth = 4 85exe "normal i\<C-t>if (cond1 &&\n\<C-t>cond2) {\ni = 10;\n}" 86call assert_equal ([ ' if (cond1 &&' , "\t cond2) {" , "\ti = 10;" , 87 \' }' ], getline ( 1 , '$' )) 88close ! 89endfunc 90 91" Test for inserting lines before and after a one line comment 92func Test_si_one_line_comment () 93new 94setlocal smartindent shiftwidth = 4 95exe "normal i\<C-t>abc;\n\<C-t>/* comment */" 96normal oi = 10; 97normal kOj = 1; 98call assert_equal ([ ' abc;' , "\tj = 1;" , "\t/* comment */" , "\ti = 10;" ], 99 \getline ( 1 , '$' )) 100close ! 101endfunc 102 103" Test for smartindent with a comment continued across multiple lines 104func Test_si_comment_line_continuation () 105new 106setlocal smartindent shiftwidth = 4 107call setline ( 1 , [ '# com1' , '# com2 \' , ' contd' , '# com3' , ' xyz' ]) 108normal ggOabc 109call assert_equal ([ ' abc' , '# com1' , '# com2 \' , ' contd' , '# com3' , 110 \' xyz' ], getline ( 1 , '$' )) 111close ! 112endfunc 113 114func Test_si_after_completion () 115new 116setlocal ai smartindent indentexpr = 117call setline ( 1 , 'foo foot' ) 118call feedkeys ( "o f\<C-X>\<C-N>#" , 'tx' ) 119call assert_equal ( ' foo#' , getline ( 2 )) 120 121call setline ( 2 , '' ) 122call feedkeys ( "1Go f\<C-X>\<C-N>}" , 'tx' ) 123call assert_equal ( ' foo}' , getline ( 2 )) 124 125bwipe ! 126endfunc 127 128func Test_no_si_after_completion () 129new 130call setline ( 1 , 'foo foot' ) 131call feedkeys ( "o f\<C-X>\<C-N>#" , 'tx' ) 132call assert_equal ( ' foo#' , getline ( 2 )) 133bwipe ! 134endfunc 135 136" vim: shiftwidth=2 sts=2 expandtab