robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
e3e5fadee0
master
1" Tests for 'makeencoding'. 2 3source shared.vim 4source check.vim 5 6CheckFeature quickfix 7let s: python = PythonProg () 8if s: python == '' 9throw 'Skipped: python program missing' 10endif 11 12let s: script = 'test_makeencoding.py' 13 14if has ( 'iconv' ) 15let s: message_tbl = { 16 \'utf-8' : 'ÀÈÌÒÙ こんにちは 你好' , 17 \'latin1' : 'ÀÈÌÒÙ' , 18 \'cp932' : 'こんにちは' , 19 \'cp936' : '你好' , 20 \} 21else 22let s: message_tbl = { 23 \'utf-8' : 'ÀÈÌÒÙ こんにちは 你好' , 24 \'latin1' : 'ÀÈÌÒÙ' , 25 \} 26endif 27 28 29" Tests for :cgetfile and :lgetfile. 30func Test_getfile () 31set errorfile = Xerror.txt 32set errorformat = %f(%l)\ :\ %m 33 34" :cgetfile 35for enc in keys ( s: message_tbl ) 36let & makeencoding = enc 37exec "silent !" . s: python . " " . s: script . " " . enc . " > " . & errorfile 38cgetfile 39copen 40call assert_equal ( "Xfoobar.c|10| " . s: message_tbl [ enc ] . " (" . enc . ")" , 41 \getline ( '.' )) 42cclose 43endfor 44 45" :lgetfile 46for enc in keys ( s: message_tbl ) 47let & makeencoding = enc 48exec "silent !" . s: python . " " . s: script . " " . enc . " > " . & errorfile 49lgetfile 50lopen 51call assert_equal ( "Xfoobar.c|10| " . s: message_tbl [ enc ] . " (" . enc . ")" , 52 \getline ( '.' )) 53lclose 54endfor 55 56call delete ( & errorfile ) 57endfunc 58 59 60" Tests for :grep and :lgrep. 61func Test_grep () 62let & grepprg = s: python 63set grepformat = %f(%l)\ :\ %m 64 65" :grep 66for enc in keys ( s: message_tbl ) 67let & makeencoding = enc 68exec "silent grep! " . s: script . " " . enc 69copen 70call assert_equal ( "Xfoobar.c|10| " . s: message_tbl [ enc ] . " (" . enc . ")" , 71 \getline ( '.' )) 72cclose 73endfor 74 75" :lgrep 76for enc in keys ( s: message_tbl ) 77let & makeencoding = enc 78exec "silent lgrep! " . s: script . " " . enc 79lopen 80call assert_equal ( "Xfoobar.c|10| " . s: message_tbl [ enc ] . " (" . enc . ")" , 81 \getline ( '.' )) 82lclose 83endfor 84endfunc 85 86 87" Tests for :make and :lmake. 88func Test_make () 89let & makeprg = s: python 90set errorformat = %f(%l)\ :\ %m 91 92" :make 93for enc in keys ( s: message_tbl ) 94let & makeencoding = enc 95exec "silent make! " . s: script . " " . enc 96copen 97call assert_equal ( "Xfoobar.c|10| " . s: message_tbl [ enc ] . " (" . enc . ")" , 98 \getline ( '.' )) 99cclose 100endfor 101 102" :lmake 103for enc in keys ( s: message_tbl ) 104let & makeencoding = enc 105exec "silent lmake! " . s: script . " " . enc 106lopen 107call assert_equal ( "Xfoobar.c|10| " . s: message_tbl [ enc ] . " (" . enc . ")" , 108 \getline ( '.' )) 109lclose 110endfor 111endfunc 112 113" Test for an error file with a long line that needs an encoding conversion 114func Test_longline_conversion () 115new 116call setline ( 1 , [ 'Xfile:10:' .. repeat ( "\xe0" , 2000 )]) 117write ++enc=latin1 Xerr.out 118bw ! 119set errorformat & 120set makeencoding = latin1 121cfile Xerr.out 122call assert_equal ( repeat ( "\u00e0" , 2000 ), getqflist ()[ 0 ]. text ) 123call delete ( 'Xerr.out' ) 124set makeencoding & 125endfunc 126 127" vim: shiftwidth=2 sts=2 expandtab