blob: 63b4d888d74905190eef013e5d6559d4cb814235 [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',
13 \ 'duplex:short,collate:n,jobsplit:y,portrait:n',
14 \ 'duplex:long,collate:y,jobsplit:n,portrait:y',
15 \ '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()
49 " Print a small help page which contains tabs to cover code that expands tabs to spaces.
50 help help
51 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
73 set printmbcharset=ISO10646 printencoding=utf-8 printmbfont=r:WadaMin-Regular
74
75 hardcopy > Xhardcopy_printmbcharset
76 let lines = readfile('Xhardcopy_printmbcharset')
77 call assert_true(len(lines) > 20)
78 call assert_true(lines[0] =~ 'PS-Adobe')
79
80 set printmbcharset=does-not-exist printencoding=utf-8 printmbfont=r:WadaMin-Regular
81 call assert_fails('hardcopy > Xhardcopy_printmbcharset', 'E456:')
82
83 set printmbcharset=GB_2312-80 printencoding=utf-8 printmbfont=r:WadaMin-Regular
84 call assert_fails('hardcopy > Xhardcopy_printmbcharset', 'E673:')
85
86 set printmbcharset=ISO10646 printencoding=utf-8 printmbfont=
87 call assert_fails('hardcopy > Xhardcopy_printmbcharset', 'E675:')
88
89 call delete('Xhardcopy_printmbcharset')
90 set printmbcharset& printencoding& printmbfont&
91 bwipe
92endfunc
93
Bram Moolenaar2e096342020-03-09 12:13:27 +010094func Test_printexpr()
Bram Moolenaar833805a2020-03-15 18:27:43 +010095 CheckFeature postscript
Bram Moolenaar2e096342020-03-09 12:13:27 +010096
97 " Not a very useful printexpr value, but enough to test
98 " hardcopy with 'printexpr'.
99 function PrintFile(fname)
100 call writefile(['Test printexpr: ' .. v:cmdarg],
101 \ 'Xhardcopy_printexpr')
102 call delete(a:fname)
103 return 0
104 endfunc
105 set printexpr=PrintFile(v:fname_in)
106
107 help help
108 hardcopy dummy args
109 call assert_equal(['Test printexpr: dummy args'],
110 \ readfile('Xhardcopy_printexpr'))
111 call delete('Xhardcopy_printexpr')
112
Bram Moolenaar833805a2020-03-15 18:27:43 +0100113 " Function returns 1 to test print failure.
Bram Moolenaar2e096342020-03-09 12:13:27 +0100114 function PrintFails(fname)
115 call delete(a:fname)
116 return 1
117 endfunc
118 set printexpr=PrintFails(v:fname_in)
119 call assert_fails('hardcopy', 'E365:')
120
121 set printexpr&
122 bwipe
123endfunc
124
125func Test_errors()
Bram Moolenaar833805a2020-03-15 18:27:43 +0100126 CheckFeature postscript
127
128 edit test_hardcopy.vim
129 call assert_fails('hardcopy >', 'E324:')
130 bwipe
Bram Moolenaar2e096342020-03-09 12:13:27 +0100131endfunc
132
133func Test_dark_background()
134 edit test_hardcopy.vim
135 syn on
136
137 for bg in ['dark', 'light']
138 exe 'set background=' .. bg
139
140 if has('postscript')
141 hardcopy > Xhardcopy_dark_background
142 let lines = readfile('Xhardcopy_dark_background')
143 call assert_true(len(lines) > 20)
144 call assert_true(lines[0] =~ 'PS-Adobe')
145 call delete('Xhardcopy_dark_background')
146 endif
147 endfor
148
149 set background&
150 bwipe
151endfun
152
153func Test_empty_buffer()
Bram Moolenaar833805a2020-03-15 18:27:43 +0100154 CheckFeature postscript
155
156 new
157 call assert_equal("\nNo text to be printed", execute('hardcopy'))
158 bwipe
Bram Moolenaarb5690792016-01-14 22:10:41 +0100159endfunc
160
161func Test_printheader_parsing()
162 " Only test that this doesn't throw an error.
163 set printheader=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P
164 set printheader=%<%f%h%m%r%=%b\ 0x%B\ \ %l,%c%V\ %P
165 set printheader=%<%f%=\ [%1*%M%*%n%R%H]\ %-19(%3l,%02c%03V%)%O'%02b'
166 set printheader=...%r%{VarExists('b:gzflag','\ [GZ]')}%h...
167 set printheader=
168 set printheader&
169endfunc
170
Bram Moolenaarbf15b8d2017-06-04 20:43:48 +0200171func Test_fname_with_spaces()
Bram Moolenaar833805a2020-03-15 18:27:43 +0100172 CheckFeature postscript
173
Bram Moolenaar43dee182018-06-16 14:44:11 +0200174 split t\ e\ s\ t.txt
175 call setline(1, ['just', 'some', 'text'])
176 hardcopy > %.ps
177 call assert_true(filereadable('t e s t.txt.ps'))
178 call delete('t e s t.txt.ps')
179 bwipe!
Bram Moolenaarbf15b8d2017-06-04 20:43:48 +0200180endfunc
Bram Moolenaar43dee182018-06-16 14:44:11 +0200181
182func Test_illegal_byte()
Bram Moolenaar833805a2020-03-15 18:27:43 +0100183 CheckFeature postscript
184 if &enc != 'utf-8'
Bram Moolenaar43dee182018-06-16 14:44:11 +0200185 return
186 endif
Bram Moolenaar833805a2020-03-15 18:27:43 +0100187
Bram Moolenaar43dee182018-06-16 14:44:11 +0200188 new
189 " conversion of 0xff will fail, this used to cause a crash
190 call setline(1, "\xff")
191 hardcopy >Xpstest
192
193 bwipe!
194 call delete('Xpstest')
195endfunc
Bram Moolenaar833805a2020-03-15 18:27:43 +0100196
197" vim: shiftwidth=2 sts=2 expandtab