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 \ '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') 33 1,50hardcopy > Xhardcopy_printoptions 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 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:') 44 set printoptions& 45 bwipe 46endfunc 47 48func 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 64 set printmbfont& 65 bwipe 66endfunc 67 68func 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 94func Test_printexpr() 95 CheckFeature postscript 96 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 113 " Function returns 1 to test print failure. 114 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() 126 CheckFeature postscript 127 128 edit test_hardcopy.vim 129 call assert_fails('hardcopy >', 'E324:') 130 bwipe 131endfunc 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() 154 CheckFeature postscript 155 156 new 157 call assert_equal("\nNo text to be printed", execute('hardcopy')) 158 bwipe 159endfunc 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 171func Test_fname_with_spaces() 172 CheckFeature postscript 173 174 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! 180endfunc 181 182func Test_illegal_byte() 183 CheckFeature postscript 184 if &enc != 'utf-8' 185 return 186 endif 187 188 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 196 197" vim: shiftwidth=2 sts=2 expandtab 198