comparison src/testdir/test_hardcopy.vim @ 19619:1eb83d461033 v8.2.0366

patch 8.2.0366: hardcopy command not tested enough Commit: https://github.com/vim/vim/commit/2e09634a7880f55a61cb6b959dd89c51972866af Author: Bram Moolenaar <Bram@vim.org> Date: Mon Mar 9 12:13:27 2020 +0100 patch 8.2.0366: hardcopy command not tested enough Problem: Hardcopy command not tested enough. Solution: Add tests for printing. (Dominique Pelle, closes https://github.com/vim/vim/issues/5748)
author Bram Moolenaar <Bram@vim.org>
date Mon, 09 Mar 2020 12:15:03 +0100
parents 873542706b0b
children f43c0e669bd6
comparison
equal deleted inserted replaced
19618:4b2a45315826 19619:1eb83d461033
1 " Test :hardcopy 1 " Test :hardcopy
2 2
3 func Test_printoptions_parsing() 3 func Test_printoptions()
4 " Only test that this doesn't throw an error. 4 edit test_hardcopy.vim
5 set printoptions=left:5in,right:10pt,top:8mm,bottom:2pc 5 syn on
6 set printoptions=left:2in,top:30pt,right:16mm,bottom:3pc 6
7 set printoptions=header:3,syntax:y,number:7,wrap:n 7 for opt in ['left:5in,right:10pt,top:8mm,bottom:2pc',
8 set printoptions=duplex:short,collate:n,jobsplit:y,portrait:n 8 \ 'left:2in,top:30pt,right:16mm,bottom:3pc',
9 set printoptions=paper:10x14 9 \ 'header:3,syntax:y,number:y,wrap:n',
10 set printoptions=paper:A3 10 \ 'header:3,syntax:n,number:y,wrap:y',
11 set printoptions=paper:A4 11 \ 'duplex:short,collate:n,jobsplit:y,portrait:n',
12 set printoptions=paper:A5 12 \ 'duplex:long,collate:y,jobsplit:n,portrait:y',
13 set printoptions=paper:B4 13 \ 'paper:10x14',
14 set printoptions=paper:B5 14 \ 'paper:A3',
15 set printoptions=paper:executive 15 \ 'paper:A4',
16 set printoptions=paper:folio 16 \ 'paper:A5',
17 set printoptions=paper:ledger 17 \ 'paper:B4',
18 set printoptions=paper:legal 18 \ 'paper:B5',
19 set printoptions=paper:letter 19 \ 'paper:executive',
20 set printoptions=paper:quarto 20 \ 'paper:folio',
21 set printoptions=paper:statement 21 \ 'paper:ledger',
22 set printoptions=paper:tabloid 22 \ 'paper:legal',
23 set printoptions=formfeed:y 23 \ 'paper:letter',
24 set printoptions= 24 \ 'paper:quarto',
25 set printoptions& 25 \ 'paper:statement',
26 \ 'paper:tabloid',
27 \ 'formfeed:y',
28 \ '']
29 exe 'set printoptions=' .. opt
30 if has('postscript')
31 hardcopy > Xhardcopy_printoptions
32 let lines = readfile('Xhardcopy_printoptions')
33 call assert_true(len(lines) > 20, opt)
34 call assert_true(lines[0] =~ 'PS-Adobe', opt)
35 call delete('Xhardcopy_printoptions')
36 endif
37 endfor
26 38
27 call assert_fails('set printoptions=paper', 'E550:') 39 call assert_fails('set printoptions=paper', 'E550:')
28 call assert_fails('set printoptions=shredder:on', 'E551:') 40 call assert_fails('set printoptions=shredder:on', 'E551:')
29 call assert_fails('set printoptions=left:no', 'E552:') 41 call assert_fails('set printoptions=left:no', 'E552:')
42 set printoptions&
43 bwipe
30 endfunc 44 endfunc
31 45
32 func Test_printmbfont_parsing() 46 func Test_printmbfont()
33 " Only test that this doesn't throw an error. 47 " Print a small help page which contains tabs to cover code that expands tabs to spaces.
34 set printmbfont=r:WadaMin-Regular,b:WadaMin-Bold,i:WadaMin-Italic,o:WadaMin-Bold-Italic,c:yes,a:no 48 help help
35 set printmbfont= 49 syn on
50
51 for opt in [':WadaMin-Regular,b:WadaMin-Bold,i:WadaMin-Italic,o:WadaMin-Bold-Italic,c:yes,a:no',
52 \ '']
53 exe 'set printmbfont=' .. opt
54 if has('postscript')
55 hardcopy > Xhardcopy_printmbfont
56 let lines = readfile('Xhardcopy_printmbfont')
57 call assert_true(len(lines) > 20, opt)
58 call assert_true(lines[0] =~ 'PS-Adobe', opt)
59 call delete('Xhardcopy_printmbfont')
60 endif
61 endfor
36 set printmbfont& 62 set printmbfont&
63 bwipe
64 endfunc
65
66 func Test_printexpr()
67 if !has('unix')
68 return
69 endif
70
71 " Not a very useful printexpr value, but enough to test
72 " hardcopy with 'printexpr'.
73 function PrintFile(fname)
74 call writefile(['Test printexpr: ' .. v:cmdarg],
75 \ 'Xhardcopy_printexpr')
76 call delete(a:fname)
77 return 0
78 endfunc
79 set printexpr=PrintFile(v:fname_in)
80
81 help help
82 hardcopy dummy args
83 call assert_equal(['Test printexpr: dummy args'],
84 \ readfile('Xhardcopy_printexpr'))
85 call delete('Xhardcopy_printexpr')
86
87 " Function return 1 to test print failure.
88 function PrintFails(fname)
89 call delete(a:fname)
90 return 1
91 endfunc
92 set printexpr=PrintFails(v:fname_in)
93 call assert_fails('hardcopy', 'E365:')
94
95 set printexpr&
96 bwipe
97 endfunc
98
99 func Test_errors()
100 " FIXME: Windows fails differently than Unix.
101 if has('unix')
102 edit test_hardcopy.vim
103 call assert_fails('hardcopy >', 'E324:')
104 bwipe
105 endif
106 endfunc
107
108 func Test_dark_background()
109 edit test_hardcopy.vim
110 syn on
111
112 for bg in ['dark', 'light']
113 exe 'set background=' .. bg
114
115 if has('postscript')
116 hardcopy > Xhardcopy_dark_background
117 let lines = readfile('Xhardcopy_dark_background')
118 call assert_true(len(lines) > 20)
119 call assert_true(lines[0] =~ 'PS-Adobe')
120 call delete('Xhardcopy_dark_background')
121 endif
122 endfor
123
124 set background&
125 bwipe
126 endfun
127
128 func Test_empty_buffer()
129 " FIXME: Unclear why this fails on Windows.
130 if has('unix')
131 new
132 call assert_equal("\nNo text to be printed", execute('hardcopy'))
133 bwipe
134 endif
37 endfunc 135 endfunc
38 136
39 func Test_printheader_parsing() 137 func Test_printheader_parsing()
40 " Only test that this doesn't throw an error. 138 " Only test that this doesn't throw an error.
41 set printheader=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P 139 set printheader=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P
42 set printheader=%<%f%h%m%r%=%b\ 0x%B\ \ %l,%c%V\ %P 140 set printheader=%<%f%h%m%r%=%b\ 0x%B\ \ %l,%c%V\ %P
43 set printheader=%<%f%=\ [%1*%M%*%n%R%H]\ %-19(%3l,%02c%03V%)%O'%02b' 141 set printheader=%<%f%=\ [%1*%M%*%n%R%H]\ %-19(%3l,%02c%03V%)%O'%02b'
44 set printheader=...%r%{VarExists('b:gzflag','\ [GZ]')}%h... 142 set printheader=...%r%{VarExists('b:gzflag','\ [GZ]')}%h...
45 set printheader= 143 set printheader=
46 set printheader& 144 set printheader&
47 endfunc
48
49 " Test that :hardcopy produces a non-empty file.
50 " We don't check much of the contents.
51 func Test_with_syntax()
52 if has('postscript')
53 edit test_hardcopy.vim
54 set printoptions=syntax:y
55 syn on
56 hardcopy > Xhardcopy
57 let lines = readfile('Xhardcopy')
58 call assert_true(len(lines) > 20)
59 call assert_true(lines[0] =~ 'PS-Adobe')
60 call delete('Xhardcopy')
61 set printoptions&
62 endif
63 endfunc 145 endfunc
64 146
65 func Test_fname_with_spaces() 147 func Test_fname_with_spaces()
66 if !has('postscript') 148 if !has('postscript')
67 return 149 return
84 hardcopy >Xpstest 166 hardcopy >Xpstest
85 167
86 bwipe! 168 bwipe!
87 call delete('Xpstest') 169 call delete('Xpstest')
88 endfunc 170 endfunc
89