blob: 6125f9b99309dcd03a06bf0acfcd1cb354d1c8ad [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',
11 \ 'duplex:short,collate:n,jobsplit:y,portrait:n',
12 \ 'duplex:long,collate:y,jobsplit:n,portrait:y',
13 \ 'paper:10x14',
14 \ 'paper:A3',
15 \ 'paper:A4',
16 \ 'paper:A5',
17 \ 'paper:B4',
18 \ 'paper:B5',
19 \ 'paper:executive',
20 \ 'paper:folio',
21 \ 'paper:ledger',
22 \ 'paper:legal',
23 \ 'paper:letter',
24 \ 'paper:quarto',
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
Bram Moolenaar4afc7c52016-04-03 14:56:52 +020038
39 call assert_fails('set printoptions=paper', 'E550:')
40 call assert_fails('set printoptions=shredder:on', 'E551:')
41 call assert_fails('set printoptions=left:no', 'E552:')
Bram Moolenaar2e096342020-03-09 12:13:27 +010042 set printoptions&
43 bwipe
Bram Moolenaarb5690792016-01-14 22:10:41 +010044endfunc
45
Bram Moolenaar2e096342020-03-09 12:13:27 +010046func Test_printmbfont()
47 " Print a small help page which contains tabs to cover code that expands tabs to spaces.
48 help help
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
Bram Moolenaarb5690792016-01-14 22:10:41 +010062 set printmbfont&
Bram Moolenaar2e096342020-03-09 12:13:27 +010063 bwipe
64endfunc
65
66func 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
97endfunc
98
99func 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
106endfunc
107
108func 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
126endfun
127
128func 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
Bram Moolenaarb5690792016-01-14 22:10:41 +0100135endfunc
136
137func Test_printheader_parsing()
138 " Only test that this doesn't throw an error.
139 set printheader=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P
140 set printheader=%<%f%h%m%r%=%b\ 0x%B\ \ %l,%c%V\ %P
141 set printheader=%<%f%=\ [%1*%M%*%n%R%H]\ %-19(%3l,%02c%03V%)%O'%02b'
142 set printheader=...%r%{VarExists('b:gzflag','\ [GZ]')}%h...
143 set printheader=
144 set printheader&
145endfunc
146
Bram Moolenaarbf15b8d2017-06-04 20:43:48 +0200147func Test_fname_with_spaces()
Bram Moolenaar43dee182018-06-16 14:44:11 +0200148 if !has('postscript')
149 return
Bram Moolenaar763209c2017-06-04 21:40:36 +0200150 endif
Bram Moolenaar43dee182018-06-16 14:44:11 +0200151 split t\ e\ s\ t.txt
152 call setline(1, ['just', 'some', 'text'])
153 hardcopy > %.ps
154 call assert_true(filereadable('t e s t.txt.ps'))
155 call delete('t e s t.txt.ps')
156 bwipe!
Bram Moolenaarbf15b8d2017-06-04 20:43:48 +0200157endfunc
Bram Moolenaar43dee182018-06-16 14:44:11 +0200158
159func Test_illegal_byte()
160 if !has('postscript') || &enc != 'utf-8'
161 return
162 endif
163 new
164 " conversion of 0xff will fail, this used to cause a crash
165 call setline(1, "\xff")
166 hardcopy >Xpstest
167
168 bwipe!
169 call delete('Xpstest')
170endfunc