blob: 33ef4bff1bfb11cf813b3c75515d05b8cea9ba62 [file] [log] [blame]
Bram Moolenaarb5690792016-01-14 22:10:41 +01001" Test :hardcopy
2
Bram Moolenaar2e096342020-03-09 12:13:27 +01003func Test_printoptions()
4 edit test_hardcopy.vim
5 syn on
6
7 for opt in ['left:5in,right:10pt,top:8mm,bottom:2pc',
8 \ 'left:2in,top:30pt,right:16mm,bottom:3pc',
9 \ 'header:3,syntax:y,number:y,wrap:n',
10 \ 'header:3,syntax:n,number:y,wrap:y',
Bram Moolenaaredc10b52021-01-01 21:34:37 +010011 \ 'header:0,syntax:a,number:y,wrap:y',
Bram Moolenaar2e096342020-03-09 12:13:27 +010012 \ 'duplex:short,collate:n,jobsplit:y,portrait:n',
13 \ 'duplex:long,collate:y,jobsplit:n,portrait:y',
Bram Moolenaaredc10b52021-01-01 21:34:37 +010014 \ 'duplex:off,collate:y,jobsplit:y,portrait:y',
Bram Moolenaar2e096342020-03-09 12:13:27 +010015 \ 'paper:10x14',
16 \ 'paper:A3',
17 \ 'paper:A4',
18 \ 'paper:A5',
19 \ 'paper:B4',
20 \ 'paper:B5',
21 \ 'paper:executive',
22 \ 'paper:folio',
23 \ 'paper:ledger',
24 \ 'paper:legal',
25 \ 'paper:letter',
26 \ 'paper:quarto',
27 \ 'paper:statement',
28 \ 'paper:tabloid',
29 \ 'formfeed:y',
30 \ '']
31 exe 'set printoptions=' .. opt
32 if has('postscript')
Bram Moolenaar833805a2020-03-15 18:27:43 +010033 1,50hardcopy > Xhardcopy_printoptions
Bram Moolenaar2e096342020-03-09 12:13:27 +010034 let lines = readfile('Xhardcopy_printoptions')
35 call assert_true(len(lines) > 20, opt)
36 call assert_true(lines[0] =~ 'PS-Adobe', opt)
37 call delete('Xhardcopy_printoptions')
38 endif
39 endfor
Bram Moolenaar4afc7c52016-04-03 14:56:52 +020040
41 call assert_fails('set printoptions=paper', 'E550:')
42 call assert_fails('set printoptions=shredder:on', 'E551:')
43 call assert_fails('set printoptions=left:no', 'E552:')
Bram Moolenaar2e096342020-03-09 12:13:27 +010044 set printoptions&
45 bwipe
Bram Moolenaarb5690792016-01-14 22:10:41 +010046endfunc
47
Bram Moolenaar2e096342020-03-09 12:13:27 +010048func Test_printmbfont()
Bram Moolenaaredc10b52021-01-01 21:34:37 +010049 " Print a help page which contains tabs, underlines (etc) to recover more code.
50 help syntax.txt
Bram Moolenaar2e096342020-03-09 12:13:27 +010051 syn on
52
53 for opt in [':WadaMin-Regular,b:WadaMin-Bold,i:WadaMin-Italic,o:WadaMin-Bold-Italic,c:yes,a:no',
54 \ '']
55 exe 'set printmbfont=' .. opt
56 if has('postscript')
57 hardcopy > Xhardcopy_printmbfont
58 let lines = readfile('Xhardcopy_printmbfont')
59 call assert_true(len(lines) > 20, opt)
60 call assert_true(lines[0] =~ 'PS-Adobe', opt)
61 call delete('Xhardcopy_printmbfont')
62 endif
63 endfor
Bram Moolenaarb5690792016-01-14 22:10:41 +010064 set printmbfont&
Bram Moolenaar2e096342020-03-09 12:13:27 +010065 bwipe
66endfunc
67
Bram Moolenaar833805a2020-03-15 18:27:43 +010068func Test_printmbcharset()
69 CheckFeature postscript
70
71 " digraph.txt has plenty of non-latin1 characters.
72 help digraph.txt
Bram Moolenaaredc10b52021-01-01 21:34:37 +010073 set printmbcharset=ISO10646 printencoding=utf-8
74 for courier in ['yes', 'no']
75 for ascii in ['yes', 'no']
76 exe 'set printmbfont=r:WadaMin-Regular,b:WadaMin-Bold,i:WadaMin-Italic,o:WadaMin-BoldItalic'
77 \ .. ',c:' .. courier .. ',a:' .. ascii
78 hardcopy > Xhardcopy_printmbcharset
79 let lines = readfile('Xhardcopy_printmbcharset')
80 call assert_true(len(lines) > 20)
81 call assert_true(lines[0] =~ 'PS-Adobe')
82 endfor
83 endfor
Bram Moolenaar833805a2020-03-15 18:27:43 +010084
85 set printmbcharset=does-not-exist printencoding=utf-8 printmbfont=r:WadaMin-Regular
86 call assert_fails('hardcopy > Xhardcopy_printmbcharset', 'E456:')
87
88 set printmbcharset=GB_2312-80 printencoding=utf-8 printmbfont=r:WadaMin-Regular
89 call assert_fails('hardcopy > Xhardcopy_printmbcharset', 'E673:')
90
91 set printmbcharset=ISO10646 printencoding=utf-8 printmbfont=
92 call assert_fails('hardcopy > Xhardcopy_printmbcharset', 'E675:')
93
94 call delete('Xhardcopy_printmbcharset')
95 set printmbcharset& printencoding& printmbfont&
96 bwipe
97endfunc
98
Bram Moolenaar2e096342020-03-09 12:13:27 +010099func Test_printexpr()
Bram Moolenaar833805a2020-03-15 18:27:43 +0100100 CheckFeature postscript
Bram Moolenaar2e096342020-03-09 12:13:27 +0100101
102 " Not a very useful printexpr value, but enough to test
103 " hardcopy with 'printexpr'.
104 function PrintFile(fname)
105 call writefile(['Test printexpr: ' .. v:cmdarg],
106 \ 'Xhardcopy_printexpr')
107 call delete(a:fname)
108 return 0
109 endfunc
110 set printexpr=PrintFile(v:fname_in)
111
112 help help
113 hardcopy dummy args
114 call assert_equal(['Test printexpr: dummy args'],
115 \ readfile('Xhardcopy_printexpr'))
116 call delete('Xhardcopy_printexpr')
117
Bram Moolenaar833805a2020-03-15 18:27:43 +0100118 " Function returns 1 to test print failure.
Bram Moolenaar2e096342020-03-09 12:13:27 +0100119 function PrintFails(fname)
120 call delete(a:fname)
121 return 1
122 endfunc
123 set printexpr=PrintFails(v:fname_in)
124 call assert_fails('hardcopy', 'E365:')
125
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +0000126 " Using a script-local function
127 func s:NewPrintExpr()
128 endfunc
129 set printexpr=s:NewPrintExpr()
130 call assert_equal(expand('<SID>') .. 'NewPrintExpr()', &printexpr)
131 set printexpr=<SID>NewPrintExpr()
132 call assert_equal(expand('<SID>') .. 'NewPrintExpr()', &printexpr)
133
Bram Moolenaar2e096342020-03-09 12:13:27 +0100134 set printexpr&
135 bwipe
136endfunc
137
138func Test_errors()
Bram Moolenaar833805a2020-03-15 18:27:43 +0100139 CheckFeature postscript
140
141 edit test_hardcopy.vim
142 call assert_fails('hardcopy >', 'E324:')
143 bwipe
Bram Moolenaar2e096342020-03-09 12:13:27 +0100144endfunc
145
146func Test_dark_background()
147 edit test_hardcopy.vim
148 syn on
149
150 for bg in ['dark', 'light']
151 exe 'set background=' .. bg
152
153 if has('postscript')
154 hardcopy > Xhardcopy_dark_background
155 let lines = readfile('Xhardcopy_dark_background')
156 call assert_true(len(lines) > 20)
157 call assert_true(lines[0] =~ 'PS-Adobe')
158 call delete('Xhardcopy_dark_background')
159 endif
160 endfor
161
162 set background&
163 bwipe
164endfun
165
166func Test_empty_buffer()
Bram Moolenaar833805a2020-03-15 18:27:43 +0100167 CheckFeature postscript
168
169 new
170 call assert_equal("\nNo text to be printed", execute('hardcopy'))
171 bwipe
Bram Moolenaarb5690792016-01-14 22:10:41 +0100172endfunc
173
174func Test_printheader_parsing()
175 " Only test that this doesn't throw an error.
176 set printheader=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P
177 set printheader=%<%f%h%m%r%=%b\ 0x%B\ \ %l,%c%V\ %P
178 set printheader=%<%f%=\ [%1*%M%*%n%R%H]\ %-19(%3l,%02c%03V%)%O'%02b'
179 set printheader=...%r%{VarExists('b:gzflag','\ [GZ]')}%h...
180 set printheader=
181 set printheader&
182endfunc
183
Bram Moolenaarbf15b8d2017-06-04 20:43:48 +0200184func Test_fname_with_spaces()
Bram Moolenaar833805a2020-03-15 18:27:43 +0100185 CheckFeature postscript
186
Bram Moolenaar43dee182018-06-16 14:44:11 +0200187 split t\ e\ s\ t.txt
188 call setline(1, ['just', 'some', 'text'])
189 hardcopy > %.ps
190 call assert_true(filereadable('t e s t.txt.ps'))
191 call delete('t e s t.txt.ps')
192 bwipe!
Bram Moolenaarbf15b8d2017-06-04 20:43:48 +0200193endfunc
Bram Moolenaar43dee182018-06-16 14:44:11 +0200194
195func Test_illegal_byte()
Bram Moolenaar833805a2020-03-15 18:27:43 +0100196 CheckFeature postscript
197 if &enc != 'utf-8'
Bram Moolenaar43dee182018-06-16 14:44:11 +0200198 return
199 endif
Bram Moolenaar833805a2020-03-15 18:27:43 +0100200
Bram Moolenaar43dee182018-06-16 14:44:11 +0200201 new
202 " conversion of 0xff will fail, this used to cause a crash
203 call setline(1, "\xff")
204 hardcopy >Xpstest
205
206 bwipe!
207 call delete('Xpstest')
208endfunc
Bram Moolenaar833805a2020-03-15 18:27:43 +0100209
Christian Brabandtee9bc682024-12-06 17:19:25 +0100210func Test_printoptions_portrait()
211 CheckFeature postscript
212 edit test_hardcopy.vim
213 syn on
214
215 set printoptions=portrait:y
216 1,50hardcopy > Xhardcopy_printoptions_portrait
217 let lines = readfile('Xhardcopy_printoptions_portrait')
218 call assert_match('Orientation: Portrait', lines[6])
219 call assert_match('BoundingBox: 59 49 564 800', lines[9])
220 call assert_match('DocumentMedia: A4', lines[10])
221 call assert_match('PageMedia: A4', lines[24])
222 call delete('Xhardcopy_printoptions')
223
224 set printoptions=portrait:n
225 1,50hardcopy > Xhardcopy_printoptions_portrait
226 let lines = readfile('Xhardcopy_printoptions_portrait')
227 call assert_match('Orientation: Landscape', lines[6])
228 call assert_match('BoundingBox: 59 42 590 756', lines[9])
229 call assert_match('DocumentMedia: A4', lines[10])
230 call assert_match('PageMedia: A4', lines[24])
231 call delete('Xhardcopy_printoptions')
232
233 set printoptions&
234 bwipe
235endfunc
236
Bram Moolenaar833805a2020-03-15 18:27:43 +0100237" vim: shiftwidth=2 sts=2 expandtab