Skip to content

Commit c79745a

Browse files
committed
patch 8.1.1362: code and data in tests can be hard to read
Problem: Code and data in tests can be hard to read. Solution: Use the new heredoc style. (Yegappan Lakshmanan, closes #4400)
1 parent 0b0ad35 commit c79745a

17 files changed

Lines changed: 991 additions & 835 deletions

src/testdir/test_autocmd.vim

Lines changed: 54 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -423,18 +423,20 @@ func Test_autocmd_bufwipe_in_SessLoadPost()
423423
set noswapfile
424424
mksession!
425425

426-
let content = ['set nocp noswapfile',
427-
\ 'let v:swapchoice="e"',
428-
\ 'augroup test_autocmd_sessionload',
429-
\ 'autocmd!',
430-
\ 'autocmd SessionLoadPost * exe bufnr("Xsomething") . "bw!"',
431-
\ 'augroup END',
432-
\ '',
433-
\ 'func WriteErrors()',
434-
\ ' call writefile([execute("messages")], "Xerrors")',
435-
\ 'endfunc',
436-
\ 'au VimLeave * call WriteErrors()',
437-
\ ]
426+
let content =<< trim [CODE]
427+
set nocp noswapfile
428+
let v:swapchoice="e"
429+
augroup test_autocmd_sessionload
430+
autocmd!
431+
autocmd SessionLoadPost * exe bufnr("Xsomething") . "bw!"
432+
augroup END
433+
434+
func WriteErrors()
435+
call writefile([execute("messages")], "Xerrors")
436+
endfunc
437+
au VimLeave * call WriteErrors()
438+
[CODE]
439+
438440
call writefile(content, 'Xvimrc')
439441
call system(v:progpath. ' -u Xvimrc --not-a-term --noplugins -S Session.vim -c cq')
440442
let errors = join(readfile('Xerrors'))
@@ -452,27 +454,29 @@ func Test_autocmd_bufwipe_in_SessLoadPost2()
452454
set noswapfile
453455
mksession!
454456

455-
let content = ['set nocp noswapfile',
456-
\ 'function! DeleteInactiveBufs()',
457-
\ ' tabfirst',
458-
\ ' let tabblist = []',
459-
\ ' for i in range(1, tabpagenr(''$''))',
460-
\ ' call extend(tabblist, tabpagebuflist(i))',
461-
\ ' endfor',
462-
\ ' for b in range(1, bufnr(''$''))',
463-
\ ' if bufexists(b) && buflisted(b) && (index(tabblist, b) == -1 || bufname(b) =~# ''^$'')',
464-
\ ' exec ''bwipeout '' . b',
465-
\ ' endif',
466-
\ ' endfor',
467-
\ ' echomsg "SessionLoadPost DONE"',
468-
\ 'endfunction',
469-
\ 'au SessionLoadPost * call DeleteInactiveBufs()',
470-
\ '',
471-
\ 'func WriteErrors()',
472-
\ ' call writefile([execute("messages")], "Xerrors")',
473-
\ 'endfunc',
474-
\ 'au VimLeave * call WriteErrors()',
475-
\ ]
457+
let content =<< trim [CODE]
458+
set nocp noswapfile
459+
function! DeleteInactiveBufs()
460+
tabfirst
461+
let tabblist = []
462+
for i in range(1, tabpagenr(''$''))
463+
call extend(tabblist, tabpagebuflist(i))
464+
endfor
465+
for b in range(1, bufnr(''$''))
466+
if bufexists(b) && buflisted(b) && (index(tabblist, b) == -1 || bufname(b) =~# ''^$'')
467+
exec ''bwipeout '' . b
468+
endif
469+
endfor
470+
echomsg "SessionLoadPost DONE"
471+
endfunction
472+
au SessionLoadPost * call DeleteInactiveBufs()
473+
474+
func WriteErrors()
475+
call writefile([execute("messages")], "Xerrors")
476+
endfunc
477+
au VimLeave * call WriteErrors()
478+
[CODE]
479+
476480
call writefile(content, 'Xvimrc')
477481
call system(v:progpath. ' -u Xvimrc --not-a-term --noplugins -S Session.vim -c cq')
478482
let errors = join(readfile('Xerrors'))
@@ -933,21 +937,23 @@ func Test_bufunload_all()
933937
call writefile(['Test file Xxx1'], 'Xxx1')"
934938
call writefile(['Test file Xxx2'], 'Xxx2')"
935939

936-
let content = [
937-
\ "func UnloadAllBufs()",
938-
\ " let i = 1",
939-
\ " while i <= bufnr('$')",
940-
\ " if i != bufnr('%') && bufloaded(i)",
941-
\ " exe i . 'bunload'",
942-
\ " endif",
943-
\ " let i += 1",
944-
\ " endwhile",
945-
\ "endfunc",
946-
\ "au BufUnload * call UnloadAllBufs()",
947-
\ "au VimLeave * call writefile(['Test Finished'], 'Xout')",
948-
\ "edit Xxx1",
949-
\ "split Xxx2",
950-
\ "q"]
940+
let content =<< trim [CODE]
941+
func UnloadAllBufs()
942+
let i = 1
943+
while i <= bufnr('$')
944+
if i != bufnr('%') && bufloaded(i)
945+
exe i . 'bunload'
946+
endif
947+
let i += 1
948+
endwhile
949+
endfunc
950+
au BufUnload * call UnloadAllBufs()
951+
au VimLeave * call writefile(['Test Finished'], 'Xout')
952+
edit Xxx1
953+
split Xxx2
954+
q
955+
[CODE]
956+
951957
call writefile(content, 'Xtest')
952958

953959
call delete('Xout')

src/testdir/test_balloon.vim

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ if !CanRunVimInTerminal()
88
finish
99
endif
1010

11-
let s:common_script = [
12-
\ 'call setline(1, ["one one one", "two tXo two", "three three three"])',
13-
\ 'set balloonevalterm balloonexpr=MyBalloonExpr() balloondelay=100',
14-
\ 'func MyBalloonExpr()',
15-
\ ' return "line " .. v:beval_lnum .. " column " .. v:beval_col .. ": " .. v:beval_text',
16-
\ 'endfun',
17-
\ 'redraw',
18-
\ ]
11+
let s:common_script =<< [CODE]
12+
call setline(1, ["one one one", "two tXo two", "three three three"])
13+
set balloonevalterm balloonexpr=MyBalloonExpr() balloondelay=100
14+
func MyBalloonExpr()
15+
return "line " .. v:beval_lnum .. " column " .. v:beval_col .. ": " .. v:beval_text
16+
endfun
17+
redraw
18+
[CODE]
1919

2020
func Test_balloon_eval_term()
2121
" Use <Ignore> after <MouseMove> to return from vgetc() without removing

src/testdir/test_bufline.vim

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -93,23 +93,24 @@ func Test_appendbufline()
9393
endfunc
9494

9595
func Test_appendbufline_no_E315()
96-
let after = [
97-
\ 'set stl=%f ls=2',
98-
\ 'new',
99-
\ 'let buf = bufnr("%")',
100-
\ 'quit',
101-
\ 'vsp',
102-
\ 'exec "buffer" buf',
103-
\ 'wincmd w',
104-
\ 'call appendbufline(buf, 0, "abc")',
105-
\ 'redraw',
106-
\ 'while getbufline(buf, 1)[0] =~ "^\\s*$"',
107-
\ ' sleep 10m',
108-
\ 'endwhile',
109-
\ 'au VimLeavePre * call writefile([v:errmsg], "Xerror")',
110-
\ 'au VimLeavePre * call writefile(["done"], "Xdone")',
111-
\ 'qall!',
112-
\ ]
96+
let after =<< trim [CODE]
97+
set stl=%f ls=2
98+
new
99+
let buf = bufnr("%")
100+
quit
101+
vsp
102+
exec "buffer" buf
103+
wincmd w
104+
call appendbufline(buf, 0, "abc")
105+
redraw
106+
while getbufline(buf, 1)[0] =~ "^\\s*$"
107+
sleep 10m
108+
endwhile
109+
au VimLeavePre * call writefile([v:errmsg], "Xerror")
110+
au VimLeavePre * call writefile(["done"], "Xdone")
111+
qall!
112+
[CODE]
113+
113114
if !RunVim([], after, '--clean')
114115
return
115116
endif

src/testdir/test_cindent.vim

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,25 @@ endfunc
1818
func Test_cino_extern_c()
1919
" Test for cino-E
2020

21-
let without_ind = [
22-
\ '#ifdef __cplusplus',
23-
\ 'extern "C" {',
24-
\ '#endif',
25-
\ 'int func_a(void);',
26-
\ '#ifdef __cplusplus',
27-
\ '}',
28-
\ '#endif'
29-
\ ]
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]
3030

31-
let with_ind = [
32-
\ '#ifdef __cplusplus',
33-
\ 'extern "C" {',
34-
\ '#endif',
35-
\ "\tint func_a(void);",
36-
\ '#ifdef __cplusplus',
37-
\ '}',
38-
\ '#endif'
39-
\ ]
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]
4040
new
4141
setlocal cindent cinoptions=E0
4242
call setline(1, without_ind)
@@ -89,16 +89,32 @@ func Test_cindent_expr()
8989
return v:lnum == 1 ? shiftwidth() : 0
9090
endfunc
9191
setl expandtab sw=8 indentkeys+=; indentexpr=MyIndentFunction()
92-
call setline(1, ['var_a = something()', 'b = something()'])
92+
let testinput =<< trim [CODE]
93+
var_a = something()
94+
b = something()
95+
[CODE]
96+
call setline(1, testinput)
9397
call cursor(1, 1)
9498
call feedkeys("^\<c-v>j$A;\<esc>", 'tnix')
95-
call assert_equal([' var_a = something();', 'b = something();'], getline(1, '$'))
99+
let expected =<< trim [CODE]
100+
var_a = something();
101+
b = something();
102+
[CODE]
103+
call assert_equal(expected, getline(1, '$'))
96104

