1" Test :hardcopy 2 3source check.vim 4 5func 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 \ 'header:0,syntax:a,number:y,wrap:y', 14 \ 'duplex:short,collate:n,jobsplit:y,portrait:n', 15 \ 'duplex:long,collate:y,jobsplit:n,portrait:y', 16 \ 'duplex:off,collate:y,jobsplit:y,portrait:y', 17 \ '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') 35 1,50hardcopy > Xhardcopy_printoptions 36 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 42 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:') 46 set printoptions& 47 bwipe 48endfunc 49 50func Test_printmbfont() 51 " Print a help page which contains tabs, underlines (etc) to recover more code. 52 help syntax.txt 53 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 66 set printmbfont& 67 bwipe 68endfunc 69 70func Test_printmbcharset() 71 CheckFeature postscript 72 73 " digraph.txt has plenty of non-latin1 characters. 74 help digraph.txt 75 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 86 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 101func Test_printexpr() 102 CheckFeature postscript 103 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 120 " Function returns 1 to test print failure. 121 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 128 set printexpr& 129 bwipe 130endfunc 131 132func Test_errors() 133 CheckFeature postscript 134 135 edit test_hardcopy.vim 136 call assert_fails('hardcopy >', 'E324:') 137 bwipe 138endfunc 139 140func Test_dark_background() 141 edit test_hardcopy.vim 142 syn on 143 144 for bg in ['dark', 'light'] 145 exe 'set background=' .. bg 146 147 if has('postscript') 148 hardcopy > Xhardcopy_dark_background 149 let lines = readfile('Xhardcopy_dark_background') 150 call assert_true(len(lines) > 20) 151 call assert_true(lines[0] =~ 'PS-Adobe') 152 call delete('Xhardcopy_dark_background') 153 endif 154 endfor 155 156 set background& 157 bwipe 158endfun 159 160func Test_empty_buffer() 161 CheckFeature postscript 162 163 new 164 call assert_equal("\nNo text to be printed", execute('hardcopy')) 165 bwipe 166endfunc 167 168func Test_printheader_parsing() 169 " Only test that this doesn't throw an error. 170 set printheader=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P 171 set printheader=%<%f%h%m%r%=%b\ 0x%B\ \ %l,%c%V\ %P 172 set printheader=%<%f%=\ [%1*%M%*%n%R%H]\ %-19(%3l,%02c%03V%)%O'%02b' 173 set printheader=...%r%{VarExists('b:gzflag','\ [GZ]')}%h... 174 set printheader= 175 set printheader& 176endfunc 177 178func Test_fname_with_spaces() 179 CheckFeature postscript 180 181 split t\ e\ s\ t.txt 182 call setline(1, ['just', 'some', 'text']) 183 hardcopy > %.ps 184 call assert_true(filereadable('t e s t.txt.ps')) 185 call delete('t e s t.txt.ps') 186 bwipe! 187endfunc 188 189func Test_illegal_byte() 190 CheckFeature postscript 191 if &enc != 'utf-8' 192 return 193 endif 194 195 new 196 " conversion of 0xff will fail, this used to cause a crash 197 call setline(1, "\xff") 198 hardcopy >Xpstest 199 200 bwipe! 201 call delete('Xpstest') 202endfunc 203 204" vim: shiftwidth=2 sts=2 expandtab 205