blob: be83728b4f950c532952792d106d813de9089903 [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
Yegappan Lakshmanan8bb65f22021-12-26 10:51:39 +0000128 " Using a script-local function
129 func s:NewPrintExpr()
130 endfunc
131 set printexpr=s:NewPrintExpr()
132 call assert_equal(expand('<SID>') .. 'NewPrintExpr()', &printexpr)
133 set printexpr=<SID>NewPrintExpr()
134 call assert_equal(expand('<SID>') .. 'NewPrintExpr()', &printexpr)
135
Bram Moolenaar2e096342020-03-09 12:13:27 +0100136 set printexpr&
137 bwipe
138endfunc
139
140func Test_errors()
Bram Moolenaar833805a2020-03-15 18:27:43 +0100141 CheckFeature postscript
142
143 edit test_hardcopy.vim
144 call assert_fails('hardcopy >', 'E324:')
145 bwipe
Bram Moolenaar2e096342020-03-09 12:13:27 +0100146endfunc
147
148func Test_dark_background()
149 edit test_hardcopy.vim
150 syn on
151
152 for bg in ['dark', 'light']
153 exe 'set background=' .. bg
154
155 if has('postscript')
156 hardcopy > Xhardcopy_dark_background
157 let lines = readfile('Xhardcopy_dark_background')
158 call assert_true(len(lines) > 20)
159 call assert_true(lines[0] =~ 'PS-Adobe')
160 call delete('Xhardcopy_dark_background')
161 endif
162 endfor
163
164 set background&
165 bwipe
166endfun
167
168func Test_empty_buffer()
Bram Moolenaar833805a2020-03-15 18:27:43 +0100169 CheckFeature postscript
170
171 new
172 call assert_equal("\nNo text to be printed", execute('hardcopy'))
173 bwipe
Bram Moolenaarb5690792016-01-14 22:10:41 +0100174endfunc
175
176func Test_printheader_parsing()
177 " Only test that this doesn't throw an error.
178 set printheader=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P
179 set printheader=%<%f%h%m%r%=%b\ 0x%B\ \ %l,%c%V\ %P
180 set printheader=%<%f%=\ [%1*%M%*%n%R%H]\ %-19(%3l,%02c%03V%)%O'%02b'
181 set printheader=...%r%{VarExists('b:gzflag','\ [GZ]')}%h...
182 set printheader=
183 set printheader&
184endfunc
185
Bram Moolenaarbf15b8d2017-06-04 20:43:48 +0200186func Test_fname_with_spaces()
Bram Moolenaar833805a2020-03-15 18:27:43 +0100187 CheckFeature postscript
188
Bram Moolenaar43dee182018-06-16 14:44:11 +0200189 split t\ e\ s\ t.txt
190 call setline(1, ['just', 'some', 'text'])
191 hardcopy > %.ps
192 call assert_true(filereadable('t e s t.txt.ps'))
193 call delete('t e s t.txt.ps')
194 bwipe!
Bram Moolenaarbf15b8d2017-06-04 20:43:48 +0200195endfunc
Bram Moolenaar43dee182018-06-16 14:44:11 +0200196
197func Test_illegal_byte()
Bram Moolenaar833805a2020-03-15 18:27:43 +0100198 CheckFeature postscript
199 if &enc != 'utf-8'
Bram Moolenaar43dee182018-06-16 14:44:11 +0200200 return
201 endif
Bram Moolenaar833805a2020-03-15 18:27:43 +0100202
Bram Moolenaar43dee182018-06-16 14:44:11 +0200203 new
204 " conversion of 0xff will fail, this used to cause a crash
205 call setline(1, "\xff")
206 hardcopy >Xpstest
207
208 bwipe!
209 call delete('Xpstest')
210endfunc
Bram Moolenaar833805a2020-03-15 18:27:43 +0100211
212" vim: shiftwidth=2 sts=2 expandtab