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