Bram Moolenaar | b569079 | 2016-01-14 22:10:41 +0100 | [diff] [blame] | 1 | " Test :hardcopy |
| 2 | |
Bram Moolenaar | 2e09634 | 2020-03-09 12:13:27 +0100 | [diff] [blame] | 3 | func 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 Moolenaar | edc10b5 | 2021-01-01 21:34:37 +0100 | [diff] [blame] | 11 | \ 'header:0,syntax:a,number:y,wrap:y', |
Bram Moolenaar | 2e09634 | 2020-03-09 12:13:27 +0100 | [diff] [blame] | 12 | \ 'duplex:short,collate:n,jobsplit:y,portrait:n', |
| 13 | \ 'duplex:long,collate:y,jobsplit:n,portrait:y', |
Bram Moolenaar | edc10b5 | 2021-01-01 21:34:37 +0100 | [diff] [blame] | 14 | \ 'duplex:off,collate:y,jobsplit:y,portrait:y', |
Bram Moolenaar | 2e09634 | 2020-03-09 12:13:27 +0100 | [diff] [blame] | 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 Moolenaar | 833805a | 2020-03-15 18:27:43 +0100 | [diff] [blame] | 33 | 1,50hardcopy > Xhardcopy_printoptions |
Bram Moolenaar | 2e09634 | 2020-03-09 12:13:27 +0100 | [diff] [blame] | 34 | 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 Moolenaar | 4afc7c5 | 2016-04-03 14:56:52 +0200 | [diff] [blame] | 40 | |
| 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 Moolenaar | 2e09634 | 2020-03-09 12:13:27 +0100 | [diff] [blame] | 44 | set printoptions& |
| 45 | bwipe |
Bram Moolenaar | b569079 | 2016-01-14 22:10:41 +0100 | [diff] [blame] | 46 | endfunc |
| 47 | |
Bram Moolenaar | 2e09634 | 2020-03-09 12:13:27 +0100 | [diff] [blame] | 48 | func Test_printmbfont() |
Bram Moolenaar | edc10b5 | 2021-01-01 21:34:37 +0100 | [diff] [blame] | 49 | " Print a help page which contains tabs, underlines (etc) to recover more code. |
| 50 | help syntax.txt |
Bram Moolenaar | 2e09634 | 2020-03-09 12:13:27 +0100 | [diff] [blame] | 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 Moolenaar | b569079 | 2016-01-14 22:10:41 +0100 | [diff] [blame] | 64 | set printmbfont& |
Bram Moolenaar | 2e09634 | 2020-03-09 12:13:27 +0100 | [diff] [blame] | 65 | bwipe |
| 66 | endfunc |
| 67 | |
Bram Moolenaar | 833805a | 2020-03-15 18:27:43 +0100 | [diff] [blame] | 68 | func Test_printmbcharset() |
| 69 | CheckFeature postscript |
| 70 | |
| 71 | " digraph.txt has plenty of non-latin1 characters. |
| 72 | help digraph.txt |
Bram Moolenaar | edc10b5 | 2021-01-01 21:34:37 +0100 | [diff] [blame] | 73 | 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 Moolenaar | 833805a | 2020-03-15 18:27:43 +0100 | [diff] [blame] | 84 | |
| 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 |
| 97 | endfunc |
| 98 | |
Bram Moolenaar | 2e09634 | 2020-03-09 12:13:27 +0100 | [diff] [blame] | 99 | func Test_printexpr() |
Bram Moolenaar | 833805a | 2020-03-15 18:27:43 +0100 | [diff] [blame] | 100 | CheckFeature postscript |
Bram Moolenaar | 2e09634 | 2020-03-09 12:13:27 +0100 | [diff] [blame] | 101 | |
| 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 Moolenaar | 833805a | 2020-03-15 18:27:43 +0100 | [diff] [blame] | 118 | " Function returns 1 to test print failure. |
Bram Moolenaar | 2e09634 | 2020-03-09 12:13:27 +0100 | [diff] [blame] | 119 | 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 Lakshmanan | 8bb65f2 | 2021-12-26 10:51:39 +0000 | [diff] [blame] | 126 | " 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 Moolenaar | 2e09634 | 2020-03-09 12:13:27 +0100 | [diff] [blame] | 134 | set printexpr& |
| 135 | bwipe |
| 136 | endfunc |
| 137 | |
| 138 | func Test_errors() |
Bram Moolenaar | 833805a | 2020-03-15 18:27:43 +0100 | [diff] [blame] | 139 | CheckFeature postscript |
| 140 | |
| 141 | edit test_hardcopy.vim |
| 142 | call assert_fails('hardcopy >', 'E324:') |
| 143 | bwipe |
Bram Moolenaar | 2e09634 | 2020-03-09 12:13:27 +0100 | [diff] [blame] | 144 | endfunc |
| 145 | |
| 146 | func 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 |
| 164 | endfun |
| 165 | |
| 166 | func Test_empty_buffer() |
Bram Moolenaar | 833805a | 2020-03-15 18:27:43 +0100 | [diff] [blame] | 167 | CheckFeature postscript |
| 168 | |
| 169 | new |
| 170 | call assert_equal("\nNo text to be printed", execute('hardcopy')) |
| 171 | bwipe |
Bram Moolenaar | b569079 | 2016-01-14 22:10:41 +0100 | [diff] [blame] | 172 | endfunc |
| 173 | |
| 174 | func 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& |
| 182 | endfunc |
| 183 | |
Bram Moolenaar | bf15b8d | 2017-06-04 20:43:48 +0200 | [diff] [blame] | 184 | func Test_fname_with_spaces() |
Bram Moolenaar | 833805a | 2020-03-15 18:27:43 +0100 | [diff] [blame] | 185 | CheckFeature postscript |
| 186 | |
Bram Moolenaar | 43dee18 | 2018-06-16 14:44:11 +0200 | [diff] [blame] | 187 | 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 Moolenaar | bf15b8d | 2017-06-04 20:43:48 +0200 | [diff] [blame] | 193 | endfunc |
Bram Moolenaar | 43dee18 | 2018-06-16 14:44:11 +0200 | [diff] [blame] | 194 | |
| 195 | func Test_illegal_byte() |
Bram Moolenaar | 833805a | 2020-03-15 18:27:43 +0100 | [diff] [blame] | 196 | CheckFeature postscript |
| 197 | if &enc != 'utf-8' |
Bram Moolenaar | 43dee18 | 2018-06-16 14:44:11 +0200 | [diff] [blame] | 198 | return |
| 199 | endif |
Bram Moolenaar | 833805a | 2020-03-15 18:27:43 +0100 | [diff] [blame] | 200 | |
Bram Moolenaar | 43dee18 | 2018-06-16 14:44:11 +0200 | [diff] [blame] | 201 | 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') |
| 208 | endfunc |
Bram Moolenaar | 833805a | 2020-03-15 18:27:43 +0100 | [diff] [blame] | 209 | |
Christian Brabandt | ee9bc68 | 2024-12-06 17:19:25 +0100 | [diff] [blame] | 210 | func 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 |
| 235 | endfunc |
| 236 | |
Bram Moolenaar | 833805a | 2020-03-15 18:27:43 +0100 | [diff] [blame] | 237 | " vim: shiftwidth=2 sts=2 expandtab |