97105
%d
98-
call setline(1, [' var_a = something()', ' b = something()'])
106+
let testinput =<< trim [CODE]
107+
var_a = something()
108+
b = something()
109+
[CODE]
110+
call setline(1, testinput)
99111
call cursor(1, 1)
100112
call feedkeys("^\<c-v>j$A;\<esc>", 'tnix')
101-
call assert_equal([' var_a = something();', ' b = something()'], getline(1, '$'))
113+
let expected =<< trim [CODE]
114+
var_a = something();
115+
b = something()
116+
[CODE]
117+
call assert_equal(expected, getline(1, '$'))
102118
bw!
103119
endfunc
104120

src/testdir/test_conceal.vim

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,23 @@ if !CanRunVimInTerminal()
1111
endif
1212

1313
func Test_conceal_two_windows()
14-
call writefile([
15-
\ 'let lines = ["one one one one one", "two |hidden| here", "three |hidden| three"]',
16-
\ 'call setline(1, lines)',
17-
\ 'syntax match test /|hidden|/ conceal',
18-
\ 'set conceallevel=2',
19-
\ 'set concealcursor=',
20-
\ 'exe "normal /here\r"',
21-
\ 'new',
22-
\ 'call setline(1, lines)',
23-
\ 'call setline(4, "Second window")',
24-
\ 'syntax match test /|hidden|/ conceal',
25-
\ 'set conceallevel=2',
26-
\ 'set concealcursor=nc',
27-
\ 'exe "normal /here\r"',
28-
\ ], 'XTest_conceal')
14+
let code =<< trim [CODE]
15+
let lines = ["one one one one one", "two |hidden| here", "three |hidden| three"]
16+
call setline(1, lines)
17+
syntax match test /|hidden|/ conceal
18+
set conceallevel=2
19+
set concealcursor=
20+
exe "normal /here\r"
21+
new
22+
call setline(1, lines)
23+
call setline(4, "Second window")
24+
syntax match test /|hidden|/ conceal
25+
set conceallevel=2
26+
set concealcursor=nc
27+
exe "normal /here\r"
28+
[CODE]
29+
30+
call writefile(code, 'XTest_conceal')
2931
" Check that cursor line is concealed
3032
let buf = RunVimInTerminal('-S XTest_conceal', {})
3133
call VerifyScreenDump(buf, 'Test_conceal_two_windows_01', {})
@@ -113,14 +115,16 @@ endfunc
113115
func Test_conceal_with_cursorline()
114116
" Opens a help window, where 'conceal' is set, switches to the other window
115117
" where 'cursorline' needs to be updated when the cursor moves.
116-
call writefile([
117-
\ 'set cursorline',
118-
\ 'normal othis is a test',
119-
\ 'new',
120-
\ 'call setline(1, ["one", "two", "three", "four", "five"])',
121-
\ 'set ft=help',
122-
\ 'normal M',
123-
\ ], 'XTest_conceal_cul')
118+
let code =<< trim [CODE]
119+
set cursorline
120+
normal othis is a test
121+
new
122+
call setline(1, ["one", "two", "three", "four", "five"])
123+
set ft=help
124+
normal M
125+
[CODE]
126+
127+
call writefile(code, 'XTest_conceal_cul')
124128
let buf = RunVimInTerminal('-S XTest_conceal_cul', {})
125129
call VerifyScreenDump(buf, 'Test_conceal_cul_01', {})
126130

0 commit comments

Comments
 (0)