2018-01-20 00:47:56 -07:00
|
|
|
" Test for cinoptions and cindent
|
|
|
|
"
|
|
|
|
" TODO: rewrite test3.in into this new style test
|
|
|
|
|
|
|
|
func Test_cino_hash()
|
|
|
|
" Test that curbuf->b_ind_hash_comment is correctly reset
|
|
|
|
new
|
|
|
|
setlocal cindent cinoptions=#1
|
|
|
|
setlocal cinoptions=
|
|
|
|
call setline(1, ["#include <iostream>"])
|
|
|
|
call cursor(1, 1)
|
|
|
|
norm! o#include
|
|
|
|
"call feedkeys("o#include\<esc>", 't')
|
|
|
|
call assert_equal(["#include <iostream>", "#include"], getline(1,2))
|
|
|
|
bwipe!
|
|
|
|
endfunc
|
2018-01-25 03:26:47 -07:00
|
|
|
|
|
|
|
func Test_cino_extern_c()
|
|
|
|
" Test for cino-E
|
|
|
|
|
2019-09-23 13:12:02 -07:00
|
|
|
let without_ind =<< trim [CODE]
|
2019-10-12 00:48:48 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
int func_a(void);
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2019-09-23 13:12:02 -07:00
|
|
|
[CODE]
|
2018-01-25 03:26:47 -07:00
|
|
|
|
2019-09-23 13:12:02 -07:00
|
|
|
let with_ind =<< trim [CODE]
|
2019-10-12 00:48:48 -07:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
int func_a(void);
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2019-09-23 13:12:02 -07:00
|
|
|
[CODE]
|
2018-01-25 03:26:47 -07:00
|
|
|
new
|
|
|
|
setlocal cindent cinoptions=E0
|
|
|
|
call setline(1, without_ind)
|
|
|
|
call feedkeys("gg=G", 'tx')
|
|
|
|
call assert_equal(with_ind, getline(1, '$'))
|
|
|
|
|
|
|
|
setlocal cinoptions=E-s
|
|
|
|
call setline(1, with_ind)
|
|
|
|
call feedkeys("gg=G", 'tx')
|
|
|
|
call assert_equal(without_ind, getline(1, '$'))
|
|
|
|
|
|
|
|
setlocal cinoptions=Es
|
|
|
|
let tests = [
|
|
|
|
\ ['recognized', ['extern "C" {'], "\t\t;"],
|
|
|
|
\ ['recognized', ['extern "C++" {'], "\t\t;"],
|
|
|
|
\ ['recognized', ['extern /* com */ "C"{'], "\t\t;"],
|
|
|
|
\ ['recognized', ['extern"C"{'], "\t\t;"],
|
|
|
|
\ ['recognized', ['extern "C"', '{'], "\t\t;"],
|
|
|
|
\ ['not recognized', ['extern {'], "\t;"],
|
|
|
|
\ ['not recognized', ['extern /*"C"*/{'], "\t;"],
|
|
|
|
\ ['not recognized', ['extern "C" //{'], ";"],
|
|
|
|
\ ['not recognized', ['extern "C" /*{*/'], ";"],
|
|
|
|
\ ]
|
|
|
|
|
|
|
|
for pair in tests
|
|
|
|
let lines = pair[1]
|
|
|
|
call setline(1, lines)
|
|
|
|
call feedkeys(len(lines) . "Go;", 'tx')
|
|
|
|
call assert_equal(pair[2], getline(len(lines) + 1), 'Failed for "' . string(lines) . '"')
|
|
|
|
endfor
|
|
|
|
|
|
|
|
bwipe!
|
|
|
|
endfunc
|
|
|
|
|
2018-08-23 01:43:44 -07:00
|
|
|
func Test_cindent_rawstring()
|
2018-08-23 00:38:06 -07:00
|
|
|
new
|
|
|
|
setl cindent
|
|
|
|
call feedkeys("i" .
|
|
|
|
\ "int main() {\<CR>" .
|
|
|
|
\ "R\"(\<CR>" .
|
|
|
|
\ ")\";\<CR>" .
|
|
|
|
\ "statement;\<Esc>", "x")
|
|
|
|
call assert_equal("\tstatement;", getline(line('.')))
|
|
|
|
bw!
|
2018-08-23 01:43:44 -07:00
|
|
|
endfunc
|
|
|
|
|
|
|
|
func Test_cindent_expr()
|
|
|
|
new
|
|
|
|
func! MyIndentFunction()
|
|
|
|
return v:lnum == 1 ? shiftwidth() : 0
|
|
|
|
endfunc
|
|
|
|
setl expandtab sw=8 indentkeys+=; indentexpr=MyIndentFunction()
|
2019-09-23 13:12:02 -07:00
|
|
|
let testinput =<< trim [CODE]
|
2019-10-12 00:48:48 -07:00
|
|
|
var_a = something()
|
|
|
|
b = something()
|
2019-09-23 13:12:02 -07:00
|
|
|
[CODE]
|
|
|
|
call setline(1, testinput)
|
2018-08-23 01:43:44 -07:00
|
|
|
call cursor(1, 1)
|
|
|
|
call feedkeys("^\<c-v>j$A;\<esc>", 'tnix')
|
2019-10-12 00:48:48 -07:00
|
|
|
let expected =<< [CODE]
|
|
|
|
var_a = something();
|
|
|
|
b = something();
|
|
|
|
[CODE]
|
2019-09-23 13:12:02 -07:00
|
|
|
call assert_equal(expected, getline(1, '$'))
|
2018-08-23 01:43:44 -07:00
|
|
|
|
|
|
|
%d
|
2019-10-12 00:48:48 -07:00
|
|
|
let testinput =<< [CODE]
|
|
|
|
var_a = something()
|
|
|
|
b = something()
|
|
|
|
[CODE]
|
2019-09-23 13:12:02 -07:00
|
|
|
call setline(1, testinput)
|
2018-08-23 01:43:44 -07:00
|
|
|
call cursor(1, 1)
|
|
|
|
call feedkeys("^\<c-v>j$A;\<esc>", 'tnix')
|
2019-10-12 00:48:48 -07:00
|
|
|
let expected =<< [CODE]
|
|
|
|
var_a = something();
|
|
|
|
b = something()
|
|
|
|
[CODE]
|
2019-09-23 13:12:02 -07:00
|
|
|
call assert_equal(expected, getline(1, '$'))
|
2018-08-23 01:43:44 -07:00
|
|
|
bw!
|
|
|
|
endfunc
|
|
|
|
|
2018-01-25 03:26:47 -07:00
|
|
|
" vim: shiftwidth=2 sts=2 expandtab
|