blob: e390bd5cc8e4e2304ff6c57eecbf8cbc0a7577e2 [file] [log] [blame]
Bram Moolenaarb5690792016-01-14 22:10:41 +01001" Test :hardcopy
2
Bram Moolenaar833805a2020-03-15 18:27:43 +01003source check.vim
4
Bram Moolenaar2e096342020-03-09 12:13:27 +01005func Test_printoptions()
6 edit test_hardcopy.vim
7 syn on
8
9 for opt in ['left:5in,right:10pt,top:8mm,bottom:2pc',
10 \ 'left:2in,top:30pt,right:16mm,bottom:3pc',
11 \ 'header:3,syntax:y,number:y,wrap:n',
12 \ 'header:3,syntax:n,number:y,wrap:y',
Bram Moolenaaredc10b52021-01-01 21:34:37 +010013 \ 'header:0,syntax:a,number:y,wrap:y',
Bram Moolenaar2e096342020-03-09 12:13:27 +010014 \ 'duplex:short,collate:n,jobsplit:y,portrait:n',
15 \ 'duplex:long,collate:y,jobsplit:n,portrait:y',
Bram Moolenaaredc10b52021-01-01 21:34:37 +010016 \ 'duplex:off,collate:y,jobsplit:y,portrait:y',
Bram Moolenaar2e096342020-03-09 12:13:27 +010017 \ 'paper:10x14',
18 \ 'paper:A3',
19 \ 'paper:A4',
20 \ 'paper:A5',
21 \ 'paper:B4',
22 \ 'paper:B5',
23 \ 'paper:executive',
24 \ 'paper:folio',
25 \ 'paper:ledger',
26 \ 'paper:legal',
27 \ 'paper:letter',
28 \ 'paper:quarto',
29 \ 'paper:statement',
30 \ 'paper:tabloid',
31 \ 'formfeed:y',
32 \ '']
33 exe 'set printoptions=' .. opt
34 if has('postscript')
Bram Moolenaar833805a2020-03-15 18:27:43 +010035 1,50hardcopy > Xhardcopy_printoptions
Bram Moolenaar2e096342020-03-09 12:13:27 +010036 let lines = readfile('Xhardcopy_printoptions')
37 call assert_true(len(lines) > 20, opt)
38 call assert_true(lines[0] =~ 'PS-Adobe', opt)
39 call delete('Xhardcopy_printoptions')
40 endif
41 endfor
Bram Moolenaar4afc7c52016-04-03 14:56:52 +020042
43 call assert_fails('set printoptions=paper', 'E550:')
44 call assert_fails('set printoptions=shredder:on', 'E551:')
45 call assert_fails('set printoptions=left:no', 'E552:')
Bram Moolenaar2e096342020-03-09 12:13:27 +010046 set printoptions&
47 bwipe
Bram Moolenaarb5690792016-01-14 22:10:41 +010048endfunc
49
Bram Moolenaar2e096342020-03-09 12:13:27 +010050func Test_printmbfont()
Bram Moolenaaredc10b52021-01-01 21:34:37 +010051 " Print a help page which contains tabs, underlines (etc) to recover more code.
52 help syntax.txt
Bram Moolenaar2e096342020-03-09 12:13:27 +010053 syn on
54
55 for opt in [':WadaMin-Regular,b:WadaMin-Bold,i:WadaMin-Italic,o:WadaMin-Bold-Italic,c:yes,a:no',
56 \ '']
57 exe 'set printmbfont=' .. opt
58 if has('postscript')
59 hardcopy > Xhardcopy_printmbfont
60 let lines = readfile('Xhardcopy_printmbfont')
61 call assert_true(len(lines) > 20, opt)
62 call assert_true(lines[0] =~ 'PS-Adobe', opt)
63 call delete('Xhardcopy_printmbfont')
64 endif
65 endfor
Bram Moolenaarb5690792016-01-14 22:10:41 +010066 set printmbfont&
Bram Moolenaar2e096342020-03-09 12:13:27 +010067 bwipe
68endfunc
69
Bram Moolenaar833805a2020-03-15 18:27:43 +010070func Test_printmbcharset()
71 CheckFeature postscript
72
73 " digraph.txt has plenty of non-latin1 characters.
74 help digraph.txt
Bram Moolenaaredc10b52021-01-01 21:34:37 +010075 set printmbcharset=ISO10646 printencoding=utf-8
76 for courier in ['yes', 'no']
77 for ascii in ['yes', 'no']
78 exe 'set printmbfont=r:WadaMin-Regular,b:WadaMin-Bold,i:WadaMin-Italic,o:WadaMin-BoldItalic'
79 \ .. ',c:' .. courier .. ',a:' .. ascii
80 hardcopy > Xhardcopy_printmbcharset
81 let lines = readfile('Xhardcopy_printmbcharset')
82 call assert_true(len(lines) > 20)
83 call assert_true(lines[0] =~ 'PS-Adobe')
84 endfor
85 endfor
Bram Moolenaar833805a2020-03-15 18:27:43 +010086
87 set printmbcharset=does-not-exist printencoding=utf-8 printmbfont=r:WadaMin-Regular
88 call assert_fails('hardcopy > Xhardcopy_printmbcharset', 'E456:')
89
90 set printmbcharset=GB_2312-80 printencoding=utf-8 printmbfont=r:WadaMin-Regular
91 call assert_fails('hardcopy > Xhardcopy_printmbcharset', 'E673:')
92
93 set printmbcharset=ISO10646 printencoding=utf-8 printmbfont=
94 call assert_fails('hardcopy > Xhardcopy_printmbcharset', 'E675:')
95
96 call delete('Xhardcopy_printmbcharset')
97 set printmbcharset& printencoding& printmbfont&
98 bwipe
99endfunc
100
Bram Moolenaar2e096342020-03-09 12:13:27 +0100101func Test_printexpr()
Bram Moolenaar833805a2020-03-15 18:27:43 +0100102 CheckFeature postscript
Bram Moolenaar2e096342020-03-09 12:13:27 +0100103
104 " Not a very useful printexpr value, but enough to test
105 " hardcopy with 'printexpr'.
106 function PrintFile(fname)
107 call writefile(['Test printexpr: ' .. v:cmdarg],
108 \ 'Xhardcopy_printexpr')
109 call delete(a:fname)
110 return 0
111 endfunc
112 set printexpr=PrintFile(v:fname_in)
113
114 help help
115 hardcopy dummy args
116 call assert_equal(['Test printexpr: dummy args'],
117 \ readfile('Xhardcopy_printexpr'))
118 call delete('Xhardcopy_printexpr')
119
Bram Moolenaar833805a2020-03-15 18:27:43 +0100120 " Function returns 1 to test print failure.
Bram Moolenaar2e096342020-03-09 12:13:27 +0100121 function PrintFails(fname)
122 call delete(a:fname)
123 return 1
124 endfunc
125 set printexpr=PrintFails(v:fname_in)
126 call assert_fails('hardcopy', 'E365:')
127
128 set printexpr&
129 bwipe
130endfunc
131
132func Test_errors()
Bram Moolenaar833805a2020-03-15 18:27:43 +0100133 CheckFeature postscript
134
135 edit test_hardcopy.vim
136 call assert_fails('hardcopy >', 'E324:')
137 bwipe
Bram Moolenaar2e096342020-03-09 12:13:27 +0100138endfunc
139
140func Test_dark_background()
141 edit test_hardcopy.vim
142 syn on
143
144 for bg in ['dark', 'light']
145 exe 'set background=' .. bg
146
147 if has('postscript')
148 hardcopy > Xhardcopy_dark_background
149 let lines = readfile('Xhardcopy_dark_background')
150 call assert_true(len(lines) > 20)
151 call assert_true(lines[0] =~ 'PS-Adobe')
152 call delete('Xhardcopy_dark_background')
153 endif
154 endfor
155
156 set background&
157 bwipe
158endfun
159
160func Test_empty_buffer()
Bram Moolenaar833805a2020-03-15 18:27:43 +0100161 CheckFeature postscript
162
163 new
164 call assert_equal("\nNo text to be printed", execute('hardcopy'))
165 bwipe
Bram Moolenaarb5690792016-01-14 22:10:41 +0100166endfunc
167
168func Test_printheader_parsing()
169 " Only test that this doesn't throw an error.
170 set printheader=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P
171 set printheader=%<%f%h%m%r%=%b\ 0x%B\ \ %l,%c%V\ %P
172 set printheader=%<%f%=\ [%1*%M%*%n%R%H]\ %-19(%3l,%02c%03V%)%O'%02b'
173 set printheader=...%r%{VarExists('b:gzflag','\ [GZ]')}%h...
174 set printheader=
175 set printheader&
176endfunc
177
Bram Moolenaarbf15b8d2017-06-04 20:43:48 +0200178func Test_fname_with_spaces()
Bram Moolenaar833805a2020-03-15 18:27:43 +0100179 CheckFeature postscript
180
Bram Moolenaar43dee182018-06-16 14:44:11 +0200181 split t\ e\ s\ t.txt
182 call setline(1, ['just', 'some', 'text'])
183 hardcopy > %.ps
184 call assert_true(filereadable('t e s t.txt.ps'))
185 call delete('t e s t.txt.ps')
186 bwipe!
Bram Moolenaarbf15b8d2017-06-04 20:43:48 +0200187endfunc
Bram Moolenaar43dee182018-06-16 14:44:11 +0200188
189func Test_illegal_byte()
Bram Moolenaar833805a2020-03-15 18:27:43 +0100190 CheckFeature postscript
191 if &enc != 'utf-8'
Bram Moolenaar43dee182018-06-16 14:44:11 +0200192 return
193 endif
Bram Moolenaar833805a2020-03-15 18:27:43 +0100194
Bram Moolenaar43dee182018-06-16 14:44:11 +0200195 new
196 " conversion of 0xff will fail, this used to cause a crash
197 call setline(1, "\xff")
198 hardcopy >Xpstest
199
200 bwipe!
201 call delete('Xpstest')
202endfunc
Bram Moolenaar833805a2020-03-15 18:27:43 +0100203
204" vim: shiftwidth=2 sts=2 expandtab