test_makeencoding.vim 2.9 KB

